답안 #1113058

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113058 2024-11-15T15:03:18 Z duckindog Binaria (CCO23_day1problem1) C++17
25 / 25
91 ms 32756 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2'000'000 + 10,
          M = 1'000'003;
int n, k;
int a[N];

int id[N];
int root(int u) { return id[u] < 0 ? u : id[u] = root(id[u]); }
void add(int u, int v) {
  u = root(u); v = root(v);
  if (u == v) return;
  if (id[u] > id[v]) swap(u, v);
  id[u] += id[v];
  id[v] = u;
}

int idx[N][2];

int powder(int a, int b) { 
  int ret = 1;
  for (; b; b /= 2, a = 1ll * a * a % M) { 
    if (b & 1) ret = 1ll * ret * a % M;
  }
  return ret;
}

int fac[N], ifac[N];
void init() { 
  const int SZ = 1'000'000;
  fac[0] = 1;
  for (int i = 1; i <= SZ; ++i) fac[i] = 1ll * fac[i - 1] * i % M;
  
  ifac[SZ] = powder(fac[SZ], M - 2);
  for (int i = SZ; i >= 1; --i) ifac[i - 1] = 1ll * ifac[i] * i % M;
}
inline int C(int n, int k) { return 1ll * fac[n] * ifac[n - k] % M * ifac[k] % M; }

int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);

  cin >> n >> k;
  for (int i = k; i <= n; ++i) cin >> a[i];

  int possible = 0, impossible = 1;
  for (int i = 1; i <= n; ++i) idx[i][0] = 2 * i, idx[i][1] = 2 * i + 1;
  
  memset(id, -1, sizeof id);
  for (int i = k + 1; i <= n; ++i) { 
    if (a[i] - a[i - 1] == 1) { 
      add(idx[i][1], possible);
      add(idx[i - k][0], possible);

      add(idx[i][0], impossible);
      add(idx[i - k][1], impossible);
    }
    
    if (a[i] - a[i - 1] == -1) { 
      add(idx[i][0], possible);
      add(idx[i - k][1], possible);
      
      add(idx[i][1], impossible);
      add(idx[i - k][0], impossible);
    }

    if (a[i] - a[i - 1] == 0) { 
      add(idx[i][0], idx[i - k][0]);
      add(idx[i][1], idx[i - k][1]);
    }
  }

  for (int i = 1; i <= n; ++i)
    if (root(idx[i][0]) == root(idx[i][1])) { cout << 0 << "\n"; return 0; }
  
  int sum = a[k], cnt = 0;
  for (int i = 1; i <= k; ++i) { 
    if (root(idx[i][1]) == root(possible)) sum -= 1;
    else if (root(idx[i][0]) != root(possible)) cnt += 1;
  }
  
  init();
  cout << C(cnt, sum) << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 15952 KB Output is correct
2 Correct 21 ms 15960 KB Output is correct
3 Correct 20 ms 15944 KB Output is correct
4 Correct 22 ms 16100 KB Output is correct
5 Correct 21 ms 15952 KB Output is correct
6 Correct 22 ms 15952 KB Output is correct
7 Correct 21 ms 15952 KB Output is correct
8 Correct 21 ms 16052 KB Output is correct
9 Correct 20 ms 15944 KB Output is correct
10 Correct 20 ms 15952 KB Output is correct
11 Correct 20 ms 15952 KB Output is correct
12 Correct 21 ms 15944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 15952 KB Output is correct
2 Correct 21 ms 15960 KB Output is correct
3 Correct 20 ms 15944 KB Output is correct
4 Correct 22 ms 16100 KB Output is correct
5 Correct 21 ms 15952 KB Output is correct
6 Correct 22 ms 15952 KB Output is correct
7 Correct 21 ms 15952 KB Output is correct
8 Correct 21 ms 16052 KB Output is correct
9 Correct 20 ms 15944 KB Output is correct
10 Correct 20 ms 15952 KB Output is correct
11 Correct 20 ms 15952 KB Output is correct
12 Correct 21 ms 15944 KB Output is correct
13 Correct 21 ms 15952 KB Output is correct
14 Correct 20 ms 15952 KB Output is correct
15 Correct 21 ms 15952 KB Output is correct
16 Correct 21 ms 15952 KB Output is correct
17 Correct 20 ms 15952 KB Output is correct
18 Correct 20 ms 15952 KB Output is correct
19 Correct 20 ms 15940 KB Output is correct
20 Correct 24 ms 15944 KB Output is correct
21 Correct 22 ms 15944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 15952 KB Output is correct
2 Correct 21 ms 15960 KB Output is correct
3 Correct 20 ms 15944 KB Output is correct
4 Correct 22 ms 16100 KB Output is correct
5 Correct 21 ms 15952 KB Output is correct
6 Correct 22 ms 15952 KB Output is correct
7 Correct 21 ms 15952 KB Output is correct
8 Correct 21 ms 16052 KB Output is correct
9 Correct 20 ms 15944 KB Output is correct
10 Correct 20 ms 15952 KB Output is correct
11 Correct 20 ms 15952 KB Output is correct
12 Correct 21 ms 15944 KB Output is correct
13 Correct 21 ms 15952 KB Output is correct
14 Correct 20 ms 15952 KB Output is correct
15 Correct 21 ms 15952 KB Output is correct
16 Correct 21 ms 15952 KB Output is correct
17 Correct 20 ms 15952 KB Output is correct
18 Correct 20 ms 15952 KB Output is correct
19 Correct 20 ms 15940 KB Output is correct
20 Correct 24 ms 15944 KB Output is correct
21 Correct 22 ms 15944 KB Output is correct
22 Correct 22 ms 15952 KB Output is correct
23 Correct 21 ms 16000 KB Output is correct
24 Correct 21 ms 15952 KB Output is correct
25 Correct 20 ms 15952 KB Output is correct
26 Correct 21 ms 16068 KB Output is correct
27 Correct 21 ms 15952 KB Output is correct
28 Correct 24 ms 15964 KB Output is correct
29 Correct 21 ms 15948 KB Output is correct
30 Correct 21 ms 16108 KB Output is correct
31 Correct 22 ms 16088 KB Output is correct
32 Correct 22 ms 15952 KB Output is correct
33 Correct 20 ms 15952 KB Output is correct
34 Correct 20 ms 16012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 15952 KB Output is correct
2 Correct 21 ms 15960 KB Output is correct
3 Correct 20 ms 15944 KB Output is correct
4 Correct 22 ms 16100 KB Output is correct
5 Correct 21 ms 15952 KB Output is correct
6 Correct 22 ms 15952 KB Output is correct
7 Correct 21 ms 15952 KB Output is correct
8 Correct 21 ms 16052 KB Output is correct
9 Correct 20 ms 15944 KB Output is correct
10 Correct 20 ms 15952 KB Output is correct
11 Correct 20 ms 15952 KB Output is correct
12 Correct 21 ms 15944 KB Output is correct
13 Correct 21 ms 15952 KB Output is correct
14 Correct 20 ms 15952 KB Output is correct
15 Correct 21 ms 15952 KB Output is correct
16 Correct 21 ms 15952 KB Output is correct
17 Correct 20 ms 15952 KB Output is correct
18 Correct 20 ms 15952 KB Output is correct
19 Correct 20 ms 15940 KB Output is correct
20 Correct 24 ms 15944 KB Output is correct
21 Correct 22 ms 15944 KB Output is correct
22 Correct 22 ms 15952 KB Output is correct
23 Correct 21 ms 16000 KB Output is correct
24 Correct 21 ms 15952 KB Output is correct
25 Correct 20 ms 15952 KB Output is correct
26 Correct 21 ms 16068 KB Output is correct
27 Correct 21 ms 15952 KB Output is correct
28 Correct 24 ms 15964 KB Output is correct
29 Correct 21 ms 15948 KB Output is correct
30 Correct 21 ms 16108 KB Output is correct
31 Correct 22 ms 16088 KB Output is correct
32 Correct 22 ms 15952 KB Output is correct
33 Correct 20 ms 15952 KB Output is correct
34 Correct 20 ms 16012 KB Output is correct
35 Correct 71 ms 29768 KB Output is correct
36 Correct 75 ms 30280 KB Output is correct
37 Correct 74 ms 30792 KB Output is correct
38 Correct 82 ms 30768 KB Output is correct
39 Correct 68 ms 29760 KB Output is correct
40 Correct 77 ms 30792 KB Output is correct
41 Correct 71 ms 30704 KB Output is correct
42 Correct 72 ms 29800 KB Output is correct
43 Correct 65 ms 29772 KB Output is correct
44 Correct 66 ms 29780 KB Output is correct
45 Correct 64 ms 29812 KB Output is correct
46 Correct 64 ms 29768 KB Output is correct
47 Correct 65 ms 29780 KB Output is correct
48 Correct 71 ms 30576 KB Output is correct
49 Correct 69 ms 30792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 15952 KB Output is correct
2 Correct 21 ms 15960 KB Output is correct
3 Correct 20 ms 15944 KB Output is correct
4 Correct 22 ms 16100 KB Output is correct
5 Correct 21 ms 15952 KB Output is correct
6 Correct 22 ms 15952 KB Output is correct
7 Correct 21 ms 15952 KB Output is correct
8 Correct 21 ms 16052 KB Output is correct
9 Correct 20 ms 15944 KB Output is correct
10 Correct 20 ms 15952 KB Output is correct
11 Correct 20 ms 15952 KB Output is correct
12 Correct 21 ms 15944 KB Output is correct
13 Correct 21 ms 15952 KB Output is correct
14 Correct 20 ms 15952 KB Output is correct
15 Correct 21 ms 15952 KB Output is correct
16 Correct 21 ms 15952 KB Output is correct
17 Correct 20 ms 15952 KB Output is correct
18 Correct 20 ms 15952 KB Output is correct
19 Correct 20 ms 15940 KB Output is correct
20 Correct 24 ms 15944 KB Output is correct
21 Correct 22 ms 15944 KB Output is correct
22 Correct 22 ms 15952 KB Output is correct
23 Correct 21 ms 16000 KB Output is correct
24 Correct 21 ms 15952 KB Output is correct
25 Correct 20 ms 15952 KB Output is correct
26 Correct 21 ms 16068 KB Output is correct
27 Correct 21 ms 15952 KB Output is correct
28 Correct 24 ms 15964 KB Output is correct
29 Correct 21 ms 15948 KB Output is correct
30 Correct 21 ms 16108 KB Output is correct
31 Correct 22 ms 16088 KB Output is correct
32 Correct 22 ms 15952 KB Output is correct
33 Correct 20 ms 15952 KB Output is correct
34 Correct 20 ms 16012 KB Output is correct
35 Correct 71 ms 29768 KB Output is correct
36 Correct 75 ms 30280 KB Output is correct
37 Correct 74 ms 30792 KB Output is correct
38 Correct 82 ms 30768 KB Output is correct
39 Correct 68 ms 29760 KB Output is correct
40 Correct 77 ms 30792 KB Output is correct
41 Correct 71 ms 30704 KB Output is correct
42 Correct 72 ms 29800 KB Output is correct
43 Correct 65 ms 29772 KB Output is correct
44 Correct 66 ms 29780 KB Output is correct
45 Correct 64 ms 29812 KB Output is correct
46 Correct 64 ms 29768 KB Output is correct
47 Correct 65 ms 29780 KB Output is correct
48 Correct 71 ms 30576 KB Output is correct
49 Correct 69 ms 30792 KB Output is correct
50 Correct 79 ms 32580 KB Output is correct
51 Correct 79 ms 32584 KB Output is correct
52 Correct 79 ms 32584 KB Output is correct
53 Correct 82 ms 32756 KB Output is correct
54 Correct 79 ms 32588 KB Output is correct
55 Correct 80 ms 32584 KB Output is correct
56 Correct 83 ms 32688 KB Output is correct
57 Correct 77 ms 31764 KB Output is correct
58 Correct 81 ms 32584 KB Output is correct
59 Correct 81 ms 32584 KB Output is correct
60 Correct 81 ms 31564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 15952 KB Output is correct
2 Correct 21 ms 15960 KB Output is correct
3 Correct 20 ms 15944 KB Output is correct
4 Correct 22 ms 16100 KB Output is correct
5 Correct 21 ms 15952 KB Output is correct
6 Correct 22 ms 15952 KB Output is correct
7 Correct 21 ms 15952 KB Output is correct
8 Correct 21 ms 16052 KB Output is correct
9 Correct 20 ms 15944 KB Output is correct
10 Correct 20 ms 15952 KB Output is correct
11 Correct 20 ms 15952 KB Output is correct
12 Correct 21 ms 15944 KB Output is correct
13 Correct 21 ms 15952 KB Output is correct
14 Correct 20 ms 15952 KB Output is correct
15 Correct 21 ms 15952 KB Output is correct
16 Correct 21 ms 15952 KB Output is correct
17 Correct 20 ms 15952 KB Output is correct
18 Correct 20 ms 15952 KB Output is correct
19 Correct 20 ms 15940 KB Output is correct
20 Correct 24 ms 15944 KB Output is correct
21 Correct 22 ms 15944 KB Output is correct
22 Correct 22 ms 15952 KB Output is correct
23 Correct 21 ms 16000 KB Output is correct
24 Correct 21 ms 15952 KB Output is correct
25 Correct 20 ms 15952 KB Output is correct
26 Correct 21 ms 16068 KB Output is correct
27 Correct 21 ms 15952 KB Output is correct
28 Correct 24 ms 15964 KB Output is correct
29 Correct 21 ms 15948 KB Output is correct
30 Correct 21 ms 16108 KB Output is correct
31 Correct 22 ms 16088 KB Output is correct
32 Correct 22 ms 15952 KB Output is correct
33 Correct 20 ms 15952 KB Output is correct
34 Correct 20 ms 16012 KB Output is correct
35 Correct 71 ms 29768 KB Output is correct
36 Correct 75 ms 30280 KB Output is correct
37 Correct 74 ms 30792 KB Output is correct
38 Correct 82 ms 30768 KB Output is correct
39 Correct 68 ms 29760 KB Output is correct
40 Correct 77 ms 30792 KB Output is correct
41 Correct 71 ms 30704 KB Output is correct
42 Correct 72 ms 29800 KB Output is correct
43 Correct 65 ms 29772 KB Output is correct
44 Correct 66 ms 29780 KB Output is correct
45 Correct 64 ms 29812 KB Output is correct
46 Correct 64 ms 29768 KB Output is correct
47 Correct 65 ms 29780 KB Output is correct
48 Correct 71 ms 30576 KB Output is correct
49 Correct 69 ms 30792 KB Output is correct
50 Correct 79 ms 32580 KB Output is correct
51 Correct 79 ms 32584 KB Output is correct
52 Correct 79 ms 32584 KB Output is correct
53 Correct 82 ms 32756 KB Output is correct
54 Correct 79 ms 32588 KB Output is correct
55 Correct 80 ms 32584 KB Output is correct
56 Correct 83 ms 32688 KB Output is correct
57 Correct 77 ms 31764 KB Output is correct
58 Correct 81 ms 32584 KB Output is correct
59 Correct 81 ms 32584 KB Output is correct
60 Correct 81 ms 31564 KB Output is correct
61 Correct 32 ms 23880 KB Output is correct
62 Correct 33 ms 23788 KB Output is correct
63 Correct 29 ms 23884 KB Output is correct
64 Correct 31 ms 23948 KB Output is correct
65 Correct 66 ms 29256 KB Output is correct
66 Correct 56 ms 27464 KB Output is correct
67 Correct 91 ms 32368 KB Output is correct
68 Correct 36 ms 24616 KB Output is correct
69 Correct 31 ms 23892 KB Output is correct
70 Correct 30 ms 23888 KB Output is correct
71 Correct 32 ms 23772 KB Output is correct