# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
863302 | 2023-10-20T02:24:49 Z | quandlm | Binaria (CCO23_day1problem1) | C++14 | 71 ms | 24884 KB |
#include <bits/stdc++.h> #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } #define ll long long #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, a, b) for (int i = (a); i >= (b); --i) #define pi pair<int,int> #define ple tuple<int,int,int> #define fi first #define se second #define ii make_pair #define isz(a) ((int)a.size()) #define ALL(a) a.begin(), a.end() using namespace std; const int N = 1e6 + 10; const int mod = 1e6 + 3; int n,k,a[N],color[N],sz[N],lab[N],ifact[N]; void pre_calc () { ifact[0] = 1; FOR(i,1,n+10) { color[i] = -1; sz[i] = 1; lab[i] = i; ifact[i] = 1ll * ifact[i-1] * i % mod; } } int find (int u) { return (lab[u] == u ? u : lab[u] = find(lab[u])); } bool join (int u, int v) { u = find(u); v = find(v); if (u == v) return false; if (sz[u] < sz[v]) swap(u, v); lab[v] = u; sz[u] += sz[v]; if (color[v] == -1) color[v] = color[u]; return true; } int pow_mod (int a, int b) { if (b == 0) return 1; if (b == 1) return a; int res = pow_mod(a, b/2); res = 1ll * res * res % mod; if (b & 1) res = 1ll * res * a % mod; return res; } int C (int k, int n) { int A = ifact[n]; int B = 1ll * ifact[n - k] * ifact[k] % mod; return 1ll * A * pow_mod(B, mod - 2) % mod; } int main () { file("dynamic"); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; FOR(i,1,n-k+1) cin >> a[i]; pre_calc(); FOR(i,1,n-k) { if(a[i] == a[i+1]) { join(i, i + k); } else if (a[i] > a[i+1]) { color[find(i)] = 1; color[find(i + k)] = 0; } else { color[find(i)] = 0; color[find(i + k)] = 1; } } int cnt = 0; for (int i=1; i<=k; ++i) { int c = color[find(i)]; if (c != -1) a[1] -= c; else ++cnt; } cout << C(a[1], cnt) << '\n'; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8588 KB | Output is correct |
3 | Correct | 1 ms | 8792 KB | Output is correct |
4 | Correct | 1 ms | 8540 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 1 ms | 8664 KB | Output is correct |
7 | Correct | 1 ms | 8540 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 1 ms | 8660 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 2 ms | 8540 KB | Output is correct |
12 | Correct | 1 ms | 8536 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8588 KB | Output is correct |
3 | Correct | 1 ms | 8792 KB | Output is correct |
4 | Correct | 1 ms | 8540 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 1 ms | 8664 KB | Output is correct |
7 | Correct | 1 ms | 8540 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 1 ms | 8660 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 2 ms | 8540 KB | Output is correct |
12 | Correct | 1 ms | 8536 KB | Output is correct |
13 | Correct | 1 ms | 8540 KB | Output is correct |
14 | Correct | 1 ms | 8540 KB | Output is correct |
15 | Correct | 1 ms | 8540 KB | Output is correct |
16 | Correct | 1 ms | 8540 KB | Output is correct |
17 | Correct | 1 ms | 8536 KB | Output is correct |
18 | Correct | 1 ms | 8540 KB | Output is correct |
19 | Correct | 1 ms | 8540 KB | Output is correct |
20 | Correct | 1 ms | 8540 KB | Output is correct |
21 | Correct | 1 ms | 8540 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8588 KB | Output is correct |
3 | Correct | 1 ms | 8792 KB | Output is correct |
4 | Correct | 1 ms | 8540 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 1 ms | 8664 KB | Output is correct |
7 | Correct | 1 ms | 8540 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 1 ms | 8660 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 2 ms | 8540 KB | Output is correct |
12 | Correct | 1 ms | 8536 KB | Output is correct |
13 | Correct | 1 ms | 8540 KB | Output is correct |
14 | Correct | 1 ms | 8540 KB | Output is correct |
15 | Correct | 1 ms | 8540 KB | Output is correct |
16 | Correct | 1 ms | 8540 KB | Output is correct |
17 | Correct | 1 ms | 8536 KB | Output is correct |
18 | Correct | 1 ms | 8540 KB | Output is correct |
19 | Correct | 1 ms | 8540 KB | Output is correct |
20 | Correct | 1 ms | 8540 KB | Output is correct |
21 | Correct | 1 ms | 8540 KB | Output is correct |
22 | Correct | 2 ms | 8680 KB | Output is correct |
23 | Correct | 1 ms | 8540 KB | Output is correct |
24 | Correct | 1 ms | 8540 KB | Output is correct |
25 | Correct | 1 ms | 8540 KB | Output is correct |
26 | Correct | 1 ms | 8540 KB | Output is correct |
27 | Correct | 1 ms | 8540 KB | Output is correct |
28 | Correct | 1 ms | 8540 KB | Output is correct |
29 | Correct | 1 ms | 8540 KB | Output is correct |
30 | Correct | 1 ms | 8668 KB | Output is correct |
31 | Correct | 1 ms | 8536 KB | Output is correct |
32 | Correct | 1 ms | 8540 KB | Output is correct |
33 | Correct | 2 ms | 8540 KB | Output is correct |
34 | Correct | 1 ms | 8644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8588 KB | Output is correct |
3 | Correct | 1 ms | 8792 KB | Output is correct |
4 | Correct | 1 ms | 8540 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 1 ms | 8664 KB | Output is correct |
7 | Correct | 1 ms | 8540 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 1 ms | 8660 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 2 ms | 8540 KB | Output is correct |
12 | Correct | 1 ms | 8536 KB | Output is correct |
13 | Correct | 1 ms | 8540 KB | Output is correct |
14 | Correct | 1 ms | 8540 KB | Output is correct |
15 | Correct | 1 ms | 8540 KB | Output is correct |
16 | Correct | 1 ms | 8540 KB | Output is correct |
17 | Correct | 1 ms | 8536 KB | Output is correct |
18 | Correct | 1 ms | 8540 KB | Output is correct |
19 | Correct | 1 ms | 8540 KB | Output is correct |
20 | Correct | 1 ms | 8540 KB | Output is correct |
21 | Correct | 1 ms | 8540 KB | Output is correct |
22 | Correct | 2 ms | 8680 KB | Output is correct |
23 | Correct | 1 ms | 8540 KB | Output is correct |
24 | Correct | 1 ms | 8540 KB | Output is correct |
25 | Correct | 1 ms | 8540 KB | Output is correct |
26 | Correct | 1 ms | 8540 KB | Output is correct |
27 | Correct | 1 ms | 8540 KB | Output is correct |
28 | Correct | 1 ms | 8540 KB | Output is correct |
29 | Correct | 1 ms | 8540 KB | Output is correct |
30 | Correct | 1 ms | 8668 KB | Output is correct |
31 | Correct | 1 ms | 8536 KB | Output is correct |
32 | Correct | 1 ms | 8540 KB | Output is correct |
33 | Correct | 2 ms | 8540 KB | Output is correct |
34 | Correct | 1 ms | 8644 KB | Output is correct |
35 | Correct | 49 ms | 21852 KB | Output is correct |
36 | Correct | 57 ms | 22624 KB | Output is correct |
37 | Correct | 55 ms | 22876 KB | Output is correct |
38 | Correct | 54 ms | 22708 KB | Output is correct |
39 | Correct | 48 ms | 21852 KB | Output is correct |
40 | Correct | 54 ms | 22940 KB | Output is correct |
41 | Correct | 55 ms | 22868 KB | Output is correct |
42 | Correct | 49 ms | 21840 KB | Output is correct |
43 | Correct | 49 ms | 21840 KB | Output is correct |
44 | Correct | 53 ms | 21932 KB | Output is correct |
45 | Correct | 51 ms | 21808 KB | Output is correct |
46 | Correct | 50 ms | 21964 KB | Output is correct |
47 | Correct | 48 ms | 21844 KB | Output is correct |
48 | Correct | 54 ms | 22848 KB | Output is correct |
49 | Correct | 67 ms | 22820 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8588 KB | Output is correct |
3 | Correct | 1 ms | 8792 KB | Output is correct |
4 | Correct | 1 ms | 8540 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 1 ms | 8664 KB | Output is correct |
7 | Correct | 1 ms | 8540 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 1 ms | 8660 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 2 ms | 8540 KB | Output is correct |
12 | Correct | 1 ms | 8536 KB | Output is correct |
13 | Correct | 1 ms | 8540 KB | Output is correct |
14 | Correct | 1 ms | 8540 KB | Output is correct |
15 | Correct | 1 ms | 8540 KB | Output is correct |
16 | Correct | 1 ms | 8540 KB | Output is correct |
17 | Correct | 1 ms | 8536 KB | Output is correct |
18 | Correct | 1 ms | 8540 KB | Output is correct |
19 | Correct | 1 ms | 8540 KB | Output is correct |
20 | Correct | 1 ms | 8540 KB | Output is correct |
21 | Correct | 1 ms | 8540 KB | Output is correct |
22 | Correct | 2 ms | 8680 KB | Output is correct |
23 | Correct | 1 ms | 8540 KB | Output is correct |
24 | Correct | 1 ms | 8540 KB | Output is correct |
25 | Correct | 1 ms | 8540 KB | Output is correct |
26 | Correct | 1 ms | 8540 KB | Output is correct |
27 | Correct | 1 ms | 8540 KB | Output is correct |
28 | Correct | 1 ms | 8540 KB | Output is correct |
29 | Correct | 1 ms | 8540 KB | Output is correct |
30 | Correct | 1 ms | 8668 KB | Output is correct |
31 | Correct | 1 ms | 8536 KB | Output is correct |
32 | Correct | 1 ms | 8540 KB | Output is correct |
33 | Correct | 2 ms | 8540 KB | Output is correct |
34 | Correct | 1 ms | 8644 KB | Output is correct |
35 | Correct | 49 ms | 21852 KB | Output is correct |
36 | Correct | 57 ms | 22624 KB | Output is correct |
37 | Correct | 55 ms | 22876 KB | Output is correct |
38 | Correct | 54 ms | 22708 KB | Output is correct |
39 | Correct | 48 ms | 21852 KB | Output is correct |
40 | Correct | 54 ms | 22940 KB | Output is correct |
41 | Correct | 55 ms | 22868 KB | Output is correct |
42 | Correct | 49 ms | 21840 KB | Output is correct |
43 | Correct | 49 ms | 21840 KB | Output is correct |
44 | Correct | 53 ms | 21932 KB | Output is correct |
45 | Correct | 51 ms | 21808 KB | Output is correct |
46 | Correct | 50 ms | 21964 KB | Output is correct |
47 | Correct | 48 ms | 21844 KB | Output is correct |
48 | Correct | 54 ms | 22848 KB | Output is correct |
49 | Correct | 67 ms | 22820 KB | Output is correct |
50 | Correct | 63 ms | 24884 KB | Output is correct |
51 | Correct | 63 ms | 24660 KB | Output is correct |
52 | Correct | 63 ms | 24776 KB | Output is correct |
53 | Correct | 65 ms | 24644 KB | Output is correct |
54 | Correct | 63 ms | 24656 KB | Output is correct |
55 | Correct | 65 ms | 24680 KB | Output is correct |
56 | Correct | 63 ms | 24880 KB | Output is correct |
57 | Correct | 60 ms | 23892 KB | Output is correct |
58 | Correct | 67 ms | 24656 KB | Output is correct |
59 | Correct | 63 ms | 24632 KB | Output is correct |
60 | Correct | 60 ms | 23864 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 8540 KB | Output is correct |
2 | Correct | 1 ms | 8588 KB | Output is correct |
3 | Correct | 1 ms | 8792 KB | Output is correct |
4 | Correct | 1 ms | 8540 KB | Output is correct |
5 | Correct | 1 ms | 8540 KB | Output is correct |
6 | Correct | 1 ms | 8664 KB | Output is correct |
7 | Correct | 1 ms | 8540 KB | Output is correct |
8 | Correct | 1 ms | 8540 KB | Output is correct |
9 | Correct | 1 ms | 8660 KB | Output is correct |
10 | Correct | 1 ms | 8540 KB | Output is correct |
11 | Correct | 2 ms | 8540 KB | Output is correct |
12 | Correct | 1 ms | 8536 KB | Output is correct |
13 | Correct | 1 ms | 8540 KB | Output is correct |
14 | Correct | 1 ms | 8540 KB | Output is correct |
15 | Correct | 1 ms | 8540 KB | Output is correct |
16 | Correct | 1 ms | 8540 KB | Output is correct |
17 | Correct | 1 ms | 8536 KB | Output is correct |
18 | Correct | 1 ms | 8540 KB | Output is correct |
19 | Correct | 1 ms | 8540 KB | Output is correct |
20 | Correct | 1 ms | 8540 KB | Output is correct |
21 | Correct | 1 ms | 8540 KB | Output is correct |
22 | Correct | 2 ms | 8680 KB | Output is correct |
23 | Correct | 1 ms | 8540 KB | Output is correct |
24 | Correct | 1 ms | 8540 KB | Output is correct |
25 | Correct | 1 ms | 8540 KB | Output is correct |
26 | Correct | 1 ms | 8540 KB | Output is correct |
27 | Correct | 1 ms | 8540 KB | Output is correct |
28 | Correct | 1 ms | 8540 KB | Output is correct |
29 | Correct | 1 ms | 8540 KB | Output is correct |
30 | Correct | 1 ms | 8668 KB | Output is correct |
31 | Correct | 1 ms | 8536 KB | Output is correct |
32 | Correct | 1 ms | 8540 KB | Output is correct |
33 | Correct | 2 ms | 8540 KB | Output is correct |
34 | Correct | 1 ms | 8644 KB | Output is correct |
35 | Correct | 49 ms | 21852 KB | Output is correct |
36 | Correct | 57 ms | 22624 KB | Output is correct |
37 | Correct | 55 ms | 22876 KB | Output is correct |
38 | Correct | 54 ms | 22708 KB | Output is correct |
39 | Correct | 48 ms | 21852 KB | Output is correct |
40 | Correct | 54 ms | 22940 KB | Output is correct |
41 | Correct | 55 ms | 22868 KB | Output is correct |
42 | Correct | 49 ms | 21840 KB | Output is correct |
43 | Correct | 49 ms | 21840 KB | Output is correct |
44 | Correct | 53 ms | 21932 KB | Output is correct |
45 | Correct | 51 ms | 21808 KB | Output is correct |
46 | Correct | 50 ms | 21964 KB | Output is correct |
47 | Correct | 48 ms | 21844 KB | Output is correct |
48 | Correct | 54 ms | 22848 KB | Output is correct |
49 | Correct | 67 ms | 22820 KB | Output is correct |
50 | Correct | 63 ms | 24884 KB | Output is correct |
51 | Correct | 63 ms | 24660 KB | Output is correct |
52 | Correct | 63 ms | 24776 KB | Output is correct |
53 | Correct | 65 ms | 24644 KB | Output is correct |
54 | Correct | 63 ms | 24656 KB | Output is correct |
55 | Correct | 65 ms | 24680 KB | Output is correct |
56 | Correct | 63 ms | 24880 KB | Output is correct |
57 | Correct | 60 ms | 23892 KB | Output is correct |
58 | Correct | 67 ms | 24656 KB | Output is correct |
59 | Correct | 63 ms | 24632 KB | Output is correct |
60 | Correct | 60 ms | 23864 KB | Output is correct |
61 | Correct | 8 ms | 16988 KB | Output is correct |
62 | Correct | 8 ms | 16848 KB | Output is correct |
63 | Correct | 8 ms | 16988 KB | Output is correct |
64 | Correct | 8 ms | 16984 KB | Output is correct |
65 | Correct | 39 ms | 22508 KB | Output is correct |
66 | Correct | 31 ms | 21528 KB | Output is correct |
67 | Correct | 71 ms | 24664 KB | Output is correct |
68 | Correct | 13 ms | 17496 KB | Output is correct |
69 | Correct | 8 ms | 16988 KB | Output is correct |
70 | Correct | 8 ms | 16864 KB | Output is correct |
71 | Correct | 8 ms | 16984 KB | Output is correct |