Submission #242446

#TimeUsernameProblemLanguageResultExecution timeMemory
242446joseacazGondola (IOI14_gondola)C++17
90 / 100
1096 ms10188 KiB
#include "gondola.h" #include <bits/stdc++.h> #define pb push_back #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; const int MAXN = 1e6 + 5; vi input; unordered_map<int, int> vis; int valid(int N, int inputSeq[]) { input.clear(); for(int i = 0; i < N; i++) input.pb(inputSeq[i]); int ans = 0, one = 0; vis.clear(); for(int i = 0; i < N; i++) { if(vis[input[i]]) return 0; vis[input[i]]++; } for(int i = 0; i < N; i++) { if(input[i] <= N) { one = 1; int idx; for(int j = 0; j < N; j++) { idx = (i + (j + 1 - input[i]) + N) % N; if(input[idx] == j + 1 || input[idx] > N) ans++; } cerr << i << " " << input[i] << " " << ans << "\n"; break; } } if(!one) return 1; return (ans == N); } int replacement(int N, int gondolaSeq[], int replacementSeq[]) { input.clear(); for(int i = 0; i < N; i++) input.pb(gondolaSeq[i]); int one = 0; for(int i = 0; i < N; i++) if(input[i] <= N) one = (i - input[i] + 1 + N) % N; vpi seq; for(int i = 0; i < N; i++) seq.pb({input[(one + i) % N], i + 1}); sort(all(seq)); int curr = 0, newGondola = N + 1; for(int i = 0; i < N; i++) { while(seq[i].second != seq[i].first) { replacementSeq[curr++] = seq[i].second; seq[i].second = newGondola++; } } return curr; } const ll MOD = 1e9 + 9; ll binexp(ll b, ll e) { if(e == 0) return 1; if(e&1) return (b * binexp(b, e-1)) % MOD; else { ll aux = binexp(b, e/2); return (aux*aux) % MOD; } } int countReplacement(int N, int inputSeq[]) { if(!valid(N, inputSeq)) return 0; cerr << "valid\n"; int one = -1; for(int i = 0; i < N; i++) if(input[i] <= N) one = (i - input[i] + 1 + N) % N; vpi seq; for(int i = 0; i < N; i++) seq.pb({input[(max(one, 0) + i) % N], i + 1}); sort(all(seq)); int last = N; ll ans = 1; for(int i = 0; i < N; i++) { if(seq[i].first <= N) continue; cerr << seq[i].first << " " << last << "\n"; ans *= binexp(N - i, seq[i].first - last - 1); cerr << ans << "\n"; last = seq[i].first; ans %= MOD; } if(one < 0) ans = (ans * N) % MOD; return ans; }
#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...