# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
953578 |
2024-03-26T09:21:48 Z |
irmuun |
Gondola (IOI14_gondola) |
C++17 |
|
48 ms |
5968 KB |
#include<bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int valid(int n, int in[]){
int mn=n+1,pos=-1;
map<int,bool>used;
for(int i=0;i<n;i++){
if(used[in[i]]){
return 0;
}
used[in[i]]=true;
if(in[i]<=n){
if(in[i]<mn){
mn=in[i];
pos=i;
}
}
}
if(pos==-1) return 1;
for(int i=0;i<n;i++){
int p=(pos+i)%n;
if(in[p]<=n){
if(in[p]!=mn+i) return 0;
}
}
return 1;
}
int replacement(int n, int gon[], int rep[]){
int mx=0;
vector<pair<int,int>>v;
int a[n];
iota(a,a+n,1);
int mn=n+1,pos=-1;
for(int i=0;i<n;i++){
if(gon[i]<=n){
if(gon[i]<mn){
mn=gon[i];
pos=i;
}
}
}
if(pos>-1){
for(int i=0;i<n;i++){
a[(i+pos)%n]=mn;
mn=mn+1;
if(mn>n) mn=1;
}
}
for(int i=0;i<n;i++){
if(gon[i]>n){
v.pb({gon[i],i});
}
}
sort(all(v));
for(int i=0;i<v.size();i++){
}
int l=n+1,cur=0;
for(int i=0;i<v.size();i++){
int bef=a[v[i].ss];
for(;l<=v[i].ff;l++){
rep[cur++]=bef;
bef=l;
}
}
return cur;
}
const int mod=1e9+9;
int binpow(int a,int b){
int res=1;
while(b){
if(b&1){
res=1ll*res*a%mod;
}
a=1ll*a*a%mod;
b=b>>1;
}
return res;
}
int countReplacement(int n, int in[]){
int ans=valid(n,in);
if(ans==0) return 0;
bool flag=false;
for(int i=0;i<n;i++){
if(in[i]<=n){
flag=true;
}
}
if(!flag){
ans=n;
}
vector<int>v;
for(int i=0;i<n;i++){
if(in[i]>n){
v.pb(in[i]);
}
}
int left=v.size(),last=n;
sort(all(v));
for(int i=0;i<v.size();i++){
ans=1ll*ans*binpow(left,v[i]-last-1)%mod;
last=v[i];
left--;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
gondola.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
gondola.cpp:38:9: warning: unused variable 'mx' [-Wunused-variable]
38 | int mx=0;
| ^~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:108:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
6 |
Correct |
11 ms |
2144 KB |
Output is correct |
7 |
Correct |
6 ms |
788 KB |
Output is correct |
8 |
Correct |
22 ms |
3912 KB |
Output is correct |
9 |
Correct |
6 ms |
1372 KB |
Output is correct |
10 |
Correct |
23 ms |
4556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
6 |
Correct |
9 ms |
2140 KB |
Output is correct |
7 |
Correct |
7 ms |
608 KB |
Output is correct |
8 |
Correct |
19 ms |
3908 KB |
Output is correct |
9 |
Correct |
6 ms |
1376 KB |
Output is correct |
10 |
Correct |
24 ms |
4448 KB |
Output is correct |
11 |
Correct |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
0 ms |
352 KB |
Output is correct |
13 |
Correct |
13 ms |
2088 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
32 ms |
4824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
356 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
6 ms |
860 KB |
Output is correct |
12 |
Correct |
7 ms |
1116 KB |
Output is correct |
13 |
Correct |
11 ms |
1516 KB |
Output is correct |
14 |
Correct |
6 ms |
860 KB |
Output is correct |
15 |
Correct |
15 ms |
2388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
36 ms |
4160 KB |
Output is correct |
10 |
Correct |
26 ms |
3416 KB |
Output is correct |
11 |
Correct |
10 ms |
1372 KB |
Output is correct |
12 |
Correct |
12 ms |
1836 KB |
Output is correct |
13 |
Correct |
4 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
34 ms |
4052 KB |
Output is correct |
10 |
Correct |
26 ms |
3420 KB |
Output is correct |
11 |
Correct |
9 ms |
1372 KB |
Output is correct |
12 |
Correct |
12 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
752 KB |
Output is correct |
14 |
Correct |
41 ms |
5460 KB |
Output is correct |
15 |
Correct |
48 ms |
5968 KB |
Output is correct |
16 |
Correct |
8 ms |
1368 KB |
Output is correct |
17 |
Correct |
30 ms |
4112 KB |
Output is correct |
18 |
Correct |
16 ms |
2392 KB |
Output is correct |