제출 #1287723

#제출 시각아이디문제언어결과실행 시간메모리
1287723hynmjBinaria (CCO23_day1problem1)C++20
0 / 25
2 ms1856 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const long long N = 2e5 + 5; int a[N]; int b[N]; int f[N]; const int mod = 1e6 + 3; int po(int n, int k = mod - 2) { if (k == 0) return 1; else if (k & 1) return n * po((n * n) % mod, k / 2) % mod; return po((n * n) % mod, k / 2); } int ncr(int n, int k) { return ((f[n] * po(f[k]) % mod) * po(f[n - k])) % mod; } void solve() { int n, k; cin >> n >> k; for (int i = 0; i < n - k + 1; i++) { cin >> b[i]; } for (int i = 0; i <= n; i++) { a[i] = -1; } for (int i = 0; i + k < n; i++) { // cout << b[i] << ' ' << b[i + 1] << endl; if (b[i] == b[i + 1]) { continue; } else if (b[i] + 1 == b[i + 1]) { if (a[i] != 0 and a[i] != -1) { cout << 0; return; } if (a[i + k] != 1 and a[i + k] != -1) { cout << 0; return; } a[i] = 0; a[i + k] = 1; } else if (b[i] == b[i + 1] + 1) { if (a[i] != 1 and a[i] != -1) { cout << 0; return; } if (a[i + k] != 0 and a[i + k] != -1) { cout << 0; return; } a[i] = 1; a[i + k] = 0; } else { cout << 0; return; } } int choices = 0; int sum = 0; for (int i = 0; i < k; i++) { int l; if (a[i] != -1) { continue; } l = -1; for (int j = i; j < n; j += k) { if (a[j] != -1) { l = a[j]; } // if (l!=-1 and a[j]!=l) // { // cout << 0; // return; // } } for (int j = i; j < n; j += k) { if (a[j] == -1) { a[j] = l; } else if (a[j] != l) { // for (int i = 0; i < n; i++) // { // cout << a[i] << ' '; // } // return; cout << 0; return; } } } for (int i = 0; i < k; i++) { if (a[i] == -1) { choices++; } else { sum += a[i]; } } // for (int i = 0; i < n; i++) // { // cout << a[i] << ' ' << endl; // } // cout << sum << ' ' << b[0] << endl; cout << ncr(choices, b[0] - sum); } signed main() { f[0] = 1; for (int i = 1; i < N; i++) { f[i] = (f[i - 1] * i) % mod; } ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout << "Case #" << i << ':' << ' '; solve(); cout << endl; } return 0; }
#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...