Skip to content

Commit 1d42a8e

Browse files
authored
Merge pull request #777 from AlgorithmWithGod/khj20006
[20250830] BOJ / P4 / 부모님께 큰절 하고 / 권혁준
2 parents 6da06e3 + ef3138f commit 1d42a8e

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
class IOController {
6+
BufferedReader br;
7+
BufferedWriter bw;
8+
StringTokenizer st;
9+
10+
public IOController() {
11+
br = new BufferedReader(new InputStreamReader(System.in));
12+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
st = new StringTokenizer("");
14+
}
15+
16+
String nextLine() throws Exception {
17+
String line = br.readLine();
18+
st = new StringTokenizer(line);
19+
return line;
20+
}
21+
22+
String nextToken() throws Exception {
23+
while (!st.hasMoreTokens()) nextLine();
24+
return st.nextToken();
25+
}
26+
27+
int nextInt() throws Exception {
28+
return Integer.parseInt(nextToken());
29+
}
30+
31+
long nextLong() throws Exception {
32+
return Long.parseLong(nextToken());
33+
}
34+
35+
double nextDouble() throws Exception {
36+
return Double.parseDouble(nextToken());
37+
}
38+
39+
void close() throws Exception {
40+
bw.flush();
41+
bw.close();
42+
}
43+
44+
void write(String content) throws Exception {
45+
bw.write(content);
46+
}
47+
48+
}
49+
50+
public class Main {
51+
52+
static IOController io;
53+
54+
//
55+
56+
static int N;
57+
static int[] a;
58+
59+
public static void main(String[] args) throws Exception {
60+
61+
io = new IOController();
62+
63+
N = io.nextInt();
64+
a = new int[N];
65+
int min = Integer.MAX_VALUE;
66+
for(int i=0;i<N;i++) {
67+
a[i] = io.nextInt();
68+
min = Math.min(min, a[i]);
69+
}
70+
71+
for(int i=0;i<N;i++) a[i] -= min;
72+
73+
Arrays.sort(a);
74+
if(a[1] == 0) {
75+
io.write("No");
76+
io.close();
77+
return;
78+
}
79+
int last = a[1], d = a[1], c = 2;
80+
boolean[] vis = new boolean[N];
81+
for(int i=2;i<N;i++) {
82+
if(a[i] == d*c) {
83+
last = d*c;
84+
c++;
85+
vis[i] = true;
86+
}
87+
}
88+
89+
List<Integer> list = new ArrayList<>();
90+
for(int i=2;i<N;i++) if(!vis[i]) list.add(a[i]);
91+
92+
d = list.get(0);
93+
c = 2;
94+
boolean can = true;
95+
for(int i=1;i<list.size();i++) {
96+
int cur = list.get(i);
97+
if(cur == d*c) c++;
98+
else can = false;
99+
}
100+
101+
if(!can) {
102+
list.add(last);
103+
Collections.sort(list);
104+
d = list.get(0);
105+
c = 2;
106+
can = true;
107+
for(int i=1;i<list.size();i++) {
108+
int cur = list.get(i);
109+
if(cur == d*c) c++;
110+
else can = false;
111+
}
112+
}
113+
114+
io.write(can ? "Yes" : "No");
115+
116+
io.close();
117+
118+
}
119+
120+
}
121+
```

0 commit comments

Comments
 (0)