# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
385881 |
2021-04-05T07:34:13 Z |
Keshi |
Gondola (IOI14_gondola) |
C++17 |
|
70 ms |
5996 KB |
//In the name of God
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll maxn = 5e5 + 100;
const ll mod = 1e9 + 9;
const ll inf = 1e18;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
int valid(int n, int inputSeq[]){
map<int, int> vis;
ll x = -1;
for(ll i = 0; i < n; i++){
if(vis[inputSeq[i]]) return 0;
vis[inputSeq[i]] = 1;
if(inputSeq[i] <= n) x = i;
}
if(x == -1) return 1;
for(ll i = 0; i < n; i++){
if(inputSeq[i] > n) continue;
if((inputSeq[i] - inputSeq[x] + n) % n != (i - x + n) % n) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
ll a[n];
ll x = 0;
vector<pll> vec;
for(ll i = 0; i < n; i++){
if(gondolaSeq[i] <= n){
x = (i - gondolaSeq[i] + n) % n;
}
else{
vec.pb(Mp(gondolaSeq[i], i));
}
}
sort(all(vec));
for(ll i = 0; i < n; i++){
a[i] = (-x + i + n) % n;
if(a[i] == 0) a[i] = n;
}
ll p = n;
ll t = 0;
for(ll i = 0; i < Sz(vec); i++){
while(p < vec[i].F){
replacementSeq[t++] = a[vec[i].S];
a[vec[i].S] = ++p;
}
}
return t;
}
ll pw(ll a, ll b){
ll c = 1;
while(b){
if(b & 1) c = c * a % mod;
a = a * a % mod;
b >>= 1;
}
return c;
}
//----------------------
int countReplacement(int n, int inputSeq[]){
if(!valid(n, inputSeq)) return 0;
vector<ll> vec;
for(ll i = 0; i < n; i++){
if(inputSeq[i] > n){
vec.pb(inputSeq[i]);
}
}
sort(all(vec));
ll p = n;
ll ans = 1;
if(Sz(vec) == n) ans = n;
for(ll i = 0; i < Sz(vec); i++){
ans = ans * pw(Sz(vec) - i, vec[i] - p - 1) % mod;
p = vec[i];
}
return ans;
}
/*int main(){
fast_io;
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
16 ms |
2284 KB |
Output is correct |
7 |
Correct |
12 ms |
748 KB |
Output is correct |
8 |
Correct |
32 ms |
3948 KB |
Output is correct |
9 |
Correct |
10 ms |
1516 KB |
Output is correct |
10 |
Correct |
36 ms |
4588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
17 ms |
2284 KB |
Output is correct |
7 |
Correct |
11 ms |
748 KB |
Output is correct |
8 |
Correct |
32 ms |
3948 KB |
Output is correct |
9 |
Correct |
9 ms |
1516 KB |
Output is correct |
10 |
Correct |
36 ms |
4588 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
20 ms |
2156 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
51 ms |
4716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
11 ms |
1260 KB |
Output is correct |
12 |
Correct |
13 ms |
1408 KB |
Output is correct |
13 |
Correct |
17 ms |
1636 KB |
Output is correct |
14 |
Correct |
11 ms |
1260 KB |
Output is correct |
15 |
Correct |
25 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
49 ms |
4076 KB |
Output is correct |
10 |
Correct |
48 ms |
3436 KB |
Output is correct |
11 |
Correct |
14 ms |
1516 KB |
Output is correct |
12 |
Correct |
18 ms |
1772 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
49 ms |
4076 KB |
Output is correct |
10 |
Correct |
38 ms |
3436 KB |
Output is correct |
11 |
Correct |
14 ms |
1516 KB |
Output is correct |
12 |
Correct |
17 ms |
1772 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
14 |
Correct |
63 ms |
4592 KB |
Output is correct |
15 |
Correct |
70 ms |
5996 KB |
Output is correct |
16 |
Correct |
11 ms |
1388 KB |
Output is correct |
17 |
Correct |
51 ms |
4204 KB |
Output is correct |
18 |
Correct |
25 ms |
2796 KB |
Output is correct |