# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
152542 | 2019-09-08T10:07:36 Z | Nightlight | Gondola (IOI14_gondola) | C++14 | 48 ms | 6224 KB |
#include "gondola.h" #include <bits/stdc++.h> #define MOD 1000000009; using namespace std; int exist[250001]; unordered_set<int> existA; int valid(int n, int inputSeq[]) { int idx = 0; for(int i = 0; i < n; i++){ if(exist[inputSeq[i]] == 1)return 0; exist[inputSeq[i]] = 1; if(!idx && inputSeq[i] <= n) idx = inputSeq[i] + 1; else{ if(idx > n)idx = 1; if(inputSeq[i] <= n && inputSeq[i] != idx) return 0; if(idx)idx++; } } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int idx = 0, MAX = 0, MAXid; for(int i = 0; i < n; i++){ if(gondolaSeq[i] <= n){ idx = gondolaSeq[i] - i; if(idx < 1) idx += n; break; } } if(!idx)idx = 1; for(int i = 0; i < n; i++){ if(idx > n)idx = 1; if(gondolaSeq[i] > MAX){ MAX = gondolaSeq[i]; MAXid = idx; } if(gondolaSeq[i] > n){ exist[gondolaSeq[i]] = idx; // cout << gondolaSeq[i] << " " << exist[gondolaSeq[i]] << "\n"; } idx++; } if(MAX == n)return 0; else{ int MAXin = 0, last = 0; exist[MAX] = 0; for(int i = n+1; i <= MAX; i++){ // cout << i << " " << exist[i] << "\n"; if(exist[i]){ replacementSeq[i-n-1] = exist[i]; }else{ if(!MAXin){ replacementSeq[i-n-1] = MAXid; MAXin = 1; }else{ replacementSeq[i-n-1] = last; } last = i; } } } return MAX - n; } //---------------------- vector<long long> replaced; long long int POW( long long int a, long long int x ){ long long res = 1; while(x){ if(x&1) res = res * a % MOD; x >>= 1; a = a * a % MOD; } res %= MOD; return res; } int countReplacement(int n, int inputSeq[]) { int idx = 0; replaced.push_back(n); for(int i = 0; i < n; i++){ if(existA.count(inputSeq[i])) return 0; existA.insert(inputSeq[i]); if(inputSeq[i] > n) replaced.push_back(inputSeq[i]); if(!idx && inputSeq[i] <= n){ idx = inputSeq[i] + 1; }else{ if(idx > n)idx = 1; if(inputSeq[i] <= n && inputSeq[i] != idx) return 0; if(idx)idx++; } } sort(replaced.begin() + 1, replaced.end()); long long ans = (idx ? 1 : n); for(int i = 1; i < replaced.size(); i++){ ans *= POW(replaced.size() - i,replaced[i] - replaced[i-1] - 1); ans %= MOD; } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 9 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 4 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 7 ms | 632 KB | Output is correct |
7 | Correct | 13 ms | 632 KB | Output is correct |
8 | Correct | 11 ms | 892 KB | Output is correct |
9 | Correct | 5 ms | 500 KB | Output is correct |
10 | Correct | 13 ms | 1016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 7 ms | 632 KB | Output is correct |
7 | Correct | 13 ms | 632 KB | Output is correct |
8 | Correct | 12 ms | 888 KB | Output is correct |
9 | Correct | 5 ms | 504 KB | Output is correct |
10 | Correct | 12 ms | 1016 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 8 ms | 760 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 14 ms | 760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 256 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 11 ms | 636 KB | Output is correct |
12 | Correct | 13 ms | 632 KB | Output is correct |
13 | Correct | 15 ms | 1528 KB | Output is correct |
14 | Correct | 11 ms | 632 KB | Output is correct |
15 | Correct | 22 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 380 KB | Output is correct |
5 | Correct | 2 ms | 380 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 380 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 38 ms | 4224 KB | Output is correct |
10 | Correct | 31 ms | 4176 KB | Output is correct |
11 | Correct | 3 ms | 1652 KB | Output is correct |
12 | Correct | 15 ms | 2296 KB | Output is correct |
13 | Correct | 5 ms | 888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 35 ms | 4220 KB | Output is correct |
10 | Correct | 29 ms | 4128 KB | Output is correct |
11 | Correct | 12 ms | 1652 KB | Output is correct |
12 | Correct | 15 ms | 2296 KB | Output is correct |
13 | Correct | 5 ms | 760 KB | Output is correct |
14 | Correct | 44 ms | 5624 KB | Output is correct |
15 | Correct | 48 ms | 6224 KB | Output is correct |
16 | Correct | 11 ms | 1528 KB | Output is correct |
17 | Correct | 33 ms | 4608 KB | Output is correct |
18 | Correct | 20 ms | 2852 KB | Output is correct |