結果
| 問題 |
No.74 貯金箱の退屈
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-06 23:01:51 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 73 ms / 5,000 ms |
| コード長 | 2,944 bytes |
| コンパイル時間 | 4,386 ms |
| コンパイル使用メモリ | 79,068 KB |
| 実行使用メモリ | 38,640 KB |
| 最終ジャッジ日時 | 2024-11-07 04:22:24 |
| 合計ジャッジ時間 | 7,823 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
import java.io.*;
import java.util.*;
public class Main_yukicoder74 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Printer pr = new Printer(System.out);
int n = sc.nextInt();
int[] d = new int[n];
for (int i = 0; i < n; i++) {
d[i] = sc.nextInt();
}
int[] w = new int[n];
BitSet[] ma = new BitSet[n + 1];
for (int i = 0; i < n + 1; i++) {
ma[i] = new BitSet(n);
}
for (int i = 0; i < n; i++) {
w[i] = sc.nextInt();
if (w[i] == 1) {
ma[0].set(i);
}
}
for (int i = 0; i < n; i++) {
int tmp = (i + d[i]) % n;
ma[i + 1].set(tmp);
int tmp2 = ((i - d[i]) % n + n) % n;
ma[i + 1].set(tmp2);
}
int cnt = 0;
int p = 1;
for (int i = 0; i < n; i++) {
boolean flag = false;
for (int j = p; j < n + 1; j++) {
if (ma[j].get(i)) {
flag = true;
BitSet tmp = ma[j];
ma[j] = ma[p];
ma[p] = tmp;
break;
}
}
if (flag) {
cnt++;
for (int j = 1; j < n + 1; j++) {
if (j != p && ma[j].get(i)) {
ma[j].xor(ma[p]);
}
}
if (ma[0].get(i)) {
ma[p].clear();
}
p++;
} else {
boolean tmp = false;
for (int j = 0; j < p; j++) {
tmp ^= ma[j].get(i);
}
if (tmp) {
cnt++;
}
}
}
if (cnt == n) {
pr.println("Yes");
} else {
// pr.println(n);
// pr.println(cnt);
pr.println("No");
}
pr.close();
sc.close();
}
@SuppressWarnings("unused")
private static class Scanner {
BufferedReader br;
Iterator<String> it;
Scanner (InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
}
String next() throws RuntimeException {
try {
if (it == null || !it.hasNext()) {
// it = Arrays.asList(br.readLine().split(" ")).iterator();
it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator();
}
return it.next();
} catch (IOException e) {
throw new IllegalStateException();
}
}
int nextInt() throws RuntimeException {
return Integer.parseInt(next());
}
long nextLong() throws RuntimeException {
return Long.parseLong(next());
}
float nextFloat() throws RuntimeException {
return Float.parseFloat(next());
}
double nextDouble() throws RuntimeException {
return Double.parseDouble(next());
}
void close() {
try {
br.close();
} catch (IOException e) {
// throw new IllegalStateException();
}
}
}
private static class Printer extends PrintWriter {
Printer(PrintStream out) {
super(out);
}
}
}