Submission #1113221

#TimeUsernameProblemLanguageResultExecution timeMemory
1113221ntdaccodeBinaria (CCO23_day1problem1)C++17
10 / 25
46 ms17992 KiB
#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 = 1e6 + 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; int du = 1; for(int i = 1;i <= n - k; i++) du = (du * i) % mod; du = power(du,mod - 2); 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]; if(k == 1) { cout << 1 << "\n"; return 0; } 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) { 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); // cout << i << " " << u << " " << v << "\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 << u << " " << v << "\n"; } //cout << a[1] << " " << K << "\n"; cout << C(a[1],K) % mod; }

Compilation message (stderr)

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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...