답안 #1113226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113226 2024-11-16T05:09:06 Z ntdaccode Binaria (CCO23_day1problem1) C++17
25 / 25
90 ms 41488 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i = a;i <= b; i++)
#define int long long

using namespace std;

typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;

const int M = 2e6 + 10;
const int N = 1e3 + 10;
const int mod = 1e6 + 3;

int n,k,a[M],id[M];

int finded(int u)
{
  return (id[u] < 0 ? u : id[u] = finded(id[u]));
}

void unioned(int u,int v)
{
  u = finded(u);
  v = finded(v);
  if(u == v) return ;
  if(u < v) swap(u,v);
  id[u] += id[v];
  id[v] = u;
  return ;
}

int power(int a,int m)
{
  if(m == 0) return 1;
  int t = power(a,m/2);
  t = (t * t) % mod;
  if(m % 2) t = (t * a) % mod;
  return t;
}

int C(int k,int n)
{
  if(k > n) return 0;
  int res = 1;
  for(int i = k + 1;i <= n; i++) res = (res * (i % mod) ) % mod;
  int du = 1;
  for(int i = 1;i <= n - k; i++) du = (du * (i % mod) ) % mod;
  du = power(du,mod - 2) % mod;
  return (res * du) % mod;
}
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if(fopen("1.inp","r"))
  {
    freopen("1.inp","r",stdin);
    freopen("1.out","w",stdout);
  }
  #define task ""
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }

  cin >> n >> k;
  for(int i = 1;i <= n - k + 1; i++) cin >> a[i];
  for(int i = 1;i <= 2 * n + 1; i++) id[i] = -1;
  for(int i = 1;i <= n - k ; i++) {
    if(abs(a[i] - a[i + 1]) > 1 || a[i] > k || a[i + 1] > k ) {
        cout << 0 ;
        return 0;
    }
    if(a[i] == a[i + 1]) {
        unioned(i,i + k );
        unioned(i + n,i + k + n);
        //cout << i + k  - 1 << " " << i + k - 1 + n << "\n";
    }
    if(a[i] == a[i + 1] + 1) {
      unioned(i + n,i + k);
      unioned(i,2 * n + 1);
      unioned(i + k + n,2 * n + 1);
    }
    if(a[i] == a[i + 1] - 1) {
      unioned(i,i + k + n);
      unioned(i + n, 2 * n + 1);
      unioned(i + k, 2 * n + 1);
    }
  }
  int K = k;
  for(int i = 1;i <= k ; i++) {
    int u = finded(i);
    int v = finded(i + n);
    if(u == 2 * n + 1 && v == 2 * n + 1) {
      cout << 0;
      return 0;
    }
    if(v == 2 * n + 1) K--;
    if(u == 2 * n + 1) K--,a[1]--;
  }

  cout << C(a[1],K) % mod;
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:59:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 476 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 476 KB Output is correct
34 Correct 1 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 476 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 476 KB Output is correct
34 Correct 1 ms 508 KB Output is correct
35 Correct 68 ms 26440 KB Output is correct
36 Correct 70 ms 27256 KB Output is correct
37 Correct 70 ms 27592 KB Output is correct
38 Correct 71 ms 27464 KB Output is correct
39 Correct 73 ms 26680 KB Output is correct
40 Correct 74 ms 27472 KB Output is correct
41 Correct 75 ms 27464 KB Output is correct
42 Correct 68 ms 26952 KB Output is correct
43 Correct 68 ms 26696 KB Output is correct
44 Correct 87 ms 41436 KB Output is correct
45 Correct 68 ms 25680 KB Output is correct
46 Correct 78 ms 41488 KB Output is correct
47 Correct 71 ms 33608 KB Output is correct
48 Correct 80 ms 27428 KB Output is correct
49 Correct 71 ms 27596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 476 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 476 KB Output is correct
34 Correct 1 ms 508 KB Output is correct
35 Correct 68 ms 26440 KB Output is correct
36 Correct 70 ms 27256 KB Output is correct
37 Correct 70 ms 27592 KB Output is correct
38 Correct 71 ms 27464 KB Output is correct
39 Correct 73 ms 26680 KB Output is correct
40 Correct 74 ms 27472 KB Output is correct
41 Correct 75 ms 27464 KB Output is correct
42 Correct 68 ms 26952 KB Output is correct
43 Correct 68 ms 26696 KB Output is correct
44 Correct 87 ms 41436 KB Output is correct
45 Correct 68 ms 25680 KB Output is correct
46 Correct 78 ms 41488 KB Output is correct
47 Correct 71 ms 33608 KB Output is correct
48 Correct 80 ms 27428 KB Output is correct
49 Correct 71 ms 27596 KB Output is correct
50 Correct 89 ms 28744 KB Output is correct
51 Correct 80 ms 28580 KB Output is correct
52 Correct 79 ms 28744 KB Output is correct
53 Correct 89 ms 28744 KB Output is correct
54 Correct 89 ms 28744 KB Output is correct
55 Correct 90 ms 28776 KB Output is correct
56 Correct 79 ms 28544 KB Output is correct
57 Correct 82 ms 27720 KB Output is correct
58 Correct 79 ms 28756 KB Output is correct
59 Correct 79 ms 28724 KB Output is correct
60 Correct 77 ms 27644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 508 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 476 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 476 KB Output is correct
34 Correct 1 ms 508 KB Output is correct
35 Correct 68 ms 26440 KB Output is correct
36 Correct 70 ms 27256 KB Output is correct
37 Correct 70 ms 27592 KB Output is correct
38 Correct 71 ms 27464 KB Output is correct
39 Correct 73 ms 26680 KB Output is correct
40 Correct 74 ms 27472 KB Output is correct
41 Correct 75 ms 27464 KB Output is correct
42 Correct 68 ms 26952 KB Output is correct
43 Correct 68 ms 26696 KB Output is correct
44 Correct 87 ms 41436 KB Output is correct
45 Correct 68 ms 25680 KB Output is correct
46 Correct 78 ms 41488 KB Output is correct
47 Correct 71 ms 33608 KB Output is correct
48 Correct 80 ms 27428 KB Output is correct
49 Correct 71 ms 27596 KB Output is correct
50 Correct 89 ms 28744 KB Output is correct
51 Correct 80 ms 28580 KB Output is correct
52 Correct 79 ms 28744 KB Output is correct
53 Correct 89 ms 28744 KB Output is correct
54 Correct 89 ms 28744 KB Output is correct
55 Correct 90 ms 28776 KB Output is correct
56 Correct 79 ms 28544 KB Output is correct
57 Correct 82 ms 27720 KB Output is correct
58 Correct 79 ms 28756 KB Output is correct
59 Correct 79 ms 28724 KB Output is correct
60 Correct 77 ms 27644 KB Output is correct
61 Correct 16 ms 16128 KB Output is correct
62 Correct 17 ms 15952 KB Output is correct
63 Correct 13 ms 15952 KB Output is correct
64 Correct 15 ms 15952 KB Output is correct
65 Correct 45 ms 23368 KB Output is correct
66 Correct 37 ms 21072 KB Output is correct
67 Correct 68 ms 27720 KB Output is correct
68 Correct 25 ms 17232 KB Output is correct
69 Correct 11 ms 15912 KB Output is correct
70 Correct 20 ms 16116 KB Output is correct
71 Correct 16 ms 16068 KB Output is correct