# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
792408 |
2023-07-25T04:18:41 Z |
이성호(#10053) |
Binaria (CCO23_day1problem1) |
C++17 |
|
231 ms |
27676 KB |
#include <iostream>
#include <vector>
using namespace std;
int res[1000005];
int sum[1000005];
const int mod = 1000003;
int mul(int id, int x)
{
if (x == 0) return 1;
long long ans = mul(id, x / 2);
ans = ans * ans % mod;
return (x & 1) ? (ans * id % mod) : ans;
}
int rev(int x)
{
return mul(x, mod - 2);
}
struct UnionFind
{
vector<int> par;
UnionFind(int n){par.resize(n+1); for(int i=1;i<=n;i++) par[i] = i;}
int fin(int i){return i==par[i]?i:(par[i] = fin(par[i]));}
void uni(int u, int v){par[fin(u)] = fin(v);}
bool isuni(int u, int v){return fin(u) == fin(v);}
};
int loc[1000005];
int main()
{
int N, K; cin >> N >> K;
for (int i = 1; i <= N - K + 1; i++) cin >> sum[i];
fill(res, res + 1000005, -1);
UnionFind uf(N);
for (int i = 1; i <= N - K; i++) {
if (sum[i+1] ^ sum[i]) {
if (sum[i+1] - sum[i] == 1) {
if (res[i+K] != 0) res[i+K] = 1;
else {
cout << "0\n";
return 0;
}
if (res[i] != 1) res[i] = 0;
else {
cout << "0\n";
return 0;
}
}
else {
if (res[i+K] != 1) res[i+K] = 0;
else {
cout << "0\n";
return 0;
}
if (res[i] != 0) res[i] = 1;
else {
cout << "0\n";
return 0;
}
}
}
else {
uf.uni(i, i+K);
}
}
fill(loc, loc + 1000005, -1);
for (int i = 1; i <= N; i++) {
int pr = uf.fin(i);
if (res[i] != -1) {
if (loc[i] != !res[i]) loc[i] = res[i];
else {
cout << "0\n";
return 0;
}
}
}
for (int i = 1; i <= K; i++) {
res[i] = loc[uf.fin(i)];
}
int tot = 0, cur = 0;
for (int i = 1; i <= K; i++) {
if (res[i] == -1) tot++;
if (res[i] == 1) cur++;
}
cur = sum[1] - cur;
if (cur < 0 || cur > tot) cout << "0\n";
else {
long long ans = 1;
for (int i = tot; i >= tot - cur + 1; i--) {
ans = ans * i % mod;
}
for (int i = 1; i <= cur; i++) {
ans = ans * rev(i) % mod;
}
cout << ans << '\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:67:13: warning: unused variable 'pr' [-Wunused-variable]
67 | int pr = uf.fin(i);
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
3 ms |
8020 KB |
Output is correct |
3 |
Correct |
3 ms |
8020 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8020 KB |
Output is correct |
6 |
Correct |
3 ms |
8020 KB |
Output is correct |
7 |
Correct |
3 ms |
8020 KB |
Output is correct |
8 |
Correct |
3 ms |
8020 KB |
Output is correct |
9 |
Correct |
3 ms |
8020 KB |
Output is correct |
10 |
Correct |
4 ms |
8020 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
3 ms |
8020 KB |
Output is correct |
3 |
Correct |
3 ms |
8020 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8020 KB |
Output is correct |
6 |
Correct |
3 ms |
8020 KB |
Output is correct |
7 |
Correct |
3 ms |
8020 KB |
Output is correct |
8 |
Correct |
3 ms |
8020 KB |
Output is correct |
9 |
Correct |
3 ms |
8020 KB |
Output is correct |
10 |
Correct |
4 ms |
8020 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8020 KB |
Output is correct |
13 |
Correct |
3 ms |
8020 KB |
Output is correct |
14 |
Correct |
3 ms |
8020 KB |
Output is correct |
15 |
Correct |
3 ms |
8060 KB |
Output is correct |
16 |
Correct |
3 ms |
8020 KB |
Output is correct |
17 |
Correct |
3 ms |
8020 KB |
Output is correct |
18 |
Correct |
3 ms |
8020 KB |
Output is correct |
19 |
Correct |
3 ms |
8020 KB |
Output is correct |
20 |
Correct |
3 ms |
8020 KB |
Output is correct |
21 |
Correct |
3 ms |
8020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
3 ms |
8020 KB |
Output is correct |
3 |
Correct |
3 ms |
8020 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8020 KB |
Output is correct |
6 |
Correct |
3 ms |
8020 KB |
Output is correct |
7 |
Correct |
3 ms |
8020 KB |
Output is correct |
8 |
Correct |
3 ms |
8020 KB |
Output is correct |
9 |
Correct |
3 ms |
8020 KB |
Output is correct |
10 |
Correct |
4 ms |
8020 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8020 KB |
Output is correct |
13 |
Correct |
3 ms |
8020 KB |
Output is correct |
14 |
Correct |
3 ms |
8020 KB |
Output is correct |
15 |
Correct |
3 ms |
8060 KB |
Output is correct |
16 |
Correct |
3 ms |
8020 KB |
Output is correct |
17 |
Correct |
3 ms |
8020 KB |
Output is correct |
18 |
Correct |
3 ms |
8020 KB |
Output is correct |
19 |
Correct |
3 ms |
8020 KB |
Output is correct |
20 |
Correct |
3 ms |
8020 KB |
Output is correct |
21 |
Correct |
3 ms |
8020 KB |
Output is correct |
22 |
Correct |
3 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8020 KB |
Output is correct |
24 |
Correct |
3 ms |
8108 KB |
Output is correct |
25 |
Correct |
3 ms |
8020 KB |
Output is correct |
26 |
Correct |
3 ms |
8020 KB |
Output is correct |
27 |
Correct |
3 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8020 KB |
Output is correct |
29 |
Correct |
3 ms |
8020 KB |
Output is correct |
30 |
Correct |
3 ms |
8020 KB |
Output is correct |
31 |
Correct |
3 ms |
8020 KB |
Output is correct |
32 |
Correct |
3 ms |
8020 KB |
Output is correct |
33 |
Correct |
3 ms |
8020 KB |
Output is correct |
34 |
Correct |
3 ms |
8020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
3 ms |
8020 KB |
Output is correct |
3 |
Correct |
3 ms |
8020 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8020 KB |
Output is correct |
6 |
Correct |
3 ms |
8020 KB |
Output is correct |
7 |
Correct |
3 ms |
8020 KB |
Output is correct |
8 |
Correct |
3 ms |
8020 KB |
Output is correct |
9 |
Correct |
3 ms |
8020 KB |
Output is correct |
10 |
Correct |
4 ms |
8020 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8020 KB |
Output is correct |
13 |
Correct |
3 ms |
8020 KB |
Output is correct |
14 |
Correct |
3 ms |
8020 KB |
Output is correct |
15 |
Correct |
3 ms |
8060 KB |
Output is correct |
16 |
Correct |
3 ms |
8020 KB |
Output is correct |
17 |
Correct |
3 ms |
8020 KB |
Output is correct |
18 |
Correct |
3 ms |
8020 KB |
Output is correct |
19 |
Correct |
3 ms |
8020 KB |
Output is correct |
20 |
Correct |
3 ms |
8020 KB |
Output is correct |
21 |
Correct |
3 ms |
8020 KB |
Output is correct |
22 |
Correct |
3 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8020 KB |
Output is correct |
24 |
Correct |
3 ms |
8108 KB |
Output is correct |
25 |
Correct |
3 ms |
8020 KB |
Output is correct |
26 |
Correct |
3 ms |
8020 KB |
Output is correct |
27 |
Correct |
3 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8020 KB |
Output is correct |
29 |
Correct |
3 ms |
8020 KB |
Output is correct |
30 |
Correct |
3 ms |
8020 KB |
Output is correct |
31 |
Correct |
3 ms |
8020 KB |
Output is correct |
32 |
Correct |
3 ms |
8020 KB |
Output is correct |
33 |
Correct |
3 ms |
8020 KB |
Output is correct |
34 |
Correct |
3 ms |
8020 KB |
Output is correct |
35 |
Correct |
124 ms |
16448 KB |
Output is correct |
36 |
Correct |
139 ms |
16512 KB |
Output is correct |
37 |
Correct |
173 ms |
16528 KB |
Output is correct |
38 |
Correct |
141 ms |
16440 KB |
Output is correct |
39 |
Correct |
126 ms |
16416 KB |
Output is correct |
40 |
Correct |
141 ms |
16500 KB |
Output is correct |
41 |
Correct |
158 ms |
16508 KB |
Output is correct |
42 |
Correct |
145 ms |
16720 KB |
Output is correct |
43 |
Correct |
122 ms |
16588 KB |
Output is correct |
44 |
Correct |
136 ms |
27676 KB |
Output is correct |
45 |
Correct |
163 ms |
27596 KB |
Output is correct |
46 |
Correct |
134 ms |
27576 KB |
Output is correct |
47 |
Correct |
123 ms |
21748 KB |
Output is correct |
48 |
Correct |
144 ms |
16420 KB |
Output is correct |
49 |
Correct |
144 ms |
16424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
3 ms |
8020 KB |
Output is correct |
3 |
Correct |
3 ms |
8020 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8020 KB |
Output is correct |
6 |
Correct |
3 ms |
8020 KB |
Output is correct |
7 |
Correct |
3 ms |
8020 KB |
Output is correct |
8 |
Correct |
3 ms |
8020 KB |
Output is correct |
9 |
Correct |
3 ms |
8020 KB |
Output is correct |
10 |
Correct |
4 ms |
8020 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8020 KB |
Output is correct |
13 |
Correct |
3 ms |
8020 KB |
Output is correct |
14 |
Correct |
3 ms |
8020 KB |
Output is correct |
15 |
Correct |
3 ms |
8060 KB |
Output is correct |
16 |
Correct |
3 ms |
8020 KB |
Output is correct |
17 |
Correct |
3 ms |
8020 KB |
Output is correct |
18 |
Correct |
3 ms |
8020 KB |
Output is correct |
19 |
Correct |
3 ms |
8020 KB |
Output is correct |
20 |
Correct |
3 ms |
8020 KB |
Output is correct |
21 |
Correct |
3 ms |
8020 KB |
Output is correct |
22 |
Correct |
3 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8020 KB |
Output is correct |
24 |
Correct |
3 ms |
8108 KB |
Output is correct |
25 |
Correct |
3 ms |
8020 KB |
Output is correct |
26 |
Correct |
3 ms |
8020 KB |
Output is correct |
27 |
Correct |
3 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8020 KB |
Output is correct |
29 |
Correct |
3 ms |
8020 KB |
Output is correct |
30 |
Correct |
3 ms |
8020 KB |
Output is correct |
31 |
Correct |
3 ms |
8020 KB |
Output is correct |
32 |
Correct |
3 ms |
8020 KB |
Output is correct |
33 |
Correct |
3 ms |
8020 KB |
Output is correct |
34 |
Correct |
3 ms |
8020 KB |
Output is correct |
35 |
Correct |
124 ms |
16448 KB |
Output is correct |
36 |
Correct |
139 ms |
16512 KB |
Output is correct |
37 |
Correct |
173 ms |
16528 KB |
Output is correct |
38 |
Correct |
141 ms |
16440 KB |
Output is correct |
39 |
Correct |
126 ms |
16416 KB |
Output is correct |
40 |
Correct |
141 ms |
16500 KB |
Output is correct |
41 |
Correct |
158 ms |
16508 KB |
Output is correct |
42 |
Correct |
145 ms |
16720 KB |
Output is correct |
43 |
Correct |
122 ms |
16588 KB |
Output is correct |
44 |
Correct |
136 ms |
27676 KB |
Output is correct |
45 |
Correct |
163 ms |
27596 KB |
Output is correct |
46 |
Correct |
134 ms |
27576 KB |
Output is correct |
47 |
Correct |
123 ms |
21748 KB |
Output is correct |
48 |
Correct |
144 ms |
16420 KB |
Output is correct |
49 |
Correct |
144 ms |
16424 KB |
Output is correct |
50 |
Correct |
186 ms |
15876 KB |
Output is correct |
51 |
Correct |
194 ms |
15908 KB |
Output is correct |
52 |
Correct |
188 ms |
15944 KB |
Output is correct |
53 |
Correct |
231 ms |
15868 KB |
Output is correct |
54 |
Correct |
187 ms |
15924 KB |
Output is correct |
55 |
Correct |
191 ms |
15892 KB |
Output is correct |
56 |
Correct |
186 ms |
15924 KB |
Output is correct |
57 |
Correct |
163 ms |
15900 KB |
Output is correct |
58 |
Correct |
187 ms |
15932 KB |
Output is correct |
59 |
Correct |
187 ms |
15840 KB |
Output is correct |
60 |
Correct |
176 ms |
15940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8020 KB |
Output is correct |
2 |
Correct |
3 ms |
8020 KB |
Output is correct |
3 |
Correct |
3 ms |
8020 KB |
Output is correct |
4 |
Correct |
3 ms |
8020 KB |
Output is correct |
5 |
Correct |
3 ms |
8020 KB |
Output is correct |
6 |
Correct |
3 ms |
8020 KB |
Output is correct |
7 |
Correct |
3 ms |
8020 KB |
Output is correct |
8 |
Correct |
3 ms |
8020 KB |
Output is correct |
9 |
Correct |
3 ms |
8020 KB |
Output is correct |
10 |
Correct |
4 ms |
8020 KB |
Output is correct |
11 |
Correct |
3 ms |
8020 KB |
Output is correct |
12 |
Correct |
3 ms |
8020 KB |
Output is correct |
13 |
Correct |
3 ms |
8020 KB |
Output is correct |
14 |
Correct |
3 ms |
8020 KB |
Output is correct |
15 |
Correct |
3 ms |
8060 KB |
Output is correct |
16 |
Correct |
3 ms |
8020 KB |
Output is correct |
17 |
Correct |
3 ms |
8020 KB |
Output is correct |
18 |
Correct |
3 ms |
8020 KB |
Output is correct |
19 |
Correct |
3 ms |
8020 KB |
Output is correct |
20 |
Correct |
3 ms |
8020 KB |
Output is correct |
21 |
Correct |
3 ms |
8020 KB |
Output is correct |
22 |
Correct |
3 ms |
8148 KB |
Output is correct |
23 |
Correct |
4 ms |
8020 KB |
Output is correct |
24 |
Correct |
3 ms |
8108 KB |
Output is correct |
25 |
Correct |
3 ms |
8020 KB |
Output is correct |
26 |
Correct |
3 ms |
8020 KB |
Output is correct |
27 |
Correct |
3 ms |
8148 KB |
Output is correct |
28 |
Correct |
4 ms |
8020 KB |
Output is correct |
29 |
Correct |
3 ms |
8020 KB |
Output is correct |
30 |
Correct |
3 ms |
8020 KB |
Output is correct |
31 |
Correct |
3 ms |
8020 KB |
Output is correct |
32 |
Correct |
3 ms |
8020 KB |
Output is correct |
33 |
Correct |
3 ms |
8020 KB |
Output is correct |
34 |
Correct |
3 ms |
8020 KB |
Output is correct |
35 |
Correct |
124 ms |
16448 KB |
Output is correct |
36 |
Correct |
139 ms |
16512 KB |
Output is correct |
37 |
Correct |
173 ms |
16528 KB |
Output is correct |
38 |
Correct |
141 ms |
16440 KB |
Output is correct |
39 |
Correct |
126 ms |
16416 KB |
Output is correct |
40 |
Correct |
141 ms |
16500 KB |
Output is correct |
41 |
Correct |
158 ms |
16508 KB |
Output is correct |
42 |
Correct |
145 ms |
16720 KB |
Output is correct |
43 |
Correct |
122 ms |
16588 KB |
Output is correct |
44 |
Correct |
136 ms |
27676 KB |
Output is correct |
45 |
Correct |
163 ms |
27596 KB |
Output is correct |
46 |
Correct |
134 ms |
27576 KB |
Output is correct |
47 |
Correct |
123 ms |
21748 KB |
Output is correct |
48 |
Correct |
144 ms |
16420 KB |
Output is correct |
49 |
Correct |
144 ms |
16424 KB |
Output is correct |
50 |
Correct |
186 ms |
15876 KB |
Output is correct |
51 |
Correct |
194 ms |
15908 KB |
Output is correct |
52 |
Correct |
188 ms |
15944 KB |
Output is correct |
53 |
Correct |
231 ms |
15868 KB |
Output is correct |
54 |
Correct |
187 ms |
15924 KB |
Output is correct |
55 |
Correct |
191 ms |
15892 KB |
Output is correct |
56 |
Correct |
186 ms |
15924 KB |
Output is correct |
57 |
Correct |
163 ms |
15900 KB |
Output is correct |
58 |
Correct |
187 ms |
15932 KB |
Output is correct |
59 |
Correct |
187 ms |
15840 KB |
Output is correct |
60 |
Correct |
176 ms |
15940 KB |
Output is correct |
61 |
Correct |
67 ms |
11988 KB |
Output is correct |
62 |
Correct |
55 ms |
11988 KB |
Output is correct |
63 |
Correct |
113 ms |
11988 KB |
Output is correct |
64 |
Correct |
75 ms |
11988 KB |
Output is correct |
65 |
Correct |
184 ms |
14116 KB |
Output is correct |
66 |
Correct |
117 ms |
13380 KB |
Output is correct |
67 |
Correct |
209 ms |
15072 KB |
Output is correct |
68 |
Correct |
24 ms |
12296 KB |
Output is correct |
69 |
Correct |
129 ms |
12040 KB |
Output is correct |
70 |
Correct |
7 ms |
11988 KB |
Output is correct |
71 |
Correct |
72 ms |
12044 KB |
Output is correct |