Submission #1144828

#TimeUsernameProblemLanguageResultExecution timeMemory
1144828SofiatpcGondola (IOI14_gondola)C++20
100 / 100
44 ms5188 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("trapv") int valid(int n, int inputSeq[]) { set<int> st; int cur = -1; for(int i = 0; i < n; i++){ int x = inputSeq[i]; if(st.find(x) != st.end())return 0; st.insert(x); if(cur == -1 && x <= n){ cur = x+1; if(cur > n)cur = 1; }else if(cur != -1){ if(x <= n && x != cur) return 0; cur++; if(cur > n)cur = 1; } } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { vector< pair<int,int> > v; int cur = -1, st = -1; for(int i = 0; i < n; i++){ int x = gondolaSeq[i]; if(cur == -1 && x <= n){ st = i; cur = x+1; if(cur > n)cur = 1; }else if(cur != -1){ if(x > n)v.push_back({x,cur}); cur++; if(cur > n)cur = 1; } } if(cur == -1){ st = n; cur = 1; } for(int i = 0; i < st; i++){ int x = gondolaSeq[i]; if(x > n)v.push_back({x,cur}); cur++; if(cur > n)cur = 1; } sort(v.begin(),v.end()); int nxt = n+1, tam = 0; for(int i = 0; i < v.size(); i++){ int og = v[i].second, fim = v[i].first; replacementSeq[tam] = og; tam++; nxt++; while(nxt-1 < fim){ replacementSeq[tam] = nxt-1; tam++; nxt++; } } return tam; } //---------------------- long long MOD = 1000000009; long long expo(long long a, long long b){ if(b == 0)return 1; long long x = expo(a,b/2); x = (x*x)%MOD; if(b%2 == 1)return (x*a)%MOD; return x; } int countReplacement(int n, int inputSeq[]) { if(valid(n,inputSeq) == 0)return 0; vector< int > v; for(int i = 0; i < n; i++) if(inputSeq[i] > n)v.push_back(inputSeq[i]); sort(v.begin(),v.end()); if(v.size() == 0)return 1; long long ans = 1, last = n+1, qtd = v.size(); for(int i = 0; i < v.size(); i++){ ans = (expo(qtd,v[i]-last) * ans)%MOD; qtd--; last = v[i]+1; } if(v.size() == n)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...