# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
819722 |
2023-08-10T12:57:37 Z |
kebine |
Gondola (IOI14_gondola) |
C++17 |
|
45 ms |
5792 KB |
#include <bits/stdc++.h>
#include "gondola.h"
#define ll long long
#define mod 1000000007
using namespace std;
int n;
int inputSeq[1000];
ll binpow(ll x,ll y){
if( y == 0 ) return 1;
ll res = binpow(x,y/2);
res *= res;
res %= mod;
if( y % 2 ) res *= x;
return res%mod;
}
int replacement(int n, int inputSeq[], int replacementSeq[]){
int mn = INT_MAX;
int id;
for(int i = 0 ; i < n ; i++){
if( mn > inputSeq[i] ){
mn = inputSeq[i];
id = i;
}
}
vector<int> v;
mn--;
id = (id-mn)%n+n;
id %= n;
for(int i = id ; i < n ; i++) v.push_back(inputSeq[i]);
for(int i = 0 ; i < id ; i++) v.push_back(inputSeq[i]);
priority_queue<pair<int,int>> pq;
for(int i = 0 ; i < n ; i++){
pq.push({-v[i],i+1});
}
int mx = *max_element(v.begin(),v.end());
if( mx == n ) return 0;
int cur = n+1;
int ti = 0;
while(!pq.empty()){
int fufu = pq.top().second;
while(cur <= -pq.top().first){
replacementSeq[ti] = fufu;
fufu = cur;
ti++;
cur++;
}
pq.pop();
}
//~ for(int i = 0; i < mx-n ; i++){
//~ cout<<replacementSeq[i]<<" ";
//~ }
//~ cout<<"\n";
return mx-n;
}
int valid(int n,int inputSeq[]){
int mn = INT_MAX;
int id;
map<int,int> cnt;
for(int i = 0 ; i < n ; i++){
cnt[inputSeq[i]]++;
if( cnt[inputSeq[i]] > 1 ) return 0;
}
for(int i = 0 ; i < n ; i++){
if( mn > inputSeq[i] ){
mn = inputSeq[i];
id = i;
}
}
if( mn > n ) return 1;
vector<int> v;
mn--;
id = (id-mn)%n+n;
id %= n;
for(int i = id ; i < n ; i++) v.push_back(inputSeq[i]);
for(int i = 0 ; i < id ; i++) v.push_back(inputSeq[i]);
for(int i = 0 ; i < n ; i++){
if( v[i] <= n && v[i] != i+1 ) return 0;
}
return 1;
}
int countReplacement(int n, int inputSeq[]){
if(!valid(n,inputSeq)) return 0;
ll mx = *max_element(inputSeq,inputSeq+n);
ll u = mx;
mx -= n;
ll c = 0;
for(int i = 0 ; i < n ; i++){
int x = inputSeq[i];
if( x > n ) {
c++;
mx--;
}
}
ll fact[mx+5];
fact[0] = fact[1] = 1;
for(ll i = 2; i <= n ; i++){
fact[i] = fact[i-1]*i;
fact[i] %= mod;
}
if( u <= n ) return binpow(fact[c],mx);
else return (binpow(fact[c],mx)*fact[n])%mod;
}
//~ int main(){
//~ ios_base::sync_with_stdio(false);
//~ cin.tie(0);
//~ cout.tie(0);
//~ cin>>n;
//~ for(int i = 0 ; i < n ; i++){
//~ cin>>inputSeq[i];
//~ }
//~ cout<<countReplacement(n,inputSeq)<<"\n";
//~ }
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:29:11: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
29 | id = (id-mn)%n+n;
| ~~~^~~~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:75:11: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
75 | id = (id-mn)%n+n;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
2828 KB |
Output is correct |
7 |
Correct |
7 ms |
1108 KB |
Output is correct |
8 |
Correct |
19 ms |
4904 KB |
Output is correct |
9 |
Correct |
6 ms |
1748 KB |
Output is correct |
10 |
Correct |
29 ms |
5592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
2772 KB |
Output is correct |
7 |
Correct |
9 ms |
1088 KB |
Output is correct |
8 |
Correct |
20 ms |
4944 KB |
Output is correct |
9 |
Correct |
6 ms |
1788 KB |
Output is correct |
10 |
Correct |
30 ms |
5604 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
16 ms |
2608 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
45 ms |
5792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
236 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
10 ms |
2488 KB |
Output is correct |
12 |
Correct |
8 ms |
2616 KB |
Output is correct |
13 |
Correct |
17 ms |
1424 KB |
Output is correct |
14 |
Correct |
8 ms |
2432 KB |
Output is correct |
15 |
Correct |
17 ms |
2344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |