# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
706469 |
2023-03-06T16:38:46 Z |
Hacv16 |
Gondola (IOI14_gondola) |
C++17 |
|
65 ms |
5976 KB |
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 9;
const int INF = 0x3f3f3f3f;
ll fexp(ll b, ll e){
if(e == 0) return 1;
if(e % 2 == 0) return fexp((b * b) % MOD, e >> 1);
return (b * fexp(b, e - 1)) % MOD;
}
int valid(int n, int v[]){
set<int> s(v, v + n);
if((int) s.size() != n) return 0;
for(int i = 0; i < n; i++){
if(v[i] > n) continue;
int left = (v[i] == 1 ? n : v[i] - 1), right = (v[i] == n ? 1 : v[i] + 1);
int lefViz = (i == 0 ? v[n - 1] : v[i - 1]);
int rigViz = (i == n - 1 ? v[0] : v[i + 1]);
if((lefViz != left && lefViz <= n) || (rigViz != right && rigViz <= n)) return 0;
}
return 1;
}
int countReplacement(int n, int v[]){
if(!valid(n, v)) return 0;
set<ll> s;
for(int i = 0; i < n; i++)
if(v[i] > n) s.insert(v[i]);
ll ans = 1, cnt = s.size(), cur = n + 1;
for(auto x : s){
ll exp = x - cur;
ans = (ans * fexp(cnt, exp)) % MOD;
ans %= MOD; cur = x + 1; cnt--;
}
if(s.size() == n) ans = (n * ans) % MOD;
return (int) ans;
}
int replacement(int n, int v[], int answer[]){
vector<int> order(n);
vector<pair<int, int>> aux;
int mn = INF, mnidx = 0;
for(int i = 0; i < n; i++)
if(v[i] < mn){ mn = v[i]; mnidx = i; }
if(mn > n) mnidx = 0, mn = 1;
for(int i = 0; i < n; i++){
order[(i + mnidx) % n] = mn;
mn = (mn == n ? 1 : mn + 1);
}
for(int i = 0; i < n; i++)
if(v[i] > n) aux.push_back({v[i], order[i]});
sort(aux.begin(), aux.end());
int numOp = 0;
for(int i = 0, val = n; i < aux.size(); i++){
answer[numOp++] = aux[i].second; val++;
while(val < aux[i].first)
answer[numOp++] = val++;
}
return numOp;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:49:17: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | if(s.size() == n) ans = (n * ans) % MOD;
| ~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0, val = n; i < aux.size(); i++){
| ~~^~~~~~~~~~~~
# |
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 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
2132 KB |
Output is correct |
7 |
Correct |
24 ms |
3532 KB |
Output is correct |
8 |
Correct |
17 ms |
3924 KB |
Output is correct |
9 |
Correct |
4 ms |
1364 KB |
Output is correct |
10 |
Correct |
16 ms |
4432 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
2132 KB |
Output is correct |
7 |
Correct |
23 ms |
3668 KB |
Output is correct |
8 |
Correct |
18 ms |
3940 KB |
Output is correct |
9 |
Correct |
5 ms |
1408 KB |
Output is correct |
10 |
Correct |
16 ms |
4504 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
11 ms |
2020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
29 ms |
4692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
0 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 |
1 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 |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 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 |
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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
8 ms |
852 KB |
Output is correct |
12 |
Correct |
9 ms |
980 KB |
Output is correct |
13 |
Correct |
13 ms |
1224 KB |
Output is correct |
14 |
Correct |
8 ms |
872 KB |
Output is correct |
15 |
Correct |
17 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
304 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
50 ms |
4504 KB |
Output is correct |
10 |
Correct |
32 ms |
3780 KB |
Output is correct |
11 |
Correct |
12 ms |
1492 KB |
Output is correct |
12 |
Correct |
15 ms |
1836 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
42 ms |
4400 KB |
Output is correct |
10 |
Correct |
32 ms |
3664 KB |
Output is correct |
11 |
Correct |
12 ms |
1492 KB |
Output is correct |
12 |
Correct |
15 ms |
1984 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
53 ms |
5368 KB |
Output is correct |
15 |
Correct |
65 ms |
5976 KB |
Output is correct |
16 |
Correct |
10 ms |
1340 KB |
Output is correct |
17 |
Correct |
49 ms |
4172 KB |
Output is correct |
18 |
Correct |
21 ms |
2368 KB |
Output is correct |