# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
30346 |
2017-07-23T09:12:58 Z |
inqr |
Gondola (IOI14_gondola) |
C++14 |
|
56 ms |
7768 KB |
#include "gondola.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define ll long long
#define pii pair < int , int >
#define DB printf("debug\n");
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define all(x) x.begin() , x.end()
#define MOD 1000000009
using namespace std;
int nx(int i,int sz){
return (i+1)%(sz);
}
map < int,int > timesseen;
int origl=-1;
int broken=0;
long long ans=1;
int valid(int n, int inputSeq[])
{
vector < int > orig;
for(int i=0;i<n;i++){
int nxx=nx(i,n);
timesseen[inputSeq[i]]++;
if(timesseen[inputSeq[i]]>1)return 0;
if(inputSeq[i]<=n)orig.pb(inputSeq[i]);
if(inputSeq[i]<=n&&inputSeq[nxx]<=n){
if(inputSeq[i]==n && inputSeq[nxx]!=1)return 0;
else if(inputSeq[i]<n && inputSeq[nxx]!=inputSeq[i]+1)return 0;
}
}
int startover=0;
for(int i=0;i<orig.size();i++){
int nxx=nx(i,orig.size());
if(orig[i]<orig[nxx])continue;
else if(startover==0)startover++;
else if(startover==1)return 0;
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
for(int i=0;i<n;i++){
int nxx=nx(i,n);
if(gondolaSeq[i]<=n){
origl=i-(gondolaSeq[i]-1)+n;
origl%=n;
}
umax(broken,gondolaSeq[i]-n);
}
if(origl==-1){
origl=0;
ans*=n;
ans%=MOD;
}
int repind[broken];
set < int > repcand;
int orig[n];
for(int i=0;i<n;i++){
int ogon=(i+1)-origl+n;
if(ogon>n)ogon%=n;
orig[i]=ogon;
if(gondolaSeq[i]>n){
repcand.insert(i);
repind[gondolaSeq[i]-n-1]=i;
}
}
for(int i=0;i<broken;i++){
if(!repind[i]){
ans*=repcand.size();ans%=MOD;
replacementSeq[i]=orig[*repcand.begin()];
orig[*repcand.begin()]=i+n+1;
}
else{
replacementSeq[i]=orig[repind[i]];
orig[repind[i]]=i+n+1;
repcand.erase(repcand.find(repind[i]));
}
}
return broken;
}
int replacement2(int n, int gondolaSeq[])
{
for(int i=0;i<n;i++){
int nxx=nx(i,n);
if(gondolaSeq[i]<=n){
origl=i-(gondolaSeq[i]-1)+n;
origl%=n;
}
umax(broken,gondolaSeq[i]-n);
}
if(origl==-1){
origl=0;
ans*=n;
ans%=MOD;
}
int repind[broken];
set < int > repcand;
int orig[n];
for(int i=0;i<n;i++){
int ogon=(i+1)-origl+n;
if(ogon>n)ogon%=n;
orig[i]=ogon;
if(gondolaSeq[i]>n){
repcand.insert(i);
repind[gondolaSeq[i]-n-1]=i;
}
}
for(int i=0;i<broken;i++){
if(!repind[i]){
ans*=repcand.size();ans%=MOD;
orig[*repcand.begin()]=i+n+1;
}
else{
orig[repind[i]]=i+n+1;
repcand.erase(repcand.find(repind[i]));
}
}
return broken;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
if(valid(n,inputSeq)==0)return 0;
int a=replacement2(n,inputSeq);
if(a==0)return 1;
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:37:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<orig.size();i++){
^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:48:7: warning: unused variable 'nxx' [-Wunused-variable]
int nxx=nx(i,n);
^
gondola.cpp: In function 'int replacement2(int, int*)':
gondola.cpp:92:7: warning: unused variable 'nxx' [-Wunused-variable]
int nxx=nx(i,n);
^
gondola.cpp:107:6: warning: variable 'orig' set but not used [-Wunused-but-set-variable]
int orig[n];
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Correct |
0 ms |
3396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Correct |
0 ms |
3396 KB |
Output is correct |
6 |
Correct |
9 ms |
5400 KB |
Output is correct |
7 |
Correct |
6 ms |
3396 KB |
Output is correct |
8 |
Correct |
36 ms |
7240 KB |
Output is correct |
9 |
Correct |
6 ms |
4612 KB |
Output is correct |
10 |
Correct |
33 ms |
7768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Correct |
0 ms |
3396 KB |
Output is correct |
6 |
Correct |
16 ms |
5400 KB |
Output is correct |
7 |
Correct |
13 ms |
3396 KB |
Output is correct |
8 |
Correct |
29 ms |
7240 KB |
Output is correct |
9 |
Correct |
9 ms |
4612 KB |
Output is correct |
10 |
Correct |
56 ms |
7768 KB |
Output is correct |
11 |
Correct |
0 ms |
3396 KB |
Output is correct |
12 |
Correct |
0 ms |
3396 KB |
Output is correct |
13 |
Correct |
16 ms |
4584 KB |
Output is correct |
14 |
Correct |
0 ms |
3396 KB |
Output is correct |
15 |
Correct |
23 ms |
3396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Correct |
0 ms |
3396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Correct |
0 ms |
3396 KB |
Output is correct |
6 |
Runtime error |
0 ms |
3396 KB |
Execution killed because of forbidden syscall writev (20) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Correct |
0 ms |
3396 KB |
Output is correct |
6 |
Runtime error |
0 ms |
3396 KB |
Execution killed because of forbidden syscall writev (20) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Runtime error |
0 ms |
3396 KB |
Execution killed because of forbidden syscall writev (20) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Runtime error |
0 ms |
3396 KB |
Execution killed because of forbidden syscall writev (20) |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3396 KB |
Output is correct |
2 |
Correct |
0 ms |
3396 KB |
Output is correct |
3 |
Correct |
0 ms |
3396 KB |
Output is correct |
4 |
Correct |
0 ms |
3396 KB |
Output is correct |
5 |
Runtime error |
0 ms |
3396 KB |
Execution killed because of forbidden syscall writev (20) |
6 |
Halted |
0 ms |
0 KB |
- |