Submission #309326

#TimeUsernameProblemLanguageResultExecution timeMemory
309326jainbot27Gondola (IOI14_gondola)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #ifndef acmx #include "gondola.h" #endif using namespace std; #define f first #define s second #define pb push_back #define ar array #define all(x) x.begin(), x.end() #define siz(x) (int)x.size() #define for(x, y, z) for(int x = (y); x < (z); x++) #define rof(x, z, y) for(int x = (y-1); x >= (z); x--) #define f0r(x, z) for(x, 0, z) #define r0f(x, z) rof(x, 0, z) #define trav(x, y) for(auto&x:y) using ll = long long; using vi = vector<int>; using vl = vector<long long>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template<class t> inline bool ckmin(t&a, t b) {return b < a ? a = b, 1 : 0;} template<class t> inline bool ckmax(t&a, t b) {return b > a ? a = b, 1 : 0;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const char nl = '\n'; const int mxn = 1e5 + 10; const int mod = 1'000'000'009; const long long infll = 1e18; int32_t validcopy(int n, int* _inputseq){ vi inputseq(n); f0r(i, n){ inputseq[i] = _inputseq[i]; inputseq[i]--; } vi vals; f0r(i, n){ vals.pb(inputseq[i]); } sort(all(vals)); vals.resize(unique(all(vals))-vals.begin()); if(siz(vals)!=n) return 0; if(vals[0]>=n) return 1; int pos; f0r(i, n){ if(inputseq[i] < n){ pos = i; break; } } int ff = inputseq[pos]; f0r(i, n){ if(inputseq[i]<=n){ int dif = i - pos; int should = (n + ff + dif)%n; if(inputseq[i] != should) return 0; } } return 1; } int32_t valid(int n, int* _inputseq){ vi inputseq(n); f0r(i, n){ inputseq[i] = _inputseq[i]; inputseq[i]--; } vi vals; f0r(i, n){ vals.pb(inputseq[i]); } sort(all(vals)); vals.resize(unique(all(vals))-vals.begin()); if(siz(vals)!=n) return 0; if(vals[0]>=n) return 1; int pos; f0r(i, n){ if(inputseq[i] < n){ pos = i; break; } } int ff = inputseq[pos]; f0r(i, n){ if(inputseq[i]<=n){ int dif = i - pos; int should = (n + ff + dif)%n; if(inputseq[i] != should) return 0; } } return 1; } int32_t replacement(int n, int _gondolaseq[], int _replacementseq[]){ vi gs(n), rs; f0r(i, n){ gs[i] = _gondolaseq[i]-1; } int pos = 0, cnt = 0, mx = -1, sp, mxpos; sp = 0; map<int, int> vals; f0r(i, n){ if(ckmax(mx, gs[i])) mxpos = i; if(gs[i] < n){ pos = i; sp = gs[i]; cnt++; } } if(cnt==n){ return 0; } // cout << pos << " " << sp << endl; int foo; f0r(i, n){ int dif = i - pos; int should= (n + sp + dif) % n; // cout << i << " " << should << endl; if(mxpos==i){ foo = should; } if(gs[i]<n&&gs[i]!=should) assert(false); if(gs[i]==should) continue; vals[gs[i]]=should; } int x = 0; // cout << mx << endl; for(i, n, mx+1){ if(vals.find(i)!=vals.end()&&i!=mx){ // cout << i << " " << vals[i] << endl; _replacementseq[x] = vals[i]+1; x++; continue; } _replacementseq[x] = foo+1; foo=i; x++; // cout<<i<<endl; } return x; } // modulo class int fact[mxn]; int add(int x, int y){ x += y; while(x >= mod) x -= mod; while(x < 0) x += mod; return x; } void ad(int &x, int y) {x = add(x, y);} int sub(int x, int y){ x -= y; while(x >= mod) x -= mod; while(x < 0) x += mod; return x; } void sb(int &x, int y) {x = sub(x, y);} int mul(int x, int y){ return ((int64_t)x * (int64_t)y) % mod; } void ml(int &x, int y) {x = mul(x, y);} int binpow(int x, int y){ int z = 1; while(y > 0) { if(y % 2 == 1) z = mul(z, x); x = mul(x, x); y /= 2; } return z; } int inv(int x){ return binpow(x, mod - 2); } int divide(int x, int y){ return mul(x, inv(y)); } void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); } int choose(int n, int k){ if(k > n) return 0; return divide(fact[n], mul(fact[n - k], fact[k])); } int32_t countreplacement(int n, int inputseq[]){ if(!validcopy(n, inputseq)) return 0; int res = 1; sort(inputseq, inputseq+n); bool f = 1; f0r(i, n){ inputseq[i]++; if(inputseq[i]>n){ if(f){ ml(res, binpow(n-i, inputseq[i]-n-1)); } else{ ml(res, binpow(n-i, inputseq[i]-inputseq[i-1]-1)); } f = 0; } } if(inputseq[0]>n) ml(res, n); return res; } // int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); // int gondolaseq[] = {7, 4, 7, 4}; // int n = 4; // int ans =countreplacement(n, gondolaseq); // cout << ans << nl; // return 0; // }

Compilation message (stderr)

gondola.cpp:156:57: error: macro "for" requires 3 arguments, but only 1 given
  156 | void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); }
      |                                                         ^
gondola.cpp:14: note: macro "for" defined here
   14 | #define for(x, y, z) for(int x = (y); x < (z); x++)
      | 
gondola.cpp: In function 'void precalc()':
gondola.cpp:156:59: error: expected '(' before 'fact'
  156 | void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); }
      |                                                           ^~~~
      |                                                           (
gondola.cpp:156:64: error: 'i' was not declared in this scope; did you mean 'vi'?
  156 | void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); }
      |                                                                ^
      |                                                                vi
gondola.cpp:156:90: error: expected primary-expression before '}' token
  156 | void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); }
      |                                                                                          ^
gondola.cpp:156:89: error: expected ';' before '}' token
  156 | void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); }
      |                                                                                         ^~
      |                                                                                         ;
gondola.cpp:156:90: error: expected primary-expression before '}' token
  156 | void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); }
      |                                                                                          ^
gondola.cpp:156:89: error: expected ')' before '}' token
  156 | void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); }
      |                                                           ~~~~                          ^~
      |                                                                                         )
gondola.cpp:156:90: error: expected primary-expression before '}' token
  156 | void precalc(){ fact[0] = 1; for(int i = 1; i < mxn; i++) fact[i] = mul(i, fact[i - 1]); }
      |                                                                                          ^