tozangezan's diary

勝手にソースコードをコピペして利用しないでください。

KP^2C Vol.1

Virtual Arenaでコンテストに参加していました。2位。

A:やるだけ

#include<stdio.h>
#include<stack>
using namespace std;
char str[6];
stack<char> S[100];

int main(){
	int a;
	scanf("%d",&a);
	while(1){
		scanf("%s",str);
		if(str[0]=='q')return 0;
		if(str[0]=='m'){
			int b,c;
			scanf("%d%d",&b,&c);
			b--;c--;
			S[c].push(S[b].top());
			S[b].pop();
		}else if(str[0]=='p'&&str[1]=='u'){
			int b;scanf("%d%s",&b,str);
			b--;S[b].push(str[0]);
		}else{
			int b;scanf("%d",&b);b--;printf("%c\n",S[b].top());S[b].pop();
		}
	}
}

B:(n+1)!+k(n>k)はkの倍数。あと多倍長。

import java.util.*;
import java.math.*;
class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int a=s.nextInt();
		BigInteger bi=new BigInteger("1");
		for(int i=0;i<a;i++)bi=bi.multiply(new BigInteger(""+(i+2)));
		bi=bi.add(new BigInteger("2"));
		System.out.println(bi.toString());
		for(int i=0;i<a;i++)System.out.println(2+i);
	}
}

C:すでに解いてたのを貼った

D:Wolfram Alpha写経ゲー。改行を厳密にやる。

import java.util.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);

String ans[]={
"1 1 0",
"2 1 1 0",
"6 2 3 1 0",
"4 1 2 1 0 0",
"30 6 15 10 0 -1 0",
"12 2 6 5 0 -1 0 0",
"42 6 21 21 0 -7 0 1 0",
"24 3 12 14 0 -7 0 2 0 0",
"90 10 45 60 0 -42 0 20 0 -3 0",
"20 2 10 15 0 -14 0 10 0 -3 0 0",
"66 6 33 55 0 -66 0 66 0 -33 0 5 0",
"24 2 12 22 0 -33 0 44 0 -33 0 10 0 0",
"2730 210 1365 2730 0 -5005 0 8580 0 -9009 0 4550 0 -691 0",
"420 30 210 455 0 -1001 0 2145 0 -3003 0 2275 0 -691 0 0",
"90 6 45 105 0 -273 0 715 0 -1287 0 1365 0 -691 0 105 0",
"48 3 24 60 0 -182 0 572 0 -1287 0 1820 0 -1382 0 420 0 0",
"510 30 255 680 0 -2380 0 8840 0 -24310 0 44200 0 -46988 0 23800 0 -3617 0",
"180 10 90 255 0 -1020 0 4420 0 -14586 0 33150 0 -46988 0 35700 0 -10851 0 0",
"3990 210 1995 5985 0 -27132 0 135660 0 -529074 0 1469650 0 -2678316 0 2848860 0 -1443183 0 219335 0",
"840 42 420 1330 0 -6783 0 38760 0 -176358 0 587860 0 -1339158 0 1899240 0 -1443183 0 438670 0 0",
"6930 330 3465 11550 0 -65835 0 426360 0 -2238390 0 8817900 0 -24551230 0 44767800 0 -47625039 0 24126850 0 -3666831 0"
};

int a=s.nextInt();
for(int i=0;i<a;i++){if(i>0)System.out.println();System.out.println(ans[s.nextInt()]);}
}}

E:計算量が想像つかない

Dは本当の解法はぜんぜん写経ゲーじゃないです…