結果

問題 No.74 貯金箱の退屈
ユーザー kuuso1kuuso1
提出日時 2014-11-21 01:26:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 1,958 bytes
コンパイル時間 2,474 ms
コンパイル使用メモリ 105,996 KB
実行使用メモリ 24,516 KB
最終ジャッジ日時 2023-08-30 22:04:39
合計ジャッジ時間 5,672 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
22,420 KB
testcase_01 AC 60 ms
24,496 KB
testcase_02 AC 61 ms
24,512 KB
testcase_03 AC 60 ms
22,400 KB
testcase_04 AC 60 ms
22,524 KB
testcase_05 AC 60 ms
22,580 KB
testcase_06 AC 61 ms
22,472 KB
testcase_07 AC 60 ms
22,640 KB
testcase_08 AC 59 ms
22,520 KB
testcase_09 AC 60 ms
22,492 KB
testcase_10 AC 61 ms
22,516 KB
testcase_11 AC 60 ms
22,480 KB
testcase_12 AC 61 ms
24,448 KB
testcase_13 AC 61 ms
22,524 KB
testcase_14 AC 60 ms
20,540 KB
testcase_15 AC 61 ms
22,520 KB
testcase_16 AC 61 ms
22,464 KB
testcase_17 AC 61 ms
22,532 KB
testcase_18 AC 61 ms
22,496 KB
testcase_19 AC 60 ms
22,636 KB
testcase_20 AC 61 ms
20,496 KB
testcase_21 AC 61 ms
22,508 KB
testcase_22 AC 61 ms
22,496 KB
testcase_23 AC 61 ms
24,516 KB
testcase_24 AC 60 ms
22,536 KB
testcase_25 AC 61 ms
22,520 KB
testcase_26 AC 60 ms
22,508 KB
testcase_27 AC 60 ms
22,512 KB
testcase_28 AC 61 ms
22,412 KB
testcase_29 AC 61 ms
22,400 KB
testcase_30 AC 61 ms
24,496 KB
testcase_31 AC 60 ms
24,460 KB
testcase_32 AC 60 ms
22,444 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		E=new List<int>[N];
		for(int i=0;i<N;i++)E[i]=new List<int>();
		Mono=new HashSet<int>();
		for(int i=0;i<N;i++){
			E[(i+D[i]%N)%N].Add((N+i-D[i]%N)%N);
			E[(N+i-D[i]%N)%N].Add((i+D[i]%N)%N);
			if((N+i-D[i]%N)%N == (i+D[i]%N)%N )Mono.Add((i+D[i]%N)%N);
		}
		
		visited=new bool[N];
		compo=new int[N];
		int c=0;
		for(int i=0;i<N;i++){
			if(!visited[i])dfs(i,++c);
		}
		bool chk=true;
		for(int i=1;i<=c;i++){
			int sum=0;
			bool clear=false;
			for(int j=0;j<N;j++){
				if(compo[j]==i){
					if(W[j]==0)sum++;
					if(Mono.Contains(j))clear=true;
				}
			}
			if(!clear && sum%2==1)chk=false;
		}
		
		Console.WriteLine(chk?"Yes":"No");
	}
	
	bool[] visited;
	int[] compo;
	
	void dfs(int now,int c){
		compo[now]=c;
		visited[now]=true;
		foreach(int next in E[now]){
			if(!visited[next])dfs(next,c);
		}
	}
	
	
	
	
	HashSet<int> Mono;
	List<int>[] E;
	
	
	int N;
	int[] D;
	int[] W;
	public Sol(){
		N=ri();
		var s=rsa();
		D=new int[N];
		for(int i=0;i<N;i++)D[i]=int.Parse(s[i]);
		s=rsa();
		W=new int[N];
		for(int i=0;i<N;i++)W[i]=int.Parse(s[i]);
		//D=ria();
		//W=ria();
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
0