# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
798686 |
2023-07-30T23:26:00 Z |
Liudas |
Gondola (IOI14_gondola) |
C++17 |
|
1000 ms |
6052 KB |
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
int valid(int N, int seq[]){
vector<int> s(2 * N);
set<int> ss;
int val = true;
for(int i = 0; i < N; i ++){
ss.insert(seq[i]);
s[i] = seq[i];
s[i + N] = seq[i];
}
if(ss.size()!=N)val = false;
int start = min_element(s.begin(), s.begin() + N) - s.begin();
int k = *min_element(s.begin(), s.begin() + N);
for(int i = start; i < start + N; i ++, k ++){
if(s[i] <= N && s[i] != k){
val = false;
}
}
return val;
}
int replacement(int N, int seq[], int rseq[]){
vector<int> s(2 * N), ss(2 * N);
vector<pair<int, int>> arr(N);
for(int i = 0; i < N; i ++){
s[i] = seq[i];
s[N+i] = seq[i];
}
int k = min_element(s.begin(), s.begin() + N) - s.begin();
int t = *min_element(s.begin(), s.begin() + N);
for(int i = k; i < k + N; i ++){
ss[i] = (t-1)%N+1;
t++;
}
for(int i = k; i < k + N; i ++){
arr[i-k] = {s[i], ss[i]};
}
int p = 0;
int last = N;
sort(arr.begin(), arr.end());
for(int i = 0; i < N; i ++){
if(arr[i].first > N){
rseq[p++] = arr[i].second;
for(;++last< arr[i].first;){
rseq[p++] = last;
}
}
}
return p;
}
int countReplacement(int N, int seq[]){
int check = valid(N, seq);
int MOD = 1e9 + 9;
if(!check){return 0;}
vector<int> broke(1, N);
for(int i = 0; i < N; i ++){
if(seq[i] > N){
broke.push_back(seq[i]);
}
}
sort(broke.begin(), broke.end());
long long ans = 1;
for(int i = 1; i < broke.size(); i++){
for(int j = broke[i-1] + 1; j < broke[i]; j ++)
ans = ans * (broke.size()-i) % MOD;
}
if(broke.size() == N + 1){
ans = ans * N % MOD;
}
return (int)ans;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:13:17: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
13 | if(ss.size()!=N)val = false;
| ~~~~~~~~~^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 1; i < broke.size(); i++){
| ~~^~~~~~~~~~~~~~
gondola.cpp:68:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
68 | if(broke.size() == N + 1){
| ~~~~~~~~~~~~~^~~~~~~~
# |
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 |
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 |
312 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 |
9 ms |
2636 KB |
Output is correct |
7 |
Correct |
21 ms |
4764 KB |
Output is correct |
8 |
Correct |
15 ms |
4904 KB |
Output is correct |
9 |
Correct |
5 ms |
1748 KB |
Output is correct |
10 |
Correct |
19 ms |
5644 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 |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
6 |
Correct |
8 ms |
2644 KB |
Output is correct |
7 |
Correct |
23 ms |
4848 KB |
Output is correct |
8 |
Correct |
16 ms |
4820 KB |
Output is correct |
9 |
Correct |
5 ms |
1748 KB |
Output is correct |
10 |
Correct |
20 ms |
5564 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
10 ms |
2548 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
31 ms |
5828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 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 |
# |
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 |
308 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 |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 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 |
9 ms |
2936 KB |
Output is correct |
12 |
Correct |
10 ms |
3184 KB |
Output is correct |
13 |
Correct |
11 ms |
1748 KB |
Output is correct |
14 |
Correct |
8 ms |
2804 KB |
Output is correct |
15 |
Correct |
17 ms |
2232 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 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 |
308 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 |
# |
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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
304 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 |
308 KB |
Output is correct |
9 |
Correct |
26 ms |
4856 KB |
Output is correct |
10 |
Correct |
25 ms |
4172 KB |
Output is correct |
11 |
Correct |
8 ms |
1748 KB |
Output is correct |
12 |
Correct |
9 ms |
2004 KB |
Output is correct |
13 |
Correct |
3 ms |
704 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 |
340 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 |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
26 ms |
4660 KB |
Output is correct |
10 |
Correct |
21 ms |
3796 KB |
Output is correct |
11 |
Correct |
8 ms |
1624 KB |
Output is correct |
12 |
Correct |
9 ms |
1888 KB |
Output is correct |
13 |
Correct |
4 ms |
596 KB |
Output is correct |
14 |
Execution timed out |
1071 ms |
6052 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |