Submission #599451

#TimeUsernameProblemLanguageResultExecution timeMemory
599451AriaHGondola (IOI14_gondola)C++17
75 / 100
58 ms10304 KiB
#include "gondola.h" #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair < int, int > pii; typedef pair < ll, ll > pll; #define F first #define S second #define all(x) x.begin(), x.end() #define SZ(x) (int)x.size() #define Mp make_pair #define endl "\n" #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int N = 1e6 + 10; const int LOG = 20; const ll mod = 1e9 + 9; const ll inf = 8e18; map < int, int > mark; int valid(int n, int inputSeq[]) { int id = -1; for(int i = 0; i < n; i ++) { if(++ mark[inputSeq[i]] > 1) return 0; if(inputSeq[i] <= n) { id = i; } } if(id == -1) return 1; int start = (id - (inputSeq[id] - 1) + n + n) % n; for(int i = 0; i < n; i ++) { int j = (i + start) % n; if(inputSeq[j] > n) continue; if(inputSeq[j] != i + 1) { return 0; } } return 1; } //---------------------- int replacement(int n, int A[], int replacementSeq[]) { int Mx = 0; int id = -1; for(int i = 0; i < n; i ++) { Mx = max(Mx, A[i]); mark[A[i]] ++; if(A[i] <= n) { id = i; } } vector < int > vec; vec.push_back(Mx); for(int i = Mx - 1; i > n; i --) { if(mark[i] > 2) return -1; if(mark[i] == 0) vec.push_back(i); } int start; if(id == -1) { start = 0; } else { start = (id - (A[id] - 1) + n + n) % n; } for(int i = 0; i < n; i ++) { int j = (start + i) % n; if(A[j] <= n) continue; ///printf("i = %d j = %d\n", i, j); if(A[j] != Mx) replacementSeq[A[j] - n - 1] = i + 1; else { ///printf("here i = %d j = %d\n", i, j); int last = i + 1; while(SZ(vec)) { int l = vec.back(); ///printf("here l = %d last = %d\n", l, last); vec.pop_back(); replacementSeq[l - n - 1] = last; last = l; } } } return Mx - n; } //---------------------- int countReplacement(int n, int A[]) { ll ret = 1; int Mx = 0; int id = -1; for(int i = 0; i < n; i ++) { Mx = max(Mx, A[i]); mark[A[i]] ++; if(A[i] <= n) { id = i; } } int cnt = 0; for(int i = Mx; i > n; i --) { if(mark[i] > 1) return 0; if(mark[i] == 0) ret = 1ll * ret * cnt % mod; else cnt ++; } int start; if(id == -1) { for(int i = 1; i <= n; i ++) { ret = ret * i % mod; } return ret; } else { start = (id - (A[id] - 1) + n + n) % n; } for(int i = 0; i < n; i ++) { int j = (start + i) % n; if(A[j] > n) continue; if(A[j] != i + 1) return 0; } return ret; }
#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...