# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1027272 | 2024-07-19T03:03:16 Z | khanhtb | Binaria (CCO23_day1problem1) | C++14 | 12 ms | 19052 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Incorrect | 12 ms | 19052 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Incorrect | 12 ms | 19052 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Incorrect | 12 ms | 19052 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Incorrect | 12 ms | 19052 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Incorrect | 12 ms | 19052 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4444 KB | Output is correct |
3 | Incorrect | 12 ms | 19052 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |