Submission #138752

#TimeUsernameProblemLanguageResultExecution timeMemory
138752Mahmoud_AdelGondola (IOI14_gondola)C++14
Compilation error
0 ms0 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6+5, mod = 1e9+9; int mark[N], mep[N]; ll power(ll a, ll b) { if(!b) return 1; ll temp = power(a, b/2); temp = (temp*temp)%mod; if(b%2) temp *= a, temp %= mod; return temp; } int valid(int n, int inputSeq[]) { for(int i=0; i<n; i++) { if(mark[inputSeq[i]]) return 0; else mark[inputSeq[i]] = 1; } int j = -1; for(int i=0; i<n; i++) if(inputSeq[i] > 0 && inputSeq[i] <= n) j = i; if(j == -1) return 1; for(int i=0; i<n; i++) { int id = (i+j)%n, jd = (i+j+1)%n; if(inputSeq[jd] > n) inputSeq[jd] = inputSeq[id]%n + 1; if(inputSeq[jd] != inputSeq[id]%n + 1) return 0; } return 1; } //---------------------- int replacement(int n, int inputSeq[], int replacementSeq[]) { memset(mep, 0, sizeof mep); int j = -1, c = n; for(int i=0; i<n; i++) if(inputSeq[i] <= n) j = i; if(j == -1) { for(int i=0; i<n; i++) replacementSeq[inputSeq[i]-n-1] = i+1; return n; } for(int i=0; i<n; i++) { int id = (i+j) % n, jd = (i+j+1) % n; if(inputSeq[jd] > n) c = max(c, inputSeq[jd]), mep[inputSeq[jd]] = inputSeq[id]%n + 1; } int last = -1; for(int i=n+1; i<c; i++) { if(mep[i]) replacementSeq[i-n-1] = mep[i]; else replacementSeq[i-n-1] = mep[i-c-1], last = i; } if(last != -1) replacementSeq[c-n-1] = i; else replacementSeq[c-n-1] = mep[c-n-1]; return c-n; } //---------------------- int countReplacement(int n, int inputSeq[]) { int tmp[n]; for(int i=0; i<n; i++) tmp[i] = inputSeq[i]; if(!valid(n, inputSeq)) return 0; for(int i=0; i<n; i++) inputSeq[i] = tmp[i]; memset(mep, 0, sizeof mep); ll j = -1, c = n; for(int i=0; i<n; i++) if(inputSeq[i] <= n) j = i; else vec.push_back(inputSeq[i]); ll ans = 1; sort(vec.begin(), vec.end()); for(int i=0; i<vec.size()-1; i++) { ll tmp = power((ll)vec.size()-i, vec[i+1]-vec[i-1]); ans = (ans%mod * tmp%mod)%mod; } return (ans*(j==-1? n:1))%mod; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:58:41: error: 'i' was not declared in this scope
  if(last != -1) replacementSeq[c-n-1] = i;
                                         ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:74:7: error: 'vec' was not declared in this scope
  else vec.push_back(inputSeq[i]);
       ^~~
gondola.cpp:76:7: error: 'vec' was not declared in this scope
  sort(vec.begin(), vec.end());
       ^~~
gondola.cpp:72:13: warning: unused variable 'c' [-Wunused-variable]
  ll j = -1, c = n;
             ^