# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
288457 | 2020-09-01T13:56:07 Z | Atill83 | 곤돌라 (IOI14_gondola) | C++14 | 43 ms | 2684 KB |
#include "gondola.h" #include <bits/stdc++.h> using namespace std; const int MAXN = (int)3e5 + 5; const int mod = (int) 1e9 + 9; int yer[MAXN]; int valid(int n, int inputSeq[]) { int * p = inputSeq; for (int i = 1; i <= n; i++) { yer[i] = -1; } vector<int> ot; for (int i = 0; i < n; i++) { if (inputSeq[i] <= n) { if (yer[inputSeq[i]] != -1) return 0; yer[inputSeq[i]] = i; } else { ot.push_back(inputSeq[i]); } } sort(ot.begin(), ot.end()); for (int i = 1; i < ot.size(); i++) if(ot[i] == ot[i - 1]) return 0; int mini = 0; for (int i = 1; i < n; i++){ if(p[mini] > p[i]){ mini = i; } } if(p[mini] > n) return 1; int cur = p[mini] + 1; //cerr<<mini<<endl; for(int j = 1; j < n; j++){ int idx = mini + j; idx %= n; //cerr<<p[idx]<<endl; if(p[idx] != cur && p[idx] <= n) return 0; cur++; //cerr<<cur<<endl; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int *p = gondolaSeq, * q = replacementSeq; for (int i = 1; i <= n; i++) { yer[i] = -1; } vector<int> ot; for (int i = 0; i < n; i++) { if (gondolaSeq[i] <= n) { if (yer[gondolaSeq[i]] != -1) return 0; yer[gondolaSeq[i]] = i; } else { ot.push_back(gondolaSeq[i]); } } int curi = 0; if((int)ot.size() == n){ int mx = 0; int last = -1; for(int i = 0; i < n; i++){ int cur = gondolaSeq[i]; if(cur - n > mx){ mx = cur - n; last = i + 1; } q[cur - n - 1] = i + 1; } q[mx - 1] = 0; for(int j = 0; j < mx; j++){ if(q[j] == 0){ q[j] = last; last = n + j + 1; } } return mx; }else{ int piv = 0; for(int i = 1; i <= n; i++){ if(yer[i] != -1){ piv = i; break; } } int last = piv; last++; if(last == n + 1) last = 1; int mx = 0; int ono = -1; for(int j = 1; j < n; j++){ int idx = yer[piv] + j; idx %= n; int cur = gondolaSeq[idx]; if(cur > n){ assert(last != 0); if(mx < cur - n){ mx = cur - n; ono = last; } replacementSeq[cur - n - 1] = last; }else{ assert(cur == last); } last++; if(last == n + 1) last = 1; } replacementSeq[mx - 1] = 0; for(int i = 0; i < mx; i++){ if(replacementSeq[i] == 0){ replacementSeq[i] = ono; ono = n + i + 1; } } return mx; } } //---------------------- long long bp(long long a, long long b){ long long res = 1; while(b){ if(b % 2) res = (res * a) % mod; a = (a * a) % mod; b = b / 2; } return res; } int countReplacement(int n, int inputSeq[]) { int *p = inputSeq; if(!valid(n, inputSeq)){ return 0; } long long ans = 1; sort(p, p + n); if(p[0] > n) ans = n; p[n] = 0; sort(p, p + n + 1); //cerr<<"ali"<<endl; for(int i = 0; i <= n - 1; i++){ if(p[i + 1] <= n) continue; //cerr<<p[i]<<" "<<p[i + 1]<<endl; ans = ans*bp(n - i, (p[i + 1] - max(n, p[i]) - 1)); ans %= mod; } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 256 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 256 KB | Output is correct |
6 | Correct | 6 ms | 640 KB | Output is correct |
7 | Correct | 13 ms | 1024 KB | Output is correct |
8 | Correct | 11 ms | 896 KB | Output is correct |
9 | Correct | 4 ms | 512 KB | Output is correct |
10 | Correct | 13 ms | 1024 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 7 ms | 640 KB | Output is correct |
7 | Correct | 15 ms | 1000 KB | Output is correct |
8 | Correct | 11 ms | 896 KB | Output is correct |
9 | Correct | 4 ms | 512 KB | Output is correct |
10 | Correct | 13 ms | 1024 KB | Output is correct |
11 | Correct | 1 ms | 256 KB | Output is correct |
12 | Correct | 0 ms | 384 KB | Output is correct |
13 | Correct | 9 ms | 1024 KB | Output is correct |
14 | Correct | 0 ms | 256 KB | Output is correct |
15 | Correct | 17 ms | 1280 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 384 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 12 ms | 896 KB | Output is correct |
12 | Correct | 14 ms | 1024 KB | Output is correct |
13 | Correct | 15 ms | 1416 KB | Output is correct |
14 | Correct | 12 ms | 896 KB | Output is correct |
15 | Correct | 24 ms | 2356 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 288 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 0 ms | 256 KB | Output is correct |
4 | Correct | 0 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 0 ms | 256 KB | Output is correct |
7 | Correct | 0 ms | 256 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 29 ms | 1364 KB | Output is correct |
10 | Correct | 24 ms | 1152 KB | Output is correct |
11 | Correct | 10 ms | 768 KB | Output is correct |
12 | Correct | 12 ms | 768 KB | Output is correct |
13 | Correct | 3 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 256 KB | Output is correct |
5 | Correct | 0 ms | 256 KB | Output is correct |
6 | Correct | 1 ms | 256 KB | Output is correct |
7 | Correct | 0 ms | 384 KB | Output is correct |
8 | Correct | 0 ms | 256 KB | Output is correct |
9 | Correct | 29 ms | 1280 KB | Output is correct |
10 | Correct | 25 ms | 1280 KB | Output is correct |
11 | Correct | 10 ms | 768 KB | Output is correct |
12 | Correct | 12 ms | 768 KB | Output is correct |
13 | Correct | 3 ms | 384 KB | Output is correct |
14 | Correct | 38 ms | 2428 KB | Output is correct |
15 | Correct | 43 ms | 2684 KB | Output is correct |
16 | Correct | 8 ms | 896 KB | Output is correct |
17 | Correct | 28 ms | 1792 KB | Output is correct |
18 | Correct | 16 ms | 1408 KB | Output is correct |