結果

問題 No.3120 Lower Nim
ユーザー 37zigen
提出日時 2025-04-19 02:40:02
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,723 bytes
コンパイル時間 8,335 ms
コンパイル使用メモリ 85,996 KB
実行使用メモリ 82,316 KB
平均クエリ数 2508.34
最終ジャッジ日時 2025-04-19 02:40:46
合計ジャッジ時間 36,784 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 42 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;

public class Main implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "", 512 * 1024 * 1024).start();
    }

    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 upper=K;
    	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(N-n0==1) {
    			int i=0;
    			while(B[i]==0)++i;
    			id=i;
    			x=coe*B[i];
    			return true;
    		}
    		if(nOdd%2==1) {
    			int i=0;
    			while(B[i]==0)++i;
    			x=coe;
    			id=i;
    			return true;
    		}
    		if(n1==N-n0)return false;
    		for(int i=0;i<N;++i)B[i]/=2;
    		coe*=2;
    		upper/=2;
    	}
    }
    
    void push() {
   		A[id]-=x;
   		K=x;
		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));}
}
0