# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1063739 |
2024-08-18T00:38:35 Z |
pawned |
Gondola (IOI14_gondola) |
C++17 |
|
42 ms |
7508 KB |
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
#include "gondola.h"
const ll MOD = 1e9 + 9;
ll nr(ll x) {
x %= MOD;
x += MOD;
x %= MOD;
return x;
}
ll binpow(ll x, ll y) {
x = nr(x);
ll res = 1;
while (y > 0) {
if (y % 2 == 1)
res = nr(res * x);
x = nr(x * x);
y /= 2;
}
return res;
}
int valid(int N, int inputSeq[]) {
vi a;
for (int i = 0; i < N; i++) {
a.pb(inputSeq[i] - 1);
}
int fpos = -1; // fixed position
int fval = -1; // fixed val at position
for (int i = 0; i < N; i++) {
if (a[i] < N) {
fpos = i;
fval = a[i];
}
}
vi b;
if (fval > fpos) {
int s = fval - fpos;
for (int i = N - s; i < N; i++) {
b.pb(a[i]);
}
for (int i = 0; i < N - s; i++) {
b.pb(a[i]);
}
}
else {
int s = fpos - fval;
for (int i = s; i < N; i++) {
b.pb(a[i]);
}
for (int i = 0; i < s; i++) {
b.pb(a[i]);
}
}
for (int i = 0; i < N; i++) {
if (b[i] < N) {
if (b[i] != i)
return 0;
}
}
// all values must be diff
set<int> allv;
for (int x : b)
allv.insert(x);
if (allv.size() != N)
return 0;
return 1;
}
int replacement(int N, int gondolaSeq[], int replacementSeq[]) {
vi a;
for (int i = 0; i < N; i++) {
a.pb(gondolaSeq[i] - 1);
}
int fpos = -1; // fixed position
int fval = -1; // fixed val at position
for (int i = 0; i < N; i++) {
if (a[i] < N) {
fpos = i;
fval = a[i];
}
}
vi b;
if (fpos == -1) {
b = a;
}
else if (fval > fpos) {
int s = fval - fpos;
for (int i = N - s; i < N; i++) {
b.pb(a[i]);
}
for (int i = 0; i < N - s; i++) {
b.pb(a[i]);
}
}
else {
int s = fpos - fval;
for (int i = s; i < N; i++) {
b.pb(a[i]);
}
for (int i = 0; i < s; i++) {
b.pb(a[i]);
}
}
/* cout<<"b: ";
for (int x : b)
cout<<x<<" ";
cout<<endl;*/
// replace 0, 1, ..., N - 1 with b
vector<ii> rep;
for (int i = 0; i < N; i++) {
if (b[i] != i)
rep.pb({b[i], i});
}
sort(rep.begin(), rep.end());
/* cout<<"rep: ";
for (ii p : rep)
cout<<"("<<p.fi<<", "<<p.se<<"); ";
cout<<endl;*/
if (rep.size() == 0) { // just 0 to N - 1
return 0;
}
int curr = N - 1;
vi ans;
for (int i = 0; i < rep.size(); i++) {
ans.pb(rep[i].se);
for (int j = curr + 1; j < rep[i].fi; j++) {
ans.pb(j);
}
curr = rep[i].fi;
}
int K = ans.size();
for (int i = 0; i < K; i++) {
replacementSeq[i] = ans[i] + 1;
}
return K;
}
int countReplacement(int N, int inputSeq[]) {
if (!valid(N, inputSeq))
return 0;
vi a;
for (int i = 0; i < N; i++) {
a.pb(inputSeq[i] - 1);
}
vi pr; // those over N - 1
for (int i = 0; i < N; i++) {
if (a[i] > N - 1)
pr.pb(a[i]);
}
pr.pb(N - 1);
sort(pr.begin(), pr.end());
/* cout<<"pr: ";
for (int x : pr)
cout<<x<<" ";
cout<<endl;*/
int K = pr.size();
ll ans = 1;
for (int i = 0; i < K - 1; i++) {
ll diff = pr[i + 1] - pr[i] - 1;
ans = nr(ans * binpow(K - i - 1, diff));
}
if (K == N + 1)
ans = nr(ans * N);
return (int)(ans);
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:78:18: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
78 | if (allv.size() != N)
| ~~~~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:138:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
138 | for (int i = 0; i < rep.size(); i++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
2904 KB |
Output is correct |
7 |
Correct |
8 ms |
3024 KB |
Output is correct |
8 |
Correct |
16 ms |
5040 KB |
Output is correct |
9 |
Correct |
4 ms |
1884 KB |
Output is correct |
10 |
Correct |
18 ms |
5956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
7 ms |
2904 KB |
Output is correct |
7 |
Correct |
7 ms |
3024 KB |
Output is correct |
8 |
Correct |
15 ms |
4992 KB |
Output is correct |
9 |
Correct |
5 ms |
1840 KB |
Output is correct |
10 |
Correct |
17 ms |
5972 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
1492 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
7 ms |
2768 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
0 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 |
7 ms |
2768 KB |
Output is correct |
12 |
Correct |
8 ms |
3024 KB |
Output is correct |
13 |
Correct |
11 ms |
2656 KB |
Output is correct |
14 |
Correct |
7 ms |
2668 KB |
Output is correct |
15 |
Correct |
17 ms |
3164 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
432 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 |
31 ms |
5816 KB |
Output is correct |
10 |
Correct |
23 ms |
4696 KB |
Output is correct |
11 |
Correct |
8 ms |
1884 KB |
Output is correct |
12 |
Correct |
11 ms |
2356 KB |
Output is correct |
13 |
Correct |
3 ms |
860 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
28 ms |
5672 KB |
Output is correct |
10 |
Correct |
22 ms |
4696 KB |
Output is correct |
11 |
Correct |
8 ms |
2064 KB |
Output is correct |
12 |
Correct |
10 ms |
2396 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
36 ms |
6644 KB |
Output is correct |
15 |
Correct |
42 ms |
7508 KB |
Output is correct |
16 |
Correct |
7 ms |
1624 KB |
Output is correct |
17 |
Correct |
27 ms |
5208 KB |
Output is correct |
18 |
Correct |
15 ms |
3160 KB |
Output is correct |