# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
102411 |
2019-03-24T18:01:45 Z |
naoai |
Gondola (IOI14_gondola) |
C++14 |
|
25 ms |
1408 KB |
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int inputSeq[]) {
vector<int> v(2 * n);
for (int i = 0; i < 2 * n; ++ i)
v[i] = inputSeq[i % n];
sort(inputSeq, inputSeq + n);
for (int i = 1; i < n; ++ i) {
if (inputSeq[i] == inputSeq[i - 1])
return 0;
}
if (inputSeq[0] > n)
return 1;
int ind = 0;
while (ind < n && v[ind] != inputSeq[0])
++ ind;
for (int i = 0; i < n; ++ i) {
if (v[ind + i] <= n && v[ind + i] != inputSeq[0] + i)
return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int mn = 0;
for (int i = 0; i < n; ++ i) {
if (gondolaSeq[i] < gondolaSeq[mn])
mn = i;
}
vector<pair<int, int>> ord;
vector<int> v(2 * n);
v.resize(2 * n);
for (int i = 0; i < 2 * n; ++ i)
v[i] = gondolaSeq[i % n];
int l = 0;
int pst = mn - v[mn] + 1;
if (pst < 0) pst += n;
for (int i = pst; i <= pst + n; ++ i) {
if (v[i] > n) {
ord.push_back({v[i], i - mn + v[mn]});
}
}
ord.push_back({n, -1});
sort(ord.begin(), ord.end());
for (int i = 1; i < (int)ord.size(); ++ i) {
int val = ord[i].second;
for (int j = ord[i - 1].first + 1; j <= ord[i].first; ++ j) {
replacementSeq[l ++] = val;
val = j;
}
}
return l;
}
//----------------------
static const int mod = 1e9 + 9;
long long lgput (long long b, int p) {
long long sol = 1;
while (p > 0) {
if (p & 1)
sol = sol * b % mod;
b = b * b % mod;
p >>= 1;
}
return sol;
}
int countReplacement(int n, int inputSeq[])
{
if (valid(n, inputSeq) == 0)
return 0;
vector<int> ord;
for (int i = 0; i < n; ++ i) {
if (inputSeq[i] > n) {
ord.push_back(inputSeq[i]);
}
}
ord.push_back(n);
sort(ord.begin(), ord.end());
long long ans = 1;
for (int i = 1; i < (int)ord.size(); ++ i) {
int cnt = ord[i] - 1 - ord[i - 1];
ans = ans * lgput((int)ord.size() - i, cnt) % mod;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 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 |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 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 |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
776 KB |
Output is correct |
7 |
Correct |
19 ms |
1408 KB |
Output is correct |
8 |
Correct |
14 ms |
1152 KB |
Output is correct |
9 |
Correct |
7 ms |
640 KB |
Output is correct |
10 |
Correct |
20 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 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 |
384 KB |
Output is correct |
6 |
Correct |
14 ms |
768 KB |
Output is correct |
7 |
Correct |
20 ms |
1408 KB |
Output is correct |
8 |
Correct |
14 ms |
1152 KB |
Output is correct |
9 |
Correct |
6 ms |
640 KB |
Output is correct |
10 |
Correct |
18 ms |
1280 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
10 ms |
768 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
20 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Incorrect |
3 ms |
256 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 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 |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
25 ms |
1152 KB |
Output is correct |
10 |
Correct |
21 ms |
1024 KB |
Output is correct |
11 |
Correct |
9 ms |
640 KB |
Output is correct |
12 |
Correct |
10 ms |
680 KB |
Output is correct |
13 |
Incorrect |
4 ms |
384 KB |
Output isn't 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 |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
22 ms |
1224 KB |
Output is correct |
10 |
Correct |
22 ms |
1060 KB |
Output is correct |
11 |
Correct |
9 ms |
640 KB |
Output is correct |
12 |
Correct |
12 ms |
680 KB |
Output is correct |
13 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |