# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
792404 |
2023-07-25T04:17:17 Z |
박상훈(#10052) |
Binaria (CCO23_day1problem1) |
C++17 |
|
191 ms |
70840 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int MOD = 1e6 + 3;
int S[1001000];
vector<int> V[1001000];
ll fact[1001000], factINV[1001000];
void NO(){
printf("0\n");
exit(1);
}
ll pw(ll a, ll e){
if (!e) return 1;
ll ret = pw(a, e/2);
if (e&1) return ret * ret % MOD * a % MOD;
return ret * ret % MOD;
}
ll ncr(int n, int r){
// printf("ok %d %d\n", n, r);
fact[0] = 1;
for (int i=1;i<=n;i++) fact[i] = fact[i-1] * i % MOD;
for (int i=0;i<=n;i++) factINV[i] = pw(fact[i], MOD-2);
return fact[n] * factINV[r] % MOD * factINV[n-r] % MOD;
}
int main(){
int n, k;
scanf("%d %d", &n, &k);
for (int i=1;i<=n-k+1;i++) scanf("%d", S+i);
for (int i=0;i<k;i++) V[i].push_back(-1);
for (int i=1;i<=n-k;i++){
if (S[i]==S[i+1]){
if (V[i%k].back()==-1) V[i%k].push_back(-1);
else V[i%k].push_back(V[i%k].back());
}
else if (S[i]+1 == S[i+1]){
if (V[i%k].back()==1) NO();
if (V[i%k].back()==-1){
for (auto &x:V[i%k]) x = 0;
}
V[i%k].push_back(1);
}
else if (S[i] == S[i+1]+1){
if (V[i%k].back()==0) NO();
if (V[i%k].back()==-1){
for (auto &x:V[i%k]) x = 1;
}
V[i%k].push_back(0);
}
else NO();
}
// for (int i=0;i<k;i++){
// printf("%d: ", i);
// for (auto &x:V[i]) printf("%d ", x);
// printf("\n");
// }
int mn = 0, mx = 0;
for (int i=0;i<k;i++){
if (V[i][0]==1) mn++, mx++;
else if (V[i][0]==-1) mx++;
}
if (mn <= S[1] && S[1] <= mx){
int N = mx - mn;
int R = S[1] - mn;
printf("%lld\n", ncr(N, R));
}
else NO();
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:35:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | for (int i=1;i<=n-k+1;i++) scanf("%d", S+i);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
11 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23748 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23784 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
11 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23748 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23784 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23764 KB |
Output is correct |
13 |
Correct |
12 ms |
23784 KB |
Output is correct |
14 |
Correct |
12 ms |
23712 KB |
Output is correct |
15 |
Correct |
11 ms |
23784 KB |
Output is correct |
16 |
Correct |
11 ms |
23804 KB |
Output is correct |
17 |
Correct |
15 ms |
23820 KB |
Output is correct |
18 |
Correct |
13 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23764 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
11 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23748 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23784 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23764 KB |
Output is correct |
13 |
Correct |
12 ms |
23784 KB |
Output is correct |
14 |
Correct |
12 ms |
23712 KB |
Output is correct |
15 |
Correct |
11 ms |
23784 KB |
Output is correct |
16 |
Correct |
11 ms |
23804 KB |
Output is correct |
17 |
Correct |
15 ms |
23820 KB |
Output is correct |
18 |
Correct |
13 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23764 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23772 KB |
Output is correct |
22 |
Correct |
12 ms |
23768 KB |
Output is correct |
23 |
Correct |
11 ms |
23740 KB |
Output is correct |
24 |
Correct |
14 ms |
23764 KB |
Output is correct |
25 |
Correct |
11 ms |
23764 KB |
Output is correct |
26 |
Correct |
14 ms |
23796 KB |
Output is correct |
27 |
Correct |
13 ms |
23724 KB |
Output is correct |
28 |
Correct |
11 ms |
23780 KB |
Output is correct |
29 |
Correct |
11 ms |
23784 KB |
Output is correct |
30 |
Correct |
14 ms |
23844 KB |
Output is correct |
31 |
Correct |
14 ms |
23840 KB |
Output is correct |
32 |
Correct |
12 ms |
23832 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
11 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
11 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23748 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23784 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23764 KB |
Output is correct |
13 |
Correct |
12 ms |
23784 KB |
Output is correct |
14 |
Correct |
12 ms |
23712 KB |
Output is correct |
15 |
Correct |
11 ms |
23784 KB |
Output is correct |
16 |
Correct |
11 ms |
23804 KB |
Output is correct |
17 |
Correct |
15 ms |
23820 KB |
Output is correct |
18 |
Correct |
13 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23764 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23772 KB |
Output is correct |
22 |
Correct |
12 ms |
23768 KB |
Output is correct |
23 |
Correct |
11 ms |
23740 KB |
Output is correct |
24 |
Correct |
14 ms |
23764 KB |
Output is correct |
25 |
Correct |
11 ms |
23764 KB |
Output is correct |
26 |
Correct |
14 ms |
23796 KB |
Output is correct |
27 |
Correct |
13 ms |
23724 KB |
Output is correct |
28 |
Correct |
11 ms |
23780 KB |
Output is correct |
29 |
Correct |
11 ms |
23784 KB |
Output is correct |
30 |
Correct |
14 ms |
23844 KB |
Output is correct |
31 |
Correct |
14 ms |
23840 KB |
Output is correct |
32 |
Correct |
12 ms |
23832 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
11 ms |
23764 KB |
Output is correct |
35 |
Correct |
92 ms |
31932 KB |
Output is correct |
36 |
Correct |
80 ms |
31952 KB |
Output is correct |
37 |
Correct |
83 ms |
32044 KB |
Output is correct |
38 |
Correct |
94 ms |
32016 KB |
Output is correct |
39 |
Correct |
91 ms |
32040 KB |
Output is correct |
40 |
Correct |
90 ms |
31968 KB |
Output is correct |
41 |
Correct |
88 ms |
31932 KB |
Output is correct |
42 |
Correct |
80 ms |
31844 KB |
Output is correct |
43 |
Correct |
78 ms |
32112 KB |
Output is correct |
44 |
Correct |
81 ms |
31912 KB |
Output is correct |
45 |
Correct |
81 ms |
31928 KB |
Output is correct |
46 |
Correct |
98 ms |
31932 KB |
Output is correct |
47 |
Correct |
87 ms |
31740 KB |
Output is correct |
48 |
Correct |
84 ms |
31932 KB |
Output is correct |
49 |
Correct |
80 ms |
31956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
11 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23748 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23784 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23764 KB |
Output is correct |
13 |
Correct |
12 ms |
23784 KB |
Output is correct |
14 |
Correct |
12 ms |
23712 KB |
Output is correct |
15 |
Correct |
11 ms |
23784 KB |
Output is correct |
16 |
Correct |
11 ms |
23804 KB |
Output is correct |
17 |
Correct |
15 ms |
23820 KB |
Output is correct |
18 |
Correct |
13 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23764 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23772 KB |
Output is correct |
22 |
Correct |
12 ms |
23768 KB |
Output is correct |
23 |
Correct |
11 ms |
23740 KB |
Output is correct |
24 |
Correct |
14 ms |
23764 KB |
Output is correct |
25 |
Correct |
11 ms |
23764 KB |
Output is correct |
26 |
Correct |
14 ms |
23796 KB |
Output is correct |
27 |
Correct |
13 ms |
23724 KB |
Output is correct |
28 |
Correct |
11 ms |
23780 KB |
Output is correct |
29 |
Correct |
11 ms |
23784 KB |
Output is correct |
30 |
Correct |
14 ms |
23844 KB |
Output is correct |
31 |
Correct |
14 ms |
23840 KB |
Output is correct |
32 |
Correct |
12 ms |
23832 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
11 ms |
23764 KB |
Output is correct |
35 |
Correct |
92 ms |
31932 KB |
Output is correct |
36 |
Correct |
80 ms |
31952 KB |
Output is correct |
37 |
Correct |
83 ms |
32044 KB |
Output is correct |
38 |
Correct |
94 ms |
32016 KB |
Output is correct |
39 |
Correct |
91 ms |
32040 KB |
Output is correct |
40 |
Correct |
90 ms |
31968 KB |
Output is correct |
41 |
Correct |
88 ms |
31932 KB |
Output is correct |
42 |
Correct |
80 ms |
31844 KB |
Output is correct |
43 |
Correct |
78 ms |
32112 KB |
Output is correct |
44 |
Correct |
81 ms |
31912 KB |
Output is correct |
45 |
Correct |
81 ms |
31928 KB |
Output is correct |
46 |
Correct |
98 ms |
31932 KB |
Output is correct |
47 |
Correct |
87 ms |
31740 KB |
Output is correct |
48 |
Correct |
84 ms |
31932 KB |
Output is correct |
49 |
Correct |
80 ms |
31956 KB |
Output is correct |
50 |
Correct |
90 ms |
33856 KB |
Output is correct |
51 |
Correct |
112 ms |
33748 KB |
Output is correct |
52 |
Correct |
96 ms |
33792 KB |
Output is correct |
53 |
Correct |
90 ms |
33700 KB |
Output is correct |
54 |
Correct |
104 ms |
33740 KB |
Output is correct |
55 |
Correct |
88 ms |
33836 KB |
Output is correct |
56 |
Correct |
93 ms |
33760 KB |
Output is correct |
57 |
Correct |
96 ms |
33896 KB |
Output is correct |
58 |
Correct |
87 ms |
33852 KB |
Output is correct |
59 |
Correct |
107 ms |
33780 KB |
Output is correct |
60 |
Correct |
86 ms |
33056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23828 KB |
Output is correct |
3 |
Correct |
11 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
13 ms |
23748 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
13 ms |
23784 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
13 ms |
23764 KB |
Output is correct |
12 |
Correct |
14 ms |
23764 KB |
Output is correct |
13 |
Correct |
12 ms |
23784 KB |
Output is correct |
14 |
Correct |
12 ms |
23712 KB |
Output is correct |
15 |
Correct |
11 ms |
23784 KB |
Output is correct |
16 |
Correct |
11 ms |
23804 KB |
Output is correct |
17 |
Correct |
15 ms |
23820 KB |
Output is correct |
18 |
Correct |
13 ms |
23764 KB |
Output is correct |
19 |
Correct |
12 ms |
23764 KB |
Output is correct |
20 |
Correct |
12 ms |
23764 KB |
Output is correct |
21 |
Correct |
13 ms |
23772 KB |
Output is correct |
22 |
Correct |
12 ms |
23768 KB |
Output is correct |
23 |
Correct |
11 ms |
23740 KB |
Output is correct |
24 |
Correct |
14 ms |
23764 KB |
Output is correct |
25 |
Correct |
11 ms |
23764 KB |
Output is correct |
26 |
Correct |
14 ms |
23796 KB |
Output is correct |
27 |
Correct |
13 ms |
23724 KB |
Output is correct |
28 |
Correct |
11 ms |
23780 KB |
Output is correct |
29 |
Correct |
11 ms |
23784 KB |
Output is correct |
30 |
Correct |
14 ms |
23844 KB |
Output is correct |
31 |
Correct |
14 ms |
23840 KB |
Output is correct |
32 |
Correct |
12 ms |
23832 KB |
Output is correct |
33 |
Correct |
12 ms |
23764 KB |
Output is correct |
34 |
Correct |
11 ms |
23764 KB |
Output is correct |
35 |
Correct |
92 ms |
31932 KB |
Output is correct |
36 |
Correct |
80 ms |
31952 KB |
Output is correct |
37 |
Correct |
83 ms |
32044 KB |
Output is correct |
38 |
Correct |
94 ms |
32016 KB |
Output is correct |
39 |
Correct |
91 ms |
32040 KB |
Output is correct |
40 |
Correct |
90 ms |
31968 KB |
Output is correct |
41 |
Correct |
88 ms |
31932 KB |
Output is correct |
42 |
Correct |
80 ms |
31844 KB |
Output is correct |
43 |
Correct |
78 ms |
32112 KB |
Output is correct |
44 |
Correct |
81 ms |
31912 KB |
Output is correct |
45 |
Correct |
81 ms |
31928 KB |
Output is correct |
46 |
Correct |
98 ms |
31932 KB |
Output is correct |
47 |
Correct |
87 ms |
31740 KB |
Output is correct |
48 |
Correct |
84 ms |
31932 KB |
Output is correct |
49 |
Correct |
80 ms |
31956 KB |
Output is correct |
50 |
Correct |
90 ms |
33856 KB |
Output is correct |
51 |
Correct |
112 ms |
33748 KB |
Output is correct |
52 |
Correct |
96 ms |
33792 KB |
Output is correct |
53 |
Correct |
90 ms |
33700 KB |
Output is correct |
54 |
Correct |
104 ms |
33740 KB |
Output is correct |
55 |
Correct |
88 ms |
33836 KB |
Output is correct |
56 |
Correct |
93 ms |
33760 KB |
Output is correct |
57 |
Correct |
96 ms |
33896 KB |
Output is correct |
58 |
Correct |
87 ms |
33852 KB |
Output is correct |
59 |
Correct |
107 ms |
33780 KB |
Output is correct |
60 |
Correct |
86 ms |
33056 KB |
Output is correct |
61 |
Correct |
188 ms |
70840 KB |
Output is correct |
62 |
Correct |
191 ms |
70724 KB |
Output is correct |
63 |
Correct |
174 ms |
70664 KB |
Output is correct |
64 |
Correct |
168 ms |
70756 KB |
Output is correct |
65 |
Correct |
135 ms |
48856 KB |
Output is correct |
66 |
Correct |
140 ms |
54768 KB |
Output is correct |
67 |
Correct |
112 ms |
38092 KB |
Output is correct |
68 |
Correct |
170 ms |
66832 KB |
Output is correct |
69 |
Correct |
171 ms |
70672 KB |
Output is correct |
70 |
Correct |
167 ms |
70744 KB |
Output is correct |
71 |
Correct |
168 ms |
70716 KB |
Output is correct |