結果

問題 No.74 貯金箱の退屈
ユーザー リチウムリチウム
提出日時 2014-11-21 02:16:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 5,000 ms
コード長 1,664 bytes
コンパイル時間 2,979 ms
コンパイル使用メモリ 75,248 KB
実行使用メモリ 56,056 KB
最終ジャッジ日時 2023-08-30 22:06:51
合計ジャッジ時間 8,063 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,704 KB
testcase_01 AC 124 ms
55,668 KB
testcase_02 AC 125 ms
55,716 KB
testcase_03 AC 137 ms
55,444 KB
testcase_04 AC 137 ms
55,720 KB
testcase_05 AC 135 ms
55,832 KB
testcase_06 AC 136 ms
55,916 KB
testcase_07 AC 134 ms
55,908 KB
testcase_08 AC 136 ms
56,052 KB
testcase_09 AC 135 ms
55,612 KB
testcase_10 AC 134 ms
55,724 KB
testcase_11 AC 135 ms
55,392 KB
testcase_12 AC 135 ms
55,696 KB
testcase_13 AC 143 ms
55,796 KB
testcase_14 AC 143 ms
55,464 KB
testcase_15 AC 142 ms
55,656 KB
testcase_16 AC 141 ms
55,596 KB
testcase_17 AC 133 ms
55,880 KB
testcase_18 AC 128 ms
55,636 KB
testcase_19 AC 134 ms
55,804 KB
testcase_20 AC 140 ms
55,452 KB
testcase_21 AC 140 ms
55,640 KB
testcase_22 AC 130 ms
55,744 KB
testcase_23 AC 131 ms
56,056 KB
testcase_24 AC 141 ms
55,908 KB
testcase_25 AC 141 ms
55,588 KB
testcase_26 AC 141 ms
55,800 KB
testcase_27 AC 140 ms
55,704 KB
testcase_28 AC 142 ms
55,912 KB
testcase_29 AC 142 ms
55,856 KB
testcase_30 AC 142 ms
55,796 KB
testcase_31 AC 143 ms
55,672 KB
testcase_32 AC 136 ms
55,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static int par[];//mainでparのi代入が必要
	static int rank[];

	static int find(int x) {
		if (par[x] == x) {
			return x;
		} else {
			return par[x] = find(par[x]);
		}
	}

	static boolean same(int x, int y) {
		return find(x) == find(y);
	}

	static void union(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		if (rank[x] < rank[y])
			par[x] = y;
		else {
			par[y] = x;
			if (rank[x] == rank[y])
				rank[x]++;

		}
	}
	
  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];
	  
	  for(int i=0;i<n;i++){
		  d[i]=sc.nextInt();
	  }
	  par=new int[n];
	  rank=new int[n];
	  for(int i=0;i<n;i++){
		  w[i]=sc.nextInt();
		  par[i]=i;
	  }
	  boolean single[]=new boolean [n];
	  for(int i=0;i<n;i++){
		  int x=(i+d[i])%n;
		  int y=i-d[i];
		  while(y<0)y+=n;
		  if(x==y)single[x]=true;
		  else union(x,y);
	  }
	  boolean ans=true;
	  for(int i=0;i<n;i++){
		  if(single[i])single[find(i)]=true;
	  }
	  boolean check[]=new boolean[n];
	  
	  ArrayList <Integer>parent[]=new ArrayList[n];
	  for(int i=0;i<n;i++){
		  parent[i]=new ArrayList<>();
	  }
	  
	  for(int i=0;i<n;i++){
		  parent[find(i)].add(i);
	  }
	  bi:for(int i=0;i<n;i++){
		  int ura=0;
		  for(int j=0;j<parent[i].size();j++){
			  int x=parent[i].get(j);
			  if(single[x])continue bi;
			  if(w[x]==0)ura++;
		  }
		  if(ura%2==1){
			  System.out.println("No");
			  return;
		  }
	  }
	  System.out.println("Yes");
  }
}
0