結果

問題 No.74 貯金箱の退屈
ユーザー リチウムリチウム
提出日時 2014-11-21 02:06:56
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,676 bytes
コンパイル時間 4,030 ms
コンパイル使用メモリ 75,152 KB
実行使用メモリ 58,336 KB
最終ジャッジ日時 2023-08-30 22:05:49
合計ジャッジ時間 8,093 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

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];
		  int y=i-d[i];
		  if(x>=n)x-=n;
		  if(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