Submission #1026368

#TimeUsernameProblemLanguageResultExecution timeMemory
1026368WhisperBinaria (CCO23_day1problem1)C++17
25 / 25
243 ms115284 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, n) for (int i = 0; i < (a); ++i) #define REPD(i, n) for (int i = (a) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e6 + 3; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } #define MAX 1000005 int N, K, M; int A[MAX]; int inv[MAX], fac[MAX]; int power(int a, int exp){ int res = 1; for (;exp > 0; a = (a * a) % Mod, exp >>= 1) if(exp & 1){ res = (res * a) % Mod; } return res; } void genFac(int n){ fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % Mod; inv[n] = power(fac[n], Mod - 2); for (int i = n - 1; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % Mod; } int C(int n, int k){ if (n < k || k < 0) return 0; return fac[n] * inv[k] % Mod * inv[n - k] % Mod; } void mul(int &x, int y){ x = (1ll * x * y) % Mod; } void add(int &x, int y){ x += y; if (x >= Mod) x -= Mod; } vector<int> G[MAX]; int col[MAX]; int vis[MAX]; void paint(int u, int c){ vis[u] = 1; col[u] = c; for (int&v : G[u]) if(!vis[v]){ paint(v, c); } } void process(void){ cin >> N >> K; M = N - K + 1; for (int i = 1; i <= M; ++i) cin >> A[i]; genFac(N); for (int i = 1; i <= N; ++i) col[i] = -1; for (int i = 1; i < M; ++i){ if(A[i] == A[i + 1]){ G[i].push_back(i + K); G[i + K].push_back(i); } else if(A[i] + 1 == A[i + 1]){ col[i] = 0, col[i + K] = 1; } else if(A[i] - 1 == A[i + 1]){ col[i] = 1, col[i + K] = 0; } else return void(cout << 0); } vector<int> vis(K + 5); for (int i = 1; i <= N; ++i){ if (~col[i]){ paint(i, col[i]); } } for (int i = 1; i < M; ++i){ if (A[i] == A[i + 1]){ if(col[i] != col[i + K]) return void(cout << 0); } else if (A[i] < A[i + 1]) { if(!(col[i] == 0 && col[i + K] == 1)) return void(cout << 0); } else{ if(!(col[i] == 1 && col[i + K] == 0)) return void(cout << 0); } } int need = A[1], emp = 0; for (int i = 1; i <= K; ++i){ if (col[i] == -1) emp++; else if(col[i] == 1) need--; } assert(emp >= 0); cout << C(emp, need); } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); process(); return (0 ^ 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...