Submission #852857

#TimeUsernameProblemLanguageResultExecution timeMemory
852857hngwlogBinaria (CCO23_day1problem1)C++14
25 / 25
183 ms74776 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define _size(x) (int)x.size() #define BIT(i, x) ((x >> i) & 1) #define MASK(n) ((1 << n) - 1) #define REP(i, n) for (int i = 0, _n = (n); i < _n; i++) #define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++) #define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--) #define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i) #define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i) #define FORALL(i, a) for (auto i: a) #define fastio ios_base::sync_with_stdio(0); cin.tie(0); const int mod = 1e6 + 3; vector<int> root, p, ivp; int getroot(int u) { return root[u] == u ? u : (root[u] = getroot(root[u])); } bool unite(int u, int v) { u = getroot(u), v = getroot(v); if (u == v) return false; root[v] = u; return true; } int _pow(int a, int x) { if (!x) return 1; int t = _pow(a, x / 2); t = (1LL * t * t) % mod; if (x % 2) t = (1LL * t * a) % mod; return t; } int C(int k, int n) { return (1LL * p[n] * ivp[k] * ivp[n - k]) % mod; } int main() { fastio; int n, k; cin >> n >> k; vector<int> a(n - k + 2); FOR(i, 1, n - k + 1) cin >> a[i]; vector<int> b(n + 1, - 1); root.resize(n + 1); FOR(i, 1, n) root[i] = i; // vector<int> deg(n + 1); FOR(i, 2, n - k + 1) { if (a[i] == a[i - 1]) { unite(i - 1, i + k - 1); continue; } if (a[i] < a[i - 1]) b[i + k - 1] = 0, b[i - 1] = 1; else b[i + k - 1] = 1, b[i - 1] = 0; // deg[i - 1]++; // deg[i + k - 1]++; } vector<vector<int>> adj(n + 1); vector<int> ids; FOR(i, 1, n) { adj[getroot(i)].push_back(i); ids.push_back(getroot(i)); } sort(ids.begin(), ids.end()); ids.resize(unique(ids.begin(), ids.end()) - ids.begin()); FORALL(id, ids) { int value = - 1; FORALL(u, adj[id]) { if (b[u] == - 1) continue; if (value == - 1) value = b[u]; else if (value != b[u]) { cout << 0 << '\n'; return 0; } } if (value == - 1) continue; FORALL(u, adj[id]) b[u] = value; } // int cnt = 0; // FOR(i, 1, n) if (!deg[i]) cnt++; p.resize(n + 1); p[0] = 1; FOR(i, 1, n) p[i] = (1LL * p[i - 1] * i) % mod; ivp.resize(n + 1); ivp[n] = _pow(p[n], mod - 2); FORD(i, n - 1, 0) ivp[i] = (1LL * ivp[i + 1] * (i + 1)) % mod; int cnt = 0, sum = 0; FOR(i, 1, k) if (b[i] == - 1) cnt++; else sum += b[i]; cout << C(a[1] - sum, cnt) << '\n'; return 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...