제출 #586223

#제출 시각아이디문제언어결과실행 시간메모리
586223Tekor곤돌라 (IOI14_gondola)C++17
100 / 100
53 ms7056 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; #define pii pair <int,int> #define f first #define s second #define mp make_pair #define pb push_back #define all(v) v.begin(),v.end() #define ll long long const ll INF = (ll)1e9 + 9ll; int valid(int n, int a[]) { int c[n + 10]; map <int,int> was; for(int i = 0;i < n;i++) { if(a[i] <= n) { int tek = a[i]; c[i] = tek; for(int j = i + 1;j < n;j++) { tek++; if(tek == n + 1)tek = 1; c[j] = tek; } for(int j = 0;j < i;j++) { tek++; if(tek == n + 1)tek = 1; c[j] = tek; } break; } } for(int i = 0;i < n;i++) { if(a[i] <= n && c[i] != a[i])return 0; if(was[a[i]])return 0; was[a[i]] = 1; } return 1; } /* 1 30 16 26 18 19 20 13 22 21 24 25 17 27 28 29 30 1 2 3 11 5 6 8 7 9 10 12 4 23 14 15 */ //---------------------- int replacement(int n, int a[], int b[]) { int c[n + 1]; bool ch = 0; for(int i = 0;i < n;i++) { if(a[i] <= n) { int tek = a[i]; c[i] = tek; for(int j = i + 1;j < n;j++) { tek++; if(tek == n + 1)tek = 1; c[j] = tek; } for(int j = 0;j < i;j++) { tek++; if(tek == n + 1)tek = 1; c[j] = tek; } ch = 1; break; } } if(!ch) { for(int i = 0;i < n;i++) { c[i] = i + 1; } } set <pii> g; for(int i = 0;i < n;i++) { if(a[i] > n)g.insert(mp(a[i],i)); } int k = 0; int cnt = n + 1; while(!g.empty()) { pii vv = *(g.begin()); int val = vv.f,bilo = c[vv.s]; while(1) { b[k++] = bilo; if(cnt == val) { cnt++; break; } bilo = cnt++; } g.erase(vv); } return k; } /* 4 2 3 2 8 14 6 94 8 9 10 93 12 13 95 1 2 3 4 5 */ //---------------------- ll binpow(ll a,ll b) { ll ans = 1,k = a; while(b) { if(b % 2)ans *= k; ans %= INF; k *= k; k %= INF; b /= 2ll; } return ans; } int countReplacement(int n, int a[]) { ll d[n + 10]; bool ch = 0; for(int i = 0;i < n;i++) { if(a[i] <= n) { d[i] = 0; ch = 1; }else d[i] = a[i] - n; } if(!valid(n,a))return 0; sort(d,d + n); ll ans = 1; ll kol = n,last = 0; for(int i = 0;i < n;i++) { if(d[i] == 0) { kol--; continue; } ll cnt = d[i] - last - 1; ans = (ans * binpow(kol,cnt)) % INF; kol--; last = d[i]; } if(!ch) { ll tek = n; ans = (ans * tek) % INF; } 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...