Submission #1287709

#TimeUsernameProblemLanguageResultExecution timeMemory
1287709hssaan_arifBinaria (CCO23_day1problem1)C++20
10 / 25
11 ms2724 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back #define int long long const int N = 3e5 + 5, M = 1e9 + 7, LG = 20; int n , k , A[N]; void solve(){ cin >> n >> k; int ans = 0; for (int i=0 ; i<(n-k+1) ; i++) cin >> A[i]; for (int i=0 ; i < (1<<k) ; i++){ if (__builtin_popcount(i) == A[0]){ int u = __builtin_popcount(i); string s = ""; for (int j=0 ; j<k ; j++){ if (i&(1<<j)){ s += '1'; }else{ s += '0'; } } bool ch = 1; for (int j=k ; j<n ; j++){ if (s[j-k] == '0'){ if (u == A[j-k+1]){ s += '0'; }else if (u+1 == A[j-k+1]){ s += '1'; u++; }else{ ch = 0; break; } }else{ u--; if (u == A[j-k+1]){ s += '0'; }else if (u+1 == A[j-k+1]){ s += '1'; u++; }else{ ch = 0; break; } } } if (ch){ ans++; } } } cout << ans << endl; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ts = 1; // cin >> ts; while(ts--){ solve(); } }
#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...