Submission #29392

#TimeUsernameProblemLanguageResultExecution timeMemory
29392cki86201Gondola (IOI14_gondola)C++11
100 / 100
39 ms6964 KiB
#include "gondola.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> #include <unordered_map> #include <unordered_set> #include <list> #include <bitset> using namespace std; typedef pair<int, int> pii; typedef long long ll; #define Fi first #define Se second #define pb(x) push_back(x) #define sz(x) ((int)(x).size()) #define rep(i, n) for(int i=0;i<n;i++) #define all(x) (x).begin(), (x).end() typedef tuple<int, int, int> t3; typedef pair<ll, ll> Pll; typedef long double ldouble; int vchk[250050] = {}; int valid(int n, int inputSeq[]) { int L = *max_element(inputSeq, inputSeq + n); rep(i, L+1) vchk[i] = -1; rep(i, n) { if(vchk[inputSeq[i]] != -1) return 0; vchk[ inputSeq[i] ] = i; } pii f = pii(-1, -1); for(int i=0;i<n;i++) if(inputSeq[i] <= n) f = pii(inputSeq[i], i); if(f == pii(-1, -1)) return 1; for(int i=0;i<n;i++) if(inputSeq[i] <= n) { int exp = (i - f.Se) + f.Fi; if(exp > n) exp -= n; if(exp <= 0) exp += n; if(exp != inputSeq[i]) return 0; } return 1; } //---------------------- int ep[250050]; int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int L = *max_element(gondolaSeq, gondolaSeq + n); rep(i, L+1) vchk[i] = -1; rep(i, n) vchk[ gondolaSeq[i] ] = i; int ret = L - n; pii f = pii(-1, -1); for(int i=0;i<n;i++) if(gondolaSeq[i] <= n) f = pii(gondolaSeq[i], i); if(f == pii(-1, -1)) f = pii(1, 0); for(int i=0;i<n;i++) { int exp = (i - f.Se) + f.Fi; if(exp > n) exp -= n; if(exp <= 0) exp += n; ep[i] = exp; } int now = ret; for(int i=L, j=L;i>n;i--) { while(vchk[j] != -1) --j; if(j > n || ep[vchk[i]] == j) vchk[j] = vchk[i], replacementSeq[--now] = j; else { int t = ep[vchk[i]]; vchk[t] = vchk[i], replacementSeq[--now] = t; } } return ret; } //---------------------- int pw(int x, int y, int MOD) { int res = 1; while(y) { if(y & 1) res = (ll)res * x % MOD; x = (ll)x * x % MOD; y >>= 1; } return res; } int countReplacement(int n, int inputSeq[]) { const int MOD = 1e9 + 9; int L = *max_element(inputSeq, inputSeq + n); vector <int> T; rep(i, n) T.pb(inputSeq[i]); sort(all(T)); for(int i=1;i<sz(T);i++) if(T[i] == T[i-1]) return 0; pii f = pii(-1, -1); for(int i=0;i<n;i++) if(inputSeq[i] <= n) f = pii(inputSeq[i], i); int flag = 1; int cc = 0; vector <int> vv; if(f != pii(-1, -1)) { flag = 0; for(int i=0;i<n;i++) { int exp = (i - f.Se) + f.Fi; if(exp > n) exp -= n; if(exp <= 0) exp += n; if(inputSeq[i] <= n && inputSeq[i] != exp) return 0; if(inputSeq[i] > n) ++cc, vv.pb(inputSeq[i]); } } else { cc = n; rep(i, n) vv.pb(inputSeq[i]); } ll ans = 1; if(flag) ans = n; int pre = n; sort(all(vv)); for(int e : vv) { ans = ans * pw(cc, e - pre - 1, MOD) % MOD; --cc; pre = e; } return (int)ans; }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:104:9: warning: unused variable 'L' [-Wunused-variable]
     int L = *max_element(inputSeq, inputSeq + n);
         ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...