Submission #1027272

#TimeUsernameProblemLanguageResultExecution timeMemory
1027272khanhtbBinaria (CCO23_day1problem1)C++14
0 / 25
12 ms19052 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define ld long double #define pb push_back #define pf push_front #define vi vector<ll> #define vii vector<vi> #define pll pair<ll, ll> #define vpll vector<pll> #define all(a) a.begin(), a.end() #define fi first #define se second using namespace std; const ll mod = 1e6 + 3; const ll inf = 2e18; const ll blocksz = 320; const ll N = 1e6 + 5; ll n,fac[N],invfac[N]; ll bipow(ll a, ll b){ ll ans = 1; while(b){ if(b&1) ans = ans*a%mod; a = a*a%mod; b>>=1; } return ans; } void precalc(){ fac[0] = 1; for(ll i = 1; i < N; i++) fac[i] = fac[i-1]*i%mod; invfac[N-1] = bipow(fac[N-1],mod-2); for(ll i = N-2; i >= 0; i--) invfac[i] = invfac[i+1]*(i+1)%mod; } ll C(ll k, ll n){ if(k > n) return 0; return ((fac[n]*invfac[k])%mod)*invfac[n-k]%mod; } ll k,a[N]; ll d[N]; bool ok = 1; void update(ll i){ for(ll j = i-k; j >= 1; j--){ if(a[j] != -1){ if(a[j] != (a[j+k]^1)) ok = 0; break; } a[j] = a[j+k]^1; } for(ll j = i+k; j <= n; j += k){ if(a[j] != -1){ if(a[j] != (a[j-k]^1)) ok = 0; break; } a[j] = (a[j-k]^1); } } void solve(){ cin >> n >> k; fill(a,a+n+1,-1); for(ll i = 1; i <= n-k+1; i++) cin >> d[i]; if(k == 1){ if(*max_element(d+1,d+n-k+1+1) != *min_element(d+1,d+n-k+1+1)) cout << 0; else cout << 1; return; } for(ll i = k+1; i <= n; i++){ if(d[i-k+1] != d[i-k]){ if(d[i-k+1] > d[i-k]) a[i] = 1, a[i-k] = 0; else a[i] = 0, a[i-k] = 1; update(i), update(i-k); } } precalc(); ll cnt = 0; ll n1 = d[1]; for(ll i = 1; i <= k; i++){ if(a[i] == -1) cnt++; if(a[i] == 1) n1--; } cout << ok*C(n1,cnt); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("test.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll T = 1; // cin >> T; for (ll i = 1; i <= T; i++){ solve(); cout << '\n'; } }

Compilation message (stderr)

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