Submission #1123808

#TimeUsernameProblemLanguageResultExecution timeMemory
1123808wikidereBinaria (CCO23_day1problem1)C++17
6 / 25
0 ms328 KiB
#include <bits/stdc++.h> #define N 1000010 #define task "task" #define pii pair<int, int> #define ll long long using namespace std; const int base = 1e6 + 3; int n, k, a[N]; namespace sub1 { int dp[1010][1 << 10] = {}; void solve() { for (int mask = 0; mask < (1 << k); mask++) dp[1][mask] = (__builtin_popcount(mask) == a[1]); for (int i = 2; i <= n - k + 1; i++) for (int mask1 = 0; mask1 < (1 << k); mask1++) for (int mask2 = 0; mask2 < (1 << k); mask2++) if ((mask2 >> 1) == (mask1 & ((1 << (k - 1)) - 1))) if (__builtin_popcount(mask1) == a[i - 1] && __builtin_popcount(mask2) == a[i]) (dp[i][mask2] += dp[i - 1][mask1]) %= base; int res = 0; for (int mask = 1; mask < (1 << k); mask++) (res += dp[n - k + 1][mask]) %= base; cout << res; } }; namespace sub0 { void solve() { int res = 0; for (int mask = 0; mask < (1 << n); mask++) { int cnt = 0; for (int i = 0; i < k; i++) cnt += (mask >> i & 1); if (a[1] != cnt) continue; if (mask == 77) { int jj; jj--; } int l = 0, r = k - 1; bool check = true; for (int i = 2; i <= n - k + 1; i++) { cnt -= (mask >> l++ & 1); cnt += (mask >> ++r & 1); if (cnt != a[i]) { check = false; break; } } res += check; } cout << res % base; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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 (n <= 10 && k <= 10) sub0::solve(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         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...