# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
203633 |
2020-02-21T17:30:12 Z |
thebes |
Gondola (IOI14_gondola) |
C++14 |
|
94 ms |
5112 KB |
#include "gondola.h"
#include <bits/stdc++.h>
#define DEBUG 1
using namespace std;
namespace output{
void __(short x){cout<<x;}
void __(unsigned x){cout<<x;}
void __(int x){cout<<x;}
void __(long long x){cout<<x;}
void __(unsigned long long x){cout<<x;}
void __(double x){cout<<x;}
void __(long double x){cout<<x;}
void __(char x){cout<<x;}
void __(const char*x){cout<<x;}
void __(const string&x){cout<<x;}
void __(bool x){cout<<(x?"true":"false");}
template<class S,class T>
void __(const pair<S,T>&x){__(DEBUG?"(":""),__(x.first),__(DEBUG?", ":" "),__(x.second),__(DEBUG?")":"");}
template<class T>
void __(const vector<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class T>
void __(const set<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class T>
void __(const multiset<T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
template<class S,class T>
void __(const map<S,T>&x){__(DEBUG?"{":"");bool _=0;for(const auto&v:x)__(_?DEBUG?", ":" ":""),__(v),_=1;__(DEBUG?"}":"");}
void pr(){cout<<"\n";}
template<class S,class... T>
void pr(const S&a,const T&...b){__(a);if(sizeof...(b))__(' ');pr(b...);}
}
using namespace output;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vl;
#define pb push_back
#define fox(i,x,y) for(int i=(x);i<=(y);i++)
#define foxr(i,x,y) for(int i=(y);i>=(x);i--)
int valid(int n,int *arr){
set<int> S;
for(int i=0;i<n;i++) S.insert(arr[i]);
if(S.size()!=n) return 0;
int mn=1<<30, st=-1;
for(int i=0;i<n;i++){
if(arr[i]>n) continue;
if(arr[i]<mn){
mn = arr[i];
st = (i-arr[i]+1+n)%n;
}
}
if(st==-1) return 1;
int f = 1;
for(int i=0;i<n;i++){
if(arr[(i+st)%n]>n) continue;
if(arr[(i+st)%n]!=i+1) f=0;
}
return f;
}
int replacement(int n,int *arr,int *rep){
vi seq; seq.resize(n);
int mn=1<<30, st=0;
for(int i=0;i<n;i++){
if(arr[i]>n) continue;
if(arr[i]<mn){
mn = arr[i];
st = (i-arr[i]+1+n)%n;
}
}
map<int,int> op;
int lst=n+1, sz=0;
for(int i=0;i<n;i++){
seq[i]=i+1;
if(arr[(st+i)%n]>n) op[arr[(st+i)%n]]=i;
}
for(auto v : op){
while(lst<v.first) rep[sz++]=seq[v.second],seq[v.second]=lst,lst++;
lst = v.first+1;
rep[sz++]=seq[v.second], seq[v.second]=v.first;
}
return sz;
}
int mod = 1e9+9;
int qpow(int b,int exp){
if(exp<=0) return 1;
else if(exp&1) return 1LL*b*qpow(b,exp-1)%mod;
else{int r=qpow(b,exp>>1); return 1LL*r*r%mod;}
}
int countReplacement(int n,int *arr){
if(!valid(n,arr)) return 0;
map<int,int> op;
int rem = 0, ans = 1;
for(int i=0;i<n;i++){
if(arr[i]>n){
rem++;
op[arr[i]]=i;
}
}
if(rem==n) ans *= n;
int lst = n+1;
for(auto v : op){
ans = 1LL*ans*qpow(rem,v.first-lst)%mod;
rem--; lst = v.first+1;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:51:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(S.size()!=n) return 0;
~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
17 ms |
2296 KB |
Output is correct |
7 |
Correct |
37 ms |
3704 KB |
Output is correct |
8 |
Correct |
29 ms |
3960 KB |
Output is correct |
9 |
Correct |
12 ms |
1528 KB |
Output is correct |
10 |
Correct |
33 ms |
4600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
17 ms |
2296 KB |
Output is correct |
7 |
Correct |
37 ms |
3704 KB |
Output is correct |
8 |
Correct |
27 ms |
3960 KB |
Output is correct |
9 |
Correct |
13 ms |
1528 KB |
Output is correct |
10 |
Correct |
33 ms |
4600 KB |
Output is correct |
11 |
Correct |
5 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
21 ms |
2040 KB |
Output is correct |
14 |
Correct |
5 ms |
256 KB |
Output is correct |
15 |
Correct |
47 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
368 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
16 ms |
888 KB |
Output is correct |
12 |
Correct |
19 ms |
1016 KB |
Output is correct |
13 |
Correct |
27 ms |
2660 KB |
Output is correct |
14 |
Correct |
16 ms |
1016 KB |
Output is correct |
15 |
Correct |
29 ms |
2204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
63 ms |
4088 KB |
Output is correct |
10 |
Correct |
47 ms |
3452 KB |
Output is correct |
11 |
Correct |
21 ms |
1400 KB |
Output is correct |
12 |
Correct |
25 ms |
1656 KB |
Output is correct |
13 |
Correct |
9 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
256 KB |
Output is correct |
6 |
Correct |
5 ms |
256 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
61 ms |
4088 KB |
Output is correct |
10 |
Correct |
49 ms |
3448 KB |
Output is correct |
11 |
Correct |
21 ms |
1400 KB |
Output is correct |
12 |
Correct |
26 ms |
1656 KB |
Output is correct |
13 |
Correct |
9 ms |
636 KB |
Output is correct |
14 |
Correct |
81 ms |
4600 KB |
Output is correct |
15 |
Correct |
94 ms |
5112 KB |
Output is correct |
16 |
Correct |
18 ms |
1144 KB |
Output is correct |
17 |
Correct |
60 ms |
3576 KB |
Output is correct |
18 |
Correct |
35 ms |
2172 KB |
Output is correct |