# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1027633 | 2024-07-19T08:07:03 Z | MarwenElarbi | Gondola (IOI14_gondola) | C++17 | 57 ms | 9556 KB |
#include <bits/stdc++.h> #include "gondola.h" using namespace std; #define pb push_back #define se second #define fi first const int nax=5e5+5; const int MOD=1e9+9; int valid(int n, int inputSeq[]) { vector<pair<int,int>> tab; bool test=true; set<int> stt; for (int i = 0; i < n; ++i) { stt.insert(inputSeq[i]); } test&=(stt.size()==n); int cnt=-1e9; for (int i = 0; i < n; ++i) { if(inputSeq[i]<=n){ cnt=(inputSeq[i]-(i+1)+n)%n; } } if(cnt==-1e9) return test; for (int i = 0; i < n; ++i) { if(inputSeq[i]<=n){ if((inputSeq[i]-(i+1)+n)%n!=cnt) test=false; } } return test; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { vector<pair<int,int>> tab; for (int i = 0; i < n; ++i) { if(gondolaSeq[i]>n){ tab.pb({gondolaSeq[i],i+1}); } } if(tab.size()==n){ sort(tab.begin(),tab.end()); int cnt=n; int cur=0; for (int i = 0; i < tab.size(); ++i) { replacementSeq[cur++]=tab[i].se; cnt++; while(cnt<tab[i].fi){ replacementSeq[cur++]=cnt++; } } return cur; }else{ int a=0; for (int i = 0; i < n; ++i) { if(gondolaSeq[i]<=n) a=(gondolaSeq[i]-(i+1)+n)%n; } sort(tab.begin(),tab.end()); int cnt=n; int cur=0; for (int i = 0; i < tab.size(); ++i) { replacementSeq[cur++]=(tab[i].se+a == 0 ? n : tab[i].se+a); cnt++; while(cnt<tab[i].fi){ replacementSeq[cur++]=cnt++; } } return cur; } } //---------------------- long long binpow(long long x,long long m){ x%=MOD; long long res=1; while(m){ if(m%2) res=res*x%MOD; x=x*x%MOD; m/=2; } return res; } int countReplacement(int n, int inputSeq[]) { long long cur=1; set<int> st; if(!valid(n,inputSeq)) return 0; for (int i = 0; i < n; ++i) { st.insert(i); } for (int i = 0; i < n; ++i) { if(inputSeq[i]<=n) st.erase(inputSeq[i]); } if(st.size()==0) return 1; set<int> stt; for (int i = 0; i < n; ++i) { if(inputSeq[i]>n) stt.insert(inputSeq[i]); } int cnt=n; if(stt.size()==n) cur=n; while(stt.size()){ //cout <<cnt<<endl; cur*=binpow(stt.size(),*stt.begin()-1-cnt)%MOD; cur%=MOD; cnt=*stt.begin(); stt.erase(*stt.begin()); } return cur; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 600 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 8 ms | 2140 KB | Output is correct |
7 | Correct | 17 ms | 3676 KB | Output is correct |
8 | Correct | 11 ms | 3932 KB | Output is correct |
9 | Correct | 4 ms | 1372 KB | Output is correct |
10 | Correct | 17 ms | 4560 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 7 ms | 2140 KB | Output is correct |
7 | Correct | 17 ms | 3560 KB | Output is correct |
8 | Correct | 13 ms | 3932 KB | Output is correct |
9 | Correct | 4 ms | 1372 KB | Output is correct |
10 | Correct | 17 ms | 4440 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 9 ms | 2140 KB | Output is correct |
14 | Correct | 0 ms | 600 KB | Output is correct |
15 | Correct | 22 ms | 4732 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Integer 86 violates the range [1, 76] |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Integer 86 violates the range [1, 76] |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Integer 86 violates the range [1, 76] |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 40 ms | 5968 KB | Output is correct |
10 | Correct | 29 ms | 4700 KB | Output is correct |
11 | Correct | 10 ms | 2396 KB | Output is correct |
12 | Correct | 17 ms | 2904 KB | Output is correct |
13 | Correct | 3 ms | 860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 41 ms | 5904 KB | Output is correct |
10 | Correct | 30 ms | 4696 KB | Output is correct |
11 | Correct | 14 ms | 2396 KB | Output is correct |
12 | Correct | 13 ms | 2908 KB | Output is correct |
13 | Correct | 3 ms | 856 KB | Output is correct |
14 | Correct | 50 ms | 8540 KB | Output is correct |
15 | Correct | 57 ms | 9556 KB | Output is correct |
16 | Correct | 8 ms | 2136 KB | Output is correct |
17 | Correct | 34 ms | 6396 KB | Output is correct |
18 | Correct | 18 ms | 3928 KB | Output is correct |