Submission #863302

#TimeUsernameProblemLanguageResultExecution timeMemory
863302quandlmBinaria (CCO23_day1problem1)C++14
25 / 25
71 ms24884 KiB
#include <bits/stdc++.h> #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } #define ll long long #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, a, b) for (int i = (a); i >= (b); --i) #define pi pair<int,int> #define ple tuple<int,int,int> #define fi first #define se second #define ii make_pair #define isz(a) ((int)a.size()) #define ALL(a) a.begin(), a.end() using namespace std; const int N = 1e6 + 10; const int mod = 1e6 + 3; int n,k,a[N],color[N],sz[N],lab[N],ifact[N]; void pre_calc () { ifact[0] = 1; FOR(i,1,n+10) { color[i] = -1; sz[i] = 1; lab[i] = i; ifact[i] = 1ll * ifact[i-1] * i % mod; } } int find (int u) { return (lab[u] == u ? u : lab[u] = find(lab[u])); } bool join (int u, int v) { u = find(u); v = find(v); if (u == v) return false; if (sz[u] < sz[v]) swap(u, v); lab[v] = u; sz[u] += sz[v]; if (color[v] == -1) color[v] = color[u]; return true; } int pow_mod (int a, int b) { if (b == 0) return 1; if (b == 1) return a; int res = pow_mod(a, b/2); res = 1ll * res * res % mod; if (b & 1) res = 1ll * res * a % mod; return res; } int C (int k, int n) { int A = ifact[n]; int B = 1ll * ifact[n - k] * ifact[k] % mod; return 1ll * A * pow_mod(B, mod - 2) % mod; } int main () { file("dynamic"); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; FOR(i,1,n-k+1) cin >> a[i]; pre_calc(); FOR(i,1,n-k) { if(a[i] == a[i+1]) { join(i, i + k); } else if (a[i] > a[i+1]) { color[find(i)] = 1; color[find(i + k)] = 0; } else { color[find(i)] = 0; color[find(i + k)] = 1; } } int cnt = 0; for (int i=1; i<=k; ++i) { int c = color[find(i)]; if (c != -1) a[1] -= c; else ++cnt; } cout << C(a[1], cnt) << '\n'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:2:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:63:5: note: in expansion of macro 'file'
   63 |     file("dynamic");
      |     ^~~~
Main.cpp:2:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                      ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:63:5: note: in expansion of macro 'file'
   63 |     file("dynamic");
      |     ^~~~
#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...