Submission #1038818

#TimeUsernameProblemLanguageResultExecution timeMemory
1038818vjudge1Binaria (CCO23_day1problem1)C++17
25 / 25
122 ms16112 KiB
// dm fryingduc #include <bits/stdc++.h> using namespace std; #define int long long #define fore(i, a, b) for (int i = (a); i <= (b); i++) #define pb emplace_back const int mod = 1e6 + 3; int binpow(int a, int b) { if (b == 0) return 1ll; int ans = binpow(a, b / 2ll); return ans * ans % mod * (b & 1ll ? a : 1ll) % mod; } int nCk(int n, int k) { int ans = 1; if (k > n || n < 0 || k < 0) return 0; fore(i, k + 1, n) ans = ans * i % mod; fore(i, 1, n - k) ans = ans * binpow(i, mod - 2) % mod; return ans; } signed main() { cin.tie(0)->sync_with_stdio(0); int n, k; cin >> n >> k; vector<int> a(n - k + 2), x(n + 1, -1); fore(i, 1, n - k + 1) cin >> a[i]; fore(i, 2, n - k + 1) if (abs(a[i] - a[i - 1]) > 1) return cout << 0, 0; fore(i, 2, n - k + 1) { if (a[i] - a[i - 1] == 1) x[i + k - 1] = 1, x[i - 1] = 0; else if (a[i] - a[i - 1] == -1) x[i + k - 1] = 0, x[i - 1] = 1; else x[i + k - 1] = x[i - 1]; } for (int i = n - k; i >= 1; i--) if (a[i] == a[i + 1]) x[i] = x[i + k]; int use = 0; fore(i, 1, k) use += (x[i] == -1), a[1] -= (x[i] == 1); cout << nCk(use, a[1]); 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...