結果
| 問題 |
No.3120 Lower Nim
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-19 03:11:33 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,244 ms / 2,000 ms |
| コード長 | 2,690 bytes |
| コンパイル時間 | 4,194 ms |
| コンパイル使用メモリ | 92,368 KB |
| 実行使用メモリ | 81,992 KB |
| 平均クエリ数 | 2678.82 |
| 最終ジャッジ日時 | 2025-04-19 03:12:13 |
| 合計ジャッジ時間 | 34,956 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 43 |
ソースコード
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Main implements Runnable {
public static void main(String[] args) {
new Thread(null, new Main(), "", 512 * 1024 * 1024).start();
// new Main().check();
}
Random rnd=new Random();
void check() {
out:for(int t=0;t<10000;++t) {
N=rnd.nextInt(1,11);
K=10000;
A=new int[N];
for(int i=0;i<N;++i) {
A[i]=rnd.nextInt(1,17);
}
boolean o=outcome();
if(!o) {
randomPlay();
push();
}
if(isP()) {
System.out.println("OK");
continue;
}
while(true) {
if(isP()||!outcome()) {
throw new AssertionError();
}
outcome();
push();
if(isP()) {
System.out.println("OK");
continue out;
}
randomPlay();
// outcome();
push();
}
}
}
boolean isP() {
return Arrays.stream(A).allMatch(a->a==0);
}
void randomPlay() {
do {
id=rnd.nextInt(N);
} while(A[id]==0);
x=rnd.nextInt(1,Math.min(K+1, A[id]+1));
K=x;
}
Scanner sc=new Scanner(System.in);
int N;
int[] A;
int id=-1;
int x=-1;
int K=-1;
boolean outcome() {
int[] B=Arrays.copyOf(A, A.length);
int coe=1;
while(true) {
int n0=0;
int n1=0;
int nOdd=0;
for(int b:B) {
if(b==0)++n0;
if(b==1)++n1;
if(b%2==1)++nOdd;
}
if(n0==N)return false;
if(nOdd%2==1) {
int i=0;
while(B[i]==0)++i;
x=coe;
id=i;
return true;
}
if(N-n0==1) {
int i=0;
while(B[i]==0)++i;
if(B[i]*coe<=K) {
id=i;
x=coe*B[i];
return true;
}
}
if(n1==N-n0)return false;
for(int i=0;i<N;++i)B[i]/=2;
coe*=2;
}
}
void push() {
A[id]-=x;
if(K!=-1&&x>K)throw new AssertionError();
K=x;
if(A[id]<0)throw new AssertionError();
int ret=sc.nextInt();
if(ret==1)System.exit(0);
}
public void run() {
N=sc.nextInt();
A=new int[N];
for(int i=0;i<N;++i) {
A[i]=sc.nextInt();
}
boolean o=outcome();
System.out.println(o?"First":"Second");
K=10000;
if(!o) {
id=sc.nextInt()-1;
x=sc.nextInt();
push();
}
while(true) {
outcome();
System.out.println((id+1)+" "+x);
push();
id=sc.nextInt()-1;
x=sc.nextInt();
push();
}
}
void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}