Submission #252160

#TimeUsernameProblemLanguageResultExecution timeMemory
252160HeheheGondola (IOI14_gondola)C++14
75 / 100
34 ms2804 KiB
#include<bits/stdc++.h> //:3 using namespace std; typedef long long ll; #define all(a) (a).begin(), (a).end() #define ff first #define ss second #define pb push_back #define mp make_pair #define rc(s) return cout<<s,0 #define pi pair <int, int> #define sz(x) (int)((x).size()) #include "gondola.h" const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const ll inf = 2e9; const ll mod = 1e9 + 9; const int N = 2e5 + 11; const ll INF64 = 3e18 + 1; const double eps = 1e-14; const double PI = acos(-1); //ifstream in(".in"); //ofstream out(".out"); int a[N]; ll poww(ll x, ll p){ ll ans = 1; while(p){ if(p % 2)ans*= x, ans %= mod; x = x*x % mod; p /= 2; } return (ans + mod) % mod; } int valid(int n, int x[]){ ll j = -1; for(int i = 0; i < n; i++){ a[i] = x[i] - 1; if(a[i] >= n)continue; j = i; } for(int i = 0; i < n; i++){ if(i == j)continue; ll diff = j - i; ll val = (a[j] - diff + n) % n; if(a[i] < n && a[i] != val)return 0; } sort(a, a + n); for(int i = 1; i < n; i++){ if(a[i] == a[i - 1])return 0; } return 1; } int replacement(int n, int x[], int y[]){ vector<pi>t; int j = 0; for(int i = 0; i < n; i++){ if(x[i] > n){ t.push_back({x[i], i}); }else j = i; } if(sz(t) == n)x[0] = 1; sort(all(t)); for(int i = 0; i < n; i++){ if(i > j){ int val = x[j] + (i - j); if(val > n)val -= n; x[i] = val; }else{ int val = x[j] - (j - i); if(val < 1)val += n; x[i] = val; } } vector<ll>ans; ll k = n; for(int i = 0; i < sz(t); i++){ int num = t[i].ff, idx = t[i].ss; ans.push_back(x[idx]); for(int j = k + 1; j < num; j++)ans.push_back(j); k = num; } for(int i = 0; i < sz(ans); i++)y[i] = ans[i]; return sz(ans); } int countReplacement(int n, int x[]){ bool X = valid(n, x); if(!X)return 0; ll ans = 1; vector<ll>t; for(int i = 1; i < n; i++){ if(x[i] > n)t.push_back(x[i]); } sort(all(t)); ll prev = n; for(int i = 0; i < sz(t); i++){ ll pozitiiDisponibile = sz(t) - i; ll numereDisponibile = t[i] - 1 - prev; ans = (ans * poww(pozitiiDisponibile, numereDisponibile)) % mod; ans = (ans + mod) % mod; prev = t[i]; } if(sz(t) == n){ ans = (ans * n) % mod; ans = (ans + mod) % 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...