# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
792965 |
2023-07-25T11:43:21 Z |
MODDI |
Gondola (IOI14_gondola) |
C++14 |
|
1000 ms |
2316 KB |
#include "gondola.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
int valid(int n, int inputSeq[])
{
int pos = -1;
for(int i = 0; i < n; i++){
if(inputSeq[i] == 1){
pos = i;
break;
}
}
bool seq = true;
int at = 1, lim = pos;
while(pos < n){
if(inputSeq[pos] == at){
pos++;
at++;
}
else{
seq = false;
break;
}
}
if(!seq) return 0;
pos = 0;
while(pos < lim){
if(inputSeq[pos] == at){
pos++;
at++;
}
else{
seq = false;
break;
}
}
if(!seq) return 0;
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int pos = -1;
for(int i = 0; i < n; i++){
if(gondolaSeq[i] >= 1 && gondolaSeq[i] <= n){
pos = i;
break;
}
}
if(pos == -1){
vector<pii> arr(n);
for(int i = 0; i < n; i++){
arr[i] = mp(gondolaSeq[i], i);
}
sort(arr.begin(), arr.end());
int j = 0, rez = 0, here = 1, at = n + 1;
int pos = arr[0].second, need[n];
for(int i = pos; i < n; i++) need[i] = here++;
for(int i = 0; i < pos; i++) need[i] = here++;
for(int i = 0; i < (int)arr.size(); i++){
int where = arr[i].second, val = arr[i].first;
replacementSeq[j++] = need[where];
rez++;
while(at < val){
replacementSeq[j++] = at++;
rez++;
}
at++;
}
return rez;
}
else{
int need[n];
bool done[n+1];
memset(done, false, sizeof done);
int at = gondolaSeq[pos];
while(at <= n){
at++;
pos++; pos%=n;
}
int here = 1;
for(int i = pos; i < n; i++) need[i] = here++;
for(int i = 0; i < pos; i++) need[i] = here++;
vector<pii> arr;
for(int i = 0; i < n; i++){
if(need[i] == gondolaSeq[i]) done[need[i]] = true;
else{
arr.pb(mp(gondolaSeq[i], i));
}
}
sort(arr.begin(), arr.end());
at = n + 1;
int j = 0, rez = 0;
for(int i = 0; i < (int)arr.size(); i++){
int where = arr[i].second, val = arr[i].first;
replacementSeq[j++] = need[where];
rez++;
while(at < val){
replacementSeq[j++] = at++;
rez++;
}
at++;
}
return rez;
}
}
const int mod = 1e9 + 9;
int countReplacement(int n, int inputSeq[])
{
//int checker = valid(n, inputSeq);
vector<pii> arr;
int pos = -1;
for(int i = 0; i < n; i++){
arr.pb(mp(inputSeq[i], i));
if(inputSeq[i] >= 1 && inputSeq[i] <= n) pos = i;
}
if(pos == -1) assert(false);
int at = inputSeq[pos];
while(at <= n){
at++;
pos++;
pos%=n;
}
int skipped = 0;
at=1;
bool ok = true;
for(int i = pos; i < n; i++){
if(inputSeq[i] == at+skipped){
at++;
skipped = 0;
}
else if(inputSeq[i] <= n && at + skipped > inputSeq[i]){
ok = false;
}
else
skipped++;
}
//cout<<"OK: "<<ok<<endl;
if(!ok) return 0;
bool sub1 = true;
for(int i = 0; i < n; i++){
if(inputSeq[i] >= 1 && inputSeq[i] <= n + 3) continue;
else sub1 = false;
}
if(n > 50) sub1 = false;
if(sub1){
bool n1 = false, n2 = false, n3 = false;
for(int i = 0; i < n; i++){
if(inputSeq[i] == n+1) n1 = true;
if(inputSeq[i] == n+2) n2 = true;
if(inputSeq[i] == n+3) n3 = true;
}
if(!n1 && n2 && n3) return 2;
else return 1;
}
else if(n <= 50){
//cout<<"HERE: "<<endl;
ll ways = 1;
int at = n+1;
while(at <= 100){
bool ima = false;
for(int i = 0; i < n; i++){
if(inputSeq[i] == at) ima = true;
}
if(ima) at++;
else{
int cnt = 0;
for(int i = 0; i < n; i++){
if(inputSeq[i] > at) cnt++;
}
if(cnt ==0) break;
ways *= cnt;
ways %= mod;
at++;
}
}
return (int)ways;
}
bool sub2 = true;
for(int i = 0; i < n; i++){
if(inputSeq[i] > 250000) sub2 = false;
}
if(sub2){
vi arr;
for(int i = 0; i < inputSeq[i]; i++){
if(inputSeq[i] <= n) continue;
else arr.pb(inputSeq[i]);
}
int at = n + 1;
ll ways = 1;
sort(arr.begin(), arr.end());
for(int i = 0; i < (int)arr.size(); i++){
while(at < arr[i]){
ways *= (arr.size() - i);
ways %= mod;
}
}
return (int)ways;
}
return -3;
}
# |
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 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
7 ms |
1128 KB |
Output is correct |
8 |
Correct |
5 ms |
872 KB |
Output is correct |
9 |
Correct |
2 ms |
472 KB |
Output is correct |
10 |
Correct |
9 ms |
1088 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 |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
616 KB |
Output is correct |
7 |
Correct |
10 ms |
1132 KB |
Output is correct |
8 |
Correct |
5 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
6 ms |
1088 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
3 ms |
624 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
7 ms |
1108 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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
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 |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
2 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
6 ms |
1364 KB |
Output is correct |
12 |
Correct |
10 ms |
1576 KB |
Output is correct |
13 |
Correct |
11 ms |
1636 KB |
Output is correct |
14 |
Correct |
6 ms |
1340 KB |
Output is correct |
15 |
Correct |
17 ms |
2316 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 |
0 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 |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
308 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 |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Execution timed out |
1077 ms |
2124 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Execution timed out |
1087 ms |
2252 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |