-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoundTableKnights.java
44 lines (41 loc) · 1.15 KB
/
RoundTableKnights.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/** https://codeforces.com/problemset/problem/71/C #implementation */
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
public class RoundTableKnights {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> goodMood = new ArrayList<>();
for (int i = 1; i <= n; i++) {
int v = sc.nextInt();
if (v == 1) {
goodMood.add(i);
}
}
// corner case
if (goodMood.size() < 3) {
System.out.println("NO");
return;
}
HashSet<Integer> set = new HashSet<>();
goodMood.forEach(x -> set.add(x));
int maxEdgeLen = n / 3;
for (int edgeLen = 1; edgeLen <= maxEdgeLen; edgeLen++) {
if (n % edgeLen != 0) continue;
int edgeNum = n / edgeLen;
for (int i = 1; i <= edgeLen; i++) {
int cnt = 0;
if (goodMood.size() < i) break;
for (int point = goodMood.get(i - 1); set.contains(point); point += edgeLen) {
cnt++;
}
if (cnt == edgeNum) {
System.out.println("YES");
return;
}
}
}
System.out.println("NO");
}
}