# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
49261 |
2018-05-24T14:37:30 Z |
doowey |
Gondola (IOI14_gondola) |
C++14 |
|
31 ms |
9260 KB |
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;
#define fi first
#define se second
#define mp make_pair
const int N = (int)1e6 + 99;
int valid(int n, int inputSeq[])
{
int cnt[N];
for(int j = 0;j < N;j ++ )
cnt[j] = 0;
int rest[n];
int maz = (int)4e5 + 12345;
for(int i = 0; i < n;i ++){
cnt[inputSeq[i]]++;
if(cnt[inputSeq[i]] >= 2)
return 0;
maz = min(maz, inputSeq[i]);
rest[i] = inputSeq[i];
}
if(maz > n)
return 1;
int p,j;
for(int i = 0;i < n;i ++ ){
if(rest[i] <= n){
p = rest[i]+1;
j = i+1;
j %= N;
while(p <= n){
rest[j] = p;
p++;
j++;
j%=n;
}
p = 1;
while(p < rest[i]){
rest[j] = p;
j++;
j %= n;
p++;
}
break;
}
}
for(int i = 0; i < n;i ++){
if(inputSeq[i] <= n){
if(rest[i] != inputSeq[i])
return 0;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolas[], int replacementSeq[])
{
int rx = 0;
int start[n];
bool is = false;
for(int i = 0;i < n;i ++){
if(gondolas[i] > n)
is = true;
if(gondolas[i] <= n)
rx = i;
}
if(is == false)
return 0;
int ini;
if(gondolas[rx] > n)
start[rx] = 1;
else
start[rx] = gondolas[rx];
int p = start[rx] + 1;
ini = start[rx];
rx ++ ;
while(p <= n){
rx %= n;
start[rx] = p;
rx++;
p++;
}
p = 1;
rx %= n;
while(p < ini){
start[rx] = p;
p++;
rx++;
rx %= n;
}
vector<pii>qq;
for(int i = 0;i < n;i ++){
if(start[i] < gondolas[i]){
qq.push_back(mp(gondolas[i],i));
}
}
sort(qq.begin(),qq.end());
int mak;
int ii = n + 1;
int ix;
int sz = 0;
for(auto x : qq){
mak = x.fi;
ix = x.se;
replacementSeq[sz] = start[ix];
sz++;
start[ix] = ii;
ii++;
while(start[ix] < mak){
replacementSeq[sz] = start[ix];
start[ix] = ii;
sz++;
ii++;
}
ii = mak + 1;
}
return sz;
}
//----------------------
const ll MOD = (int)1e9 + 9;
ll cr;
ll powr(ll n,ll k){
if(k == 0)
return 1LL;
cr = powr(n,k/2);
cr = (cr * cr) % MOD;
if(k & 1)
cr = (cr * n) % MOD;
return cr;
}
int countReplacement(int n, int seq[])
{
if(!valid(n,seq)){
return 0;
}
int tk = 1000000009;
for(int i = 0;i < n;i ++){
tk = min(tk,seq[i]);
}
ll ans = 1;
if(tk > n)
ans = n;
vector<ll>R;
for(int i = 0;i < n;i ++){
if(seq[i] > n)
R.push_back((ll)seq[i]);
}
R.push_back(n);
sort(R.begin(),R.end());
ll ff = (ll)R.size();
ff--;
for(int i = 1;i < R.size(); i ++){
ans *= powr(ff,R[i] - R[i - 1] - 1);
ans %= MOD;
--ff;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:164:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1;i < R.size(); i ++){
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4216 KB |
Output is correct |
2 |
Correct |
5 ms |
4324 KB |
Output is correct |
3 |
Correct |
6 ms |
4324 KB |
Output is correct |
4 |
Correct |
5 ms |
4436 KB |
Output is correct |
5 |
Correct |
5 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4436 KB |
Output is correct |
2 |
Correct |
6 ms |
4436 KB |
Output is correct |
3 |
Correct |
5 ms |
4436 KB |
Output is correct |
4 |
Correct |
6 ms |
4436 KB |
Output is correct |
5 |
Correct |
5 ms |
4436 KB |
Output is correct |
6 |
Correct |
12 ms |
4736 KB |
Output is correct |
7 |
Correct |
16 ms |
4816 KB |
Output is correct |
8 |
Correct |
15 ms |
5072 KB |
Output is correct |
9 |
Correct |
13 ms |
5072 KB |
Output is correct |
10 |
Correct |
21 ms |
5092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5092 KB |
Output is correct |
2 |
Correct |
6 ms |
5092 KB |
Output is correct |
3 |
Correct |
6 ms |
5092 KB |
Output is correct |
4 |
Correct |
5 ms |
5092 KB |
Output is correct |
5 |
Correct |
7 ms |
5092 KB |
Output is correct |
6 |
Correct |
11 ms |
5092 KB |
Output is correct |
7 |
Correct |
16 ms |
5092 KB |
Output is correct |
8 |
Correct |
19 ms |
5092 KB |
Output is correct |
9 |
Correct |
9 ms |
5092 KB |
Output is correct |
10 |
Correct |
28 ms |
5092 KB |
Output is correct |
11 |
Correct |
5 ms |
5092 KB |
Output is correct |
12 |
Correct |
5 ms |
5092 KB |
Output is correct |
13 |
Correct |
12 ms |
5092 KB |
Output is correct |
14 |
Correct |
6 ms |
5092 KB |
Output is correct |
15 |
Correct |
23 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5096 KB |
Output is correct |
2 |
Correct |
2 ms |
5096 KB |
Output is correct |
3 |
Correct |
3 ms |
5096 KB |
Output is correct |
4 |
Correct |
3 ms |
5096 KB |
Output is correct |
5 |
Correct |
2 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5096 KB |
Output is correct |
2 |
Correct |
3 ms |
5096 KB |
Output is correct |
3 |
Correct |
4 ms |
5096 KB |
Output is correct |
4 |
Correct |
3 ms |
5096 KB |
Output is correct |
5 |
Correct |
2 ms |
5096 KB |
Output is correct |
6 |
Correct |
2 ms |
5096 KB |
Output is correct |
7 |
Correct |
2 ms |
5096 KB |
Output is correct |
8 |
Correct |
2 ms |
5096 KB |
Output is correct |
9 |
Correct |
3 ms |
5096 KB |
Output is correct |
10 |
Correct |
3 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5096 KB |
Output is correct |
2 |
Correct |
3 ms |
5096 KB |
Output is correct |
3 |
Correct |
2 ms |
5096 KB |
Output is correct |
4 |
Correct |
2 ms |
5096 KB |
Output is correct |
5 |
Correct |
3 ms |
5096 KB |
Output is correct |
6 |
Correct |
3 ms |
5096 KB |
Output is correct |
7 |
Correct |
2 ms |
5096 KB |
Output is correct |
8 |
Correct |
2 ms |
5096 KB |
Output is correct |
9 |
Correct |
3 ms |
5096 KB |
Output is correct |
10 |
Correct |
3 ms |
5096 KB |
Output is correct |
11 |
Correct |
11 ms |
5096 KB |
Output is correct |
12 |
Correct |
13 ms |
5096 KB |
Output is correct |
13 |
Correct |
17 ms |
5096 KB |
Output is correct |
14 |
Correct |
11 ms |
5096 KB |
Output is correct |
15 |
Correct |
27 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5096 KB |
Output is correct |
2 |
Correct |
5 ms |
5096 KB |
Output is correct |
3 |
Correct |
6 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5096 KB |
Output is correct |
2 |
Correct |
6 ms |
5096 KB |
Output is correct |
3 |
Correct |
5 ms |
5096 KB |
Output is correct |
4 |
Correct |
5 ms |
5096 KB |
Output is correct |
5 |
Correct |
4 ms |
5096 KB |
Output is correct |
6 |
Correct |
5 ms |
5096 KB |
Output is correct |
7 |
Correct |
3 ms |
5096 KB |
Output is correct |
8 |
Correct |
5 ms |
5096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5096 KB |
Output is correct |
2 |
Correct |
6 ms |
5096 KB |
Output is correct |
3 |
Correct |
6 ms |
5096 KB |
Output is correct |
4 |
Correct |
6 ms |
5096 KB |
Output is correct |
5 |
Correct |
5 ms |
5096 KB |
Output is correct |
6 |
Correct |
5 ms |
5096 KB |
Output is correct |
7 |
Correct |
7 ms |
5096 KB |
Output is correct |
8 |
Correct |
6 ms |
5096 KB |
Output is correct |
9 |
Correct |
31 ms |
5800 KB |
Output is correct |
10 |
Correct |
21 ms |
5800 KB |
Output is correct |
11 |
Correct |
11 ms |
5800 KB |
Output is correct |
12 |
Correct |
12 ms |
5800 KB |
Output is correct |
13 |
Correct |
7 ms |
5800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5800 KB |
Output is correct |
2 |
Correct |
6 ms |
5800 KB |
Output is correct |
3 |
Correct |
7 ms |
5800 KB |
Output is correct |
4 |
Correct |
6 ms |
5800 KB |
Output is correct |
5 |
Correct |
6 ms |
5800 KB |
Output is correct |
6 |
Correct |
5 ms |
5800 KB |
Output is correct |
7 |
Correct |
6 ms |
5800 KB |
Output is correct |
8 |
Correct |
5 ms |
5800 KB |
Output is correct |
9 |
Correct |
27 ms |
5800 KB |
Output is correct |
10 |
Correct |
22 ms |
5800 KB |
Output is correct |
11 |
Correct |
15 ms |
5800 KB |
Output is correct |
12 |
Correct |
15 ms |
5800 KB |
Output is correct |
13 |
Correct |
8 ms |
5800 KB |
Output is correct |
14 |
Runtime error |
28 ms |
9260 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
15 |
Halted |
0 ms |
0 KB |
- |