結果

問題 No.74 貯金箱の退屈
ユーザー 37zigen37zigen
提出日時 2016-03-23 23:48:50
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,826 bytes
コンパイル時間 2,365 ms
コンパイル使用メモリ 77,844 KB
実行使用メモリ 55,080 KB
最終ジャッジ日時 2024-04-09 21:14:27
合計ジャッジ時間 7,492 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
54,088 KB
testcase_01 AC 105 ms
52,836 KB
testcase_02 AC 115 ms
54,128 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 145 ms
54,556 KB
testcase_16 AC 142 ms
54,356 KB
testcase_17 AC 124 ms
53,936 KB
testcase_18 AC 110 ms
53,872 KB
testcase_19 AC 143 ms
54,588 KB
testcase_20 AC 149 ms
54,848 KB
testcase_21 AC 145 ms
54,388 KB
testcase_22 AC 104 ms
54,324 KB
testcase_23 AC 105 ms
53,280 KB
testcase_24 AC 144 ms
54,652 KB
testcase_25 AC 147 ms
54,684 KB
testcase_26 AC 147 ms
55,016 KB
testcase_27 AC 150 ms
54,592 KB
testcase_28 AC 150 ms
54,660 KB
testcase_29 AC 157 ms
54,700 KB
testcase_30 AC 153 ms
54,868 KB
testcase_31 AC 149 ms
54,808 KB
testcase_32 AC 142 ms
54,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder074;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] d=new int[n];
		int[] w=new int[n];//k番目のコインの裏表(0の時裏、1の時表)
		double[][] Coe=new double[n][n+1];
		for(int i=0;i<n;i++){
			d[i]=sc.nextInt();
		}
		for(int i=0;i<n;i++){
			w[i]=sc.nextInt();
		}
		for(int i=0;i<n;i++){
			Coe[(i+d[i])%n][i]=1;
			int s=i-d[i];
			while(s<0){
				s+=n;
			}
			Coe[(s)%n][i]=1;
		}
		for(int i=0;i<n;i++){
			int a=0;
			if(w[i]==1)a=0;
			if(w[i]==0)a=1;
			Coe[i][n]=a;
		}
//		for(int o=0;o<Coe.length;o++){
//			for(int p=0;p<Coe[0].length;p++){
//				System.out.print(Coe[o][p]+" ");
//			}
//			System.out.println();
//		}
		if(gaussElimination(Coe)==true){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	public static boolean gaussElimination(double[][] coe){
		for(int i=0;i<coe[0].length-1;i++){
			double c=0;
			for(int j=i;j<coe.length;j++){
				if(coe[j][i]!=0){
					double[] tmp=coe[j];
					coe[j]=coe[i];
					coe[i]=tmp;
					break;
				}
			}
			double coe1=coe[i][i];
			for(int j=0;j<coe[0].length;j++){
				coe[i][j]=coe[i][j]/coe1;
			}
			for(int j=0;j<coe.length;j++){
				if(i==j)continue;
				double coe2=coe[j][i];
				for(int k=0;k<coe[0].length;k++){
					coe[j][k]=coe[j][k]-coe2*coe[i][k];
				}
			}
		}
//		for(int i=0;i<coe.length;i++){
//			for(int j=0;j<coe[0].length;j++){
//				System.out.print(coe[i][j]+" ");
//			}
//			System.out.println();
//		}
		for(int i=0;i<coe.length;i++){
			if(coe[i][i]!=1){
				if(coe[i][coe[0].length-1]==0){
					return false;
				}
			}
		}
		for(int i=0;i<coe.length;i++){
			if(coe[i][coe[0].length-1]!=(int)coe[i][coe[0].length-1])
				return false;
		}
		return true;
	}
}

0