# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1017840 | 2024-07-09T10:38:28 Z | serkanrashid | 곤돌라 (IOI14_gondola) | C++14 | 29 ms | 6764 KB |
#include "gondola.h" #include <bits/stdc++.h> using namespace std; const long long mod = 1e9+9; const int maxn = 1e5+5; int n,a[maxn]; bool check_valid() { unordered_set<int>used; int st = -1; for(int i = 0; i < n; i++) { if(used.find(a[i])!=used.end()) return false; used.insert(a[i]); if(1<=a[i] && a[i] <= n) st = i; } if(st==-1) return true; int last = a[st]; int i = (st+1)%n; while(i!=st) { last++; if(last>n) last = 1; if(1<=a[i] && a[i]<=n) { if(last!=a[i]) return false; } i = (i+1)%n; } return true; } int valid(int N, int inputSeq[]) { n = N; for(int i = 0; i < n; i++) a[i] = inputSeq[i]; return check_valid(); } int need[maxn]; bool make_need() { int st = -1; for(int i = 0; i < n; i++) if(1 <= a[i] && a[i] <= n) st = i; if(st==-1) { for(int i = 0; i < n; i++) need[i] = i+1; return false; } int last = a[st]; int i = (st+1)%n; while(i!=st) { last++; if(last>n) last = 1; need[i] = last; i = (i+1)%n; } return true; } vector<int> do_replace() { int l = 0; for(int i = 0; i < n; i++) if(a[i]>l) l = a[i]; l = l - n; vector<pair<int,int> >pos; for(int i = 0; i < n; i++) if(a[i]>n) pos.push_back({a[i],need[i]}); sort(pos.begin(),pos.end()); vector<int>res; int last = n; for(pair<int,int> nb : pos) { res.push_back(nb.second); for(int j = last+1; j < nb.first; j++) res.push_back(j); last = nb.first; } return res; } int replacement(int N, int gondolaSeq[], int replacementSeq[]) { n = N; for(int i = 0; i < n; i++) a[i] = gondolaSeq[i]; bool f = make_need(); vector<int>pom = do_replace(); for(int i = 0; i < pom.size(); i++) replacementSeq[i] = pom[i]; return pom.size(); } long long step(long long a, long long b) { long long res = 1; while(b>0) { if(b%2) res = (res*a)%mod; a = (a*a)%mod; b /= 2; } return res; } int countReplacement(int N, int inputSeq[]) { n = N; for(int i = 0; i < n; i++) a[i] = inputSeq[i]; if(!check_valid()) return 0; ///OSHTE vector<int>b; for(int i = 0; i < n; i++) if(a[i]>n) b.push_back(a[i]); sort(b.begin(),b.end()); long long ans = 1; bool f = make_need(); if(!f) ans = n; int last = n; for(int i = 0; i < b.size(); i++) { int st = b[i] - last - 1; int osn = b.size()-i; ans = (ans*step(osn,st))%mod; last = b[i]; } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 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 | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 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 | 372 KB | Output is correct |
6 | Correct | 4 ms | 2232 KB | Output is correct |
7 | Correct | 5 ms | 1112 KB | Output is correct |
8 | Correct | 8 ms | 3792 KB | Output is correct |
9 | Correct | 3 ms | 1628 KB | Output is correct |
10 | Correct | 10 ms | 4204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 344 KB | Output is correct |
6 | Correct | 5 ms | 2232 KB | Output is correct |
7 | Correct | 10 ms | 1044 KB | Output is correct |
8 | Correct | 8 ms | 3692 KB | Output is correct |
9 | Correct | 3 ms | 1624 KB | Output is correct |
10 | Correct | 9 ms | 4204 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 5 ms | 1916 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 14 ms | 5712 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 5 ms | 1372 KB | Output is correct |
12 | Correct | 6 ms | 1456 KB | Output is correct |
13 | Correct | 9 ms | 1628 KB | Output is correct |
14 | Correct | 5 ms | 1372 KB | Output is correct |
15 | Correct | 12 ms | 2308 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 | 17 ms | 3792 KB | Output is correct |
10 | Correct | 14 ms | 3436 KB | Output is correct |
11 | Correct | 5 ms | 1628 KB | Output is correct |
12 | Correct | 7 ms | 1720 KB | Output is correct |
13 | Correct | 2 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 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 | 17 ms | 3948 KB | Output is correct |
10 | Correct | 14 ms | 3400 KB | Output is correct |
11 | Correct | 5 ms | 1628 KB | Output is correct |
12 | Correct | 6 ms | 1720 KB | Output is correct |
13 | Correct | 2 ms | 604 KB | Output is correct |
14 | Correct | 21 ms | 5080 KB | Output is correct |
15 | Correct | 29 ms | 6764 KB | Output is correct |
16 | Correct | 4 ms | 1368 KB | Output is correct |
17 | Correct | 16 ms | 4028 KB | Output is correct |
18 | Correct | 9 ms | 2488 KB | Output is correct |