Submission #587074

#TimeUsernameProblemLanguageResultExecution timeMemory
587074hibikiGondola (IOI14_gondola)C++11
90 / 100
46 ms9812 KiB
#include "gondola.h" #include<bits/stdc++.h> using namespace std; #define mod 1000000009 #define pb push_back #define f first #define s second #define sz(x) (int)x.size() #define all(x) x.begin(),x.end() int valid(int n, int a[]) { map<int,bool> use; pair<int,int> mn = {1e9, 1e9}; for(int i = 0; i < n; i++) { mn = min(mn, {a[i], i}); if(use.count(a[i])) return 0; use[a[i]] = true; } if(mn.f > n) return 1; if(mn.f < 1) return 0; for(int i = 0; i < n; i++) { if(a[(mn.s + i) % n] <= n && a[(mn.s + i) % n] != (mn.f + i + n - 1) % n + 1) return 0; } return 1; } //---------------------- int to[250005], use[250005]; int replacement(int n, int a[], int ans[]) { int mx = 0; int cur = -1, idx = 0; pair<int,int> mn = {1e9, 1e9}; for(int i = 0; i < n; i++) mn = min(mn, {a[i], i}), mx = max(mx, a[i]); for(int i = 0; i < n; i++) if(a[(mn.s + i) % n] != (mn.f + i + n - 1) % n + 1) { to[(mn.f + i + n - 1) % n + 1] = a[(mn.s + i) % n]; if(a[(mn.s + i) % n] == mx) cur = (mn.f + i + n - 1) % n + 1; else use[a[(mn.s + i) % n]] = (mn.f + i + n - 1) % n + 1; } for(int i = n + 1; i <= mx; i++) { if(use[i]) ans[idx++] = use[i]; else ans[idx++] = cur, cur = i; } return idx; } //---------------------- int fast_pow(long long base, long long pw) { if(pw == 0) return 1; long long ret = 1ll; long long mul = base; while(pw > 0) { if(pw & 1) ret = (ret * mul) % mod; mul = (mul * mul) % mod; pw >>= 1; } return ret; } int countReplacement(int n, int a[]) { if(!valid(n, a)) return 0; int mx = 0; vector<int> v; long long cal = 1ll; pair<int,int> mn = {1e9, 1e9}; for(int i = 0; i < n; i++) { mn = min(mn, {a[i], i}); if(a[i] > n) v.pb(a[i]), use[a[i]] = 1; } if(mn.f > n) cal *= n; v.pb(n); sort(all(v)); for(int i = 1; i < sz(v); i++) { if(v[i] - v[i - 1] - 1 == 0) continue; cal *= fast_pow((sz(v) - i), (v[i] - v[i - 1] - 1)); cal %= mod; } return cal; }

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:81:9: warning: unused variable 'mx' [-Wunused-variable]
   81 |     int mx = 0;
      |         ^~
#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...