# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
65306 |
2018-08-07T10:43:54 Z |
gnoor |
Gondola (IOI14_gondola) |
C++17 |
|
111 ms |
7548 KB |
#include "gondola.h"
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
set<int> mark;
int valid(int n, int inputSeq[])
{
int key=-1;
int id=-1;
int cur;
for (int i=0;i<n;i++) {
inputSeq[i]--;
if (mark.find(inputSeq[i])!=mark.end()) return 0;
mark.insert(inputSeq[i]);
}
for (int i=0;i<n;i++) {
if (inputSeq[i]>=n) continue;
key=inputSeq[i];
id=i;
}
for (int i=0;i<n;i++) {
if (inputSeq[i]>=n) continue;
cur=key+i-id;
cur%=n;
cur+=n;
cur%=n;
if (inputSeq[i]!=cur) return 0;
}
return 1;
}
//----------------------
int init[100100];
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int id=0;
int key=1;
for (int i=0;i<n;i++) {
if (gondolaSeq[i]>n) continue;
id=i;
key=gondolaSeq[i];
break;
}
init[id]=key;
for (int i=id+1;i<n;i++) {
init[i]=init[i-1]+1;
if (init[i]>n) init[i]-=n;
}
for (int i=id-1;i>=0;i--) {
init[i]=init[i+1]-1;
if (init[i]<=0) init[i]+=n;
}
vector<pair<int,int>> ei;
for (int i=0;i<n;i++) {
if (gondolaSeq[i]<=n) continue;
ei.push_back({gondolaSeq[i],i});
}
sort(ei.begin(),ei.end());
int sz=0;
int curid=0;
int curcar=n+1;
int curgon=0;
for (int i=0;i<(int)ei.size();i++) {
while (curcar<ei[i].first) {
while (init[curgon]==gondolaSeq[curgon]) curgon++;
replacementSeq[sz++]=init[curgon];
init[curgon]=curcar;
curcar++;
}
replacementSeq[sz++]=init[ei[i].second];
init[ei[i].second]=ei[i].first;
curcar++;
}
return sz;
}
//----------------------
//
int mod=1000000009;
long long poww(long long b,int x) {
if (x==0) return 1;
if (x==1) return b;
long long tmp=poww(b,x/2);
tmp*=tmp;
tmp%=mod;
if (x%2) return (tmp*b)%mod;
return tmp;
}
int countReplacement(int n, int inputSeq[])
{
if (!valid(n,inputSeq)) return 0;
for (int i=0;i<n;i++) inputSeq[i]++;
int id=0;
int key=1;
for (int i=0;i<n;i++) {
if (inputSeq[i]>n) continue;
id=i;
key=inputSeq[i];
break;
}
init[id]=key;
for (int i=id+1;i<n;i++) {
init[i]=init[i-1]+1;
if (init[i]>n) init[i]-=n;
}
for (int i=id-1;i>=0;i--) {
init[i]=init[i+1]-1;
if (init[i]<=0) init[i]+=n;
}
vector<int> ei;
for (int i=0;i<n;i++) {
if (inputSeq[i]<=n) continue;
ei.push_back(inputSeq[i]);
}
sort(ei.begin(),ei.end());
int curcar=n+1;
int cnt=ei.size();
long long ans=1;
if (cnt==n) ans=n;
for (int i=0;i<(int)ei.size();i++) {
ans*=poww(cnt,ei[i]-curcar);
ans%=mod;
curcar=ei[i]+1;
cnt--;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:71:6: warning: unused variable 'curid' [-Wunused-variable]
int curid=0;
^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
472 KB |
Output is correct |
3 |
Correct |
3 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
496 KB |
Output is correct |
2 |
Correct |
3 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
528 KB |
Output is correct |
5 |
Correct |
3 ms |
536 KB |
Output is correct |
6 |
Correct |
18 ms |
2388 KB |
Output is correct |
7 |
Correct |
14 ms |
2388 KB |
Output is correct |
8 |
Correct |
35 ms |
4196 KB |
Output is correct |
9 |
Correct |
12 ms |
4196 KB |
Output is correct |
10 |
Correct |
59 ms |
4844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4844 KB |
Output is correct |
2 |
Correct |
2 ms |
4844 KB |
Output is correct |
3 |
Correct |
2 ms |
4844 KB |
Output is correct |
4 |
Correct |
2 ms |
4844 KB |
Output is correct |
5 |
Correct |
2 ms |
4844 KB |
Output is correct |
6 |
Correct |
19 ms |
4844 KB |
Output is correct |
7 |
Correct |
19 ms |
4844 KB |
Output is correct |
8 |
Correct |
39 ms |
4844 KB |
Output is correct |
9 |
Correct |
16 ms |
4844 KB |
Output is correct |
10 |
Correct |
49 ms |
4844 KB |
Output is correct |
11 |
Correct |
2 ms |
4844 KB |
Output is correct |
12 |
Correct |
3 ms |
4844 KB |
Output is correct |
13 |
Correct |
30 ms |
4844 KB |
Output is correct |
14 |
Correct |
2 ms |
4844 KB |
Output is correct |
15 |
Correct |
59 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5000 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
2 ms |
5000 KB |
Output is correct |
5 |
Correct |
2 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5000 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
3 ms |
5000 KB |
Output is correct |
5 |
Correct |
3 ms |
5000 KB |
Output is correct |
6 |
Correct |
2 ms |
5000 KB |
Output is correct |
7 |
Correct |
2 ms |
5000 KB |
Output is correct |
8 |
Correct |
3 ms |
5000 KB |
Output is correct |
9 |
Correct |
3 ms |
5000 KB |
Output is correct |
10 |
Correct |
3 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5000 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
4 |
Correct |
2 ms |
5000 KB |
Output is correct |
5 |
Correct |
4 ms |
5000 KB |
Output is correct |
6 |
Correct |
2 ms |
5000 KB |
Output is correct |
7 |
Correct |
2 ms |
5000 KB |
Output is correct |
8 |
Correct |
3 ms |
5000 KB |
Output is correct |
9 |
Correct |
3 ms |
5000 KB |
Output is correct |
10 |
Correct |
4 ms |
5000 KB |
Output is correct |
11 |
Correct |
13 ms |
5000 KB |
Output is correct |
12 |
Correct |
16 ms |
5000 KB |
Output is correct |
13 |
Correct |
21 ms |
5000 KB |
Output is correct |
14 |
Correct |
15 ms |
5000 KB |
Output is correct |
15 |
Correct |
29 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5000 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
3 |
Correct |
2 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5000 KB |
Output is correct |
2 |
Correct |
3 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
5000 KB |
Output is correct |
4 |
Correct |
2 ms |
5000 KB |
Output is correct |
5 |
Correct |
4 ms |
5000 KB |
Output is correct |
6 |
Correct |
2 ms |
5000 KB |
Output is correct |
7 |
Correct |
3 ms |
5000 KB |
Output is correct |
8 |
Correct |
3 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5000 KB |
Output is correct |
2 |
Correct |
3 ms |
5000 KB |
Output is correct |
3 |
Correct |
3 ms |
5000 KB |
Output is correct |
4 |
Correct |
2 ms |
5000 KB |
Output is correct |
5 |
Correct |
2 ms |
5000 KB |
Output is correct |
6 |
Correct |
2 ms |
5000 KB |
Output is correct |
7 |
Correct |
3 ms |
5000 KB |
Output is correct |
8 |
Correct |
2 ms |
5000 KB |
Output is correct |
9 |
Correct |
78 ms |
5044 KB |
Output is correct |
10 |
Correct |
77 ms |
5044 KB |
Output is correct |
11 |
Correct |
21 ms |
5044 KB |
Output is correct |
12 |
Correct |
23 ms |
5044 KB |
Output is correct |
13 |
Correct |
7 ms |
5044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5044 KB |
Output is correct |
2 |
Correct |
2 ms |
5044 KB |
Output is correct |
3 |
Correct |
3 ms |
5044 KB |
Output is correct |
4 |
Correct |
2 ms |
5044 KB |
Output is correct |
5 |
Correct |
3 ms |
5044 KB |
Output is correct |
6 |
Correct |
3 ms |
5044 KB |
Output is correct |
7 |
Correct |
2 ms |
5044 KB |
Output is correct |
8 |
Correct |
2 ms |
5044 KB |
Output is correct |
9 |
Correct |
76 ms |
5072 KB |
Output is correct |
10 |
Correct |
57 ms |
5072 KB |
Output is correct |
11 |
Correct |
23 ms |
5072 KB |
Output is correct |
12 |
Correct |
23 ms |
5072 KB |
Output is correct |
13 |
Correct |
7 ms |
5072 KB |
Output is correct |
14 |
Correct |
105 ms |
5992 KB |
Output is correct |
15 |
Correct |
111 ms |
7548 KB |
Output is correct |
16 |
Correct |
17 ms |
7548 KB |
Output is correct |
17 |
Correct |
64 ms |
7548 KB |
Output is correct |
18 |
Correct |
36 ms |
7548 KB |
Output is correct |