#include "gondola.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> Pll;
typedef long double ldouble;
int vchk[250050] = {};
int valid(int n, int inputSeq[])
{
int L = *max_element(inputSeq, inputSeq + n);
rep(i, L+1) vchk[i] = -1;
rep(i, n) {
if(vchk[inputSeq[i]] != -1) return 0;
vchk[ inputSeq[i] ] = i;
}
pii f = pii(-1, -1);
for(int i=0;i<n;i++) if(inputSeq[i] <= n) f = pii(inputSeq[i], i);
if(f == pii(-1, -1)) return 1;
for(int i=0;i<n;i++) if(inputSeq[i] <= n) {
int exp = (i - f.Se) + f.Fi;
if(exp > n) exp -= n;
if(exp <= 0) exp += n;
if(exp != inputSeq[i]) return 0;
}
return 1;
}
//----------------------
int ep[250050];
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int L = *max_element(gondolaSeq, gondolaSeq + n);
rep(i, L+1) vchk[i] = -1;
rep(i, n) vchk[ gondolaSeq[i] ] = i;
int ret = L - n;
pii f = pii(-1, -1);
for(int i=0;i<n;i++) if(gondolaSeq[i] <= n) f = pii(gondolaSeq[i], i);
if(f == pii(-1, -1)) f = pii(1, 0);
for(int i=0;i<n;i++) {
int exp = (i - f.Se) + f.Fi;
if(exp > n) exp -= n;
if(exp <= 0) exp += n;
ep[i] = exp;
}
int now = ret;
for(int i=L, j=L;i>n;i--) {
while(vchk[j] != -1) --j;
if(j > n || ep[vchk[i]] == j) vchk[j] = vchk[i], replacementSeq[--now] = j;
else {
int t = ep[vchk[i]];
vchk[t] = vchk[i], replacementSeq[--now] = t;
}
}
return ret;
}
//----------------------
int pw(int x, int y, int MOD) {
int res = 1;
while(y) {
if(y & 1) res = (ll)res * x % MOD;
x = (ll)x * x % MOD;
y >>= 1;
}
return res;
}
int countReplacement(int n, int inputSeq[])
{
const int MOD = 1e9 + 9;
int L = *max_element(inputSeq, inputSeq + n);
vector <int> T; rep(i, n) T.pb(inputSeq[i]); sort(all(T));
for(int i=1;i<sz(T);i++) if(T[i] == T[i-1]) return 0;
pii f = pii(-1, -1);
for(int i=0;i<n;i++) if(inputSeq[i] <= n) f = pii(inputSeq[i], i);
int flag = 1;
int cc = 0;
vector <int> vv;
if(f != pii(-1, -1)) {
flag = 0;
for(int i=0;i<n;i++) {
int exp = (i - f.Se) + f.Fi;
if(exp > n) exp -= n;
if(exp <= 0) exp += n;
if(inputSeq[i] <= n && inputSeq[i] != exp) return 0;
if(inputSeq[i] > n) ++cc, vv.pb(inputSeq[i]);
}
}
else {
cc = n;
rep(i, n) vv.pb(inputSeq[i]);
}
ll ans = 1;
if(flag) ans = n;
int pre = n;
sort(all(vv));
for(int e : vv) {
ans = ans * pw(cc, e - pre - 1, MOD) % MOD;
--cc;
pre = e;
}
return (int)ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:104:9: warning: unused variable 'L' [-Wunused-variable]
int L = *max_element(inputSeq, inputSeq + n);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
6 |
Correct |
3 ms |
5344 KB |
Output is correct |
7 |
Correct |
13 ms |
5344 KB |
Output is correct |
8 |
Correct |
6 ms |
5344 KB |
Output is correct |
9 |
Correct |
3 ms |
5344 KB |
Output is correct |
10 |
Correct |
13 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
6 |
Correct |
3 ms |
5344 KB |
Output is correct |
7 |
Correct |
9 ms |
5344 KB |
Output is correct |
8 |
Correct |
9 ms |
5344 KB |
Output is correct |
9 |
Correct |
3 ms |
5344 KB |
Output is correct |
10 |
Correct |
9 ms |
5344 KB |
Output is correct |
11 |
Correct |
0 ms |
5344 KB |
Output is correct |
12 |
Correct |
0 ms |
5344 KB |
Output is correct |
13 |
Correct |
6 ms |
5344 KB |
Output is correct |
14 |
Correct |
0 ms |
5344 KB |
Output is correct |
15 |
Correct |
13 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
6 |
Correct |
0 ms |
5344 KB |
Output is correct |
7 |
Correct |
0 ms |
5344 KB |
Output is correct |
8 |
Correct |
0 ms |
5344 KB |
Output is correct |
9 |
Correct |
0 ms |
5344 KB |
Output is correct |
10 |
Correct |
0 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
6 |
Correct |
0 ms |
5344 KB |
Output is correct |
7 |
Correct |
0 ms |
5344 KB |
Output is correct |
8 |
Correct |
0 ms |
5344 KB |
Output is correct |
9 |
Correct |
0 ms |
5344 KB |
Output is correct |
10 |
Correct |
0 ms |
5344 KB |
Output is correct |
11 |
Correct |
19 ms |
5344 KB |
Output is correct |
12 |
Correct |
9 ms |
5344 KB |
Output is correct |
13 |
Correct |
13 ms |
5344 KB |
Output is correct |
14 |
Correct |
9 ms |
5344 KB |
Output is correct |
15 |
Correct |
23 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
6 |
Correct |
0 ms |
5344 KB |
Output is correct |
7 |
Correct |
0 ms |
5344 KB |
Output is correct |
8 |
Correct |
0 ms |
5344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
6 |
Correct |
0 ms |
5344 KB |
Output is correct |
7 |
Correct |
0 ms |
5344 KB |
Output is correct |
8 |
Correct |
0 ms |
5344 KB |
Output is correct |
9 |
Correct |
23 ms |
6448 KB |
Output is correct |
10 |
Correct |
19 ms |
6196 KB |
Output is correct |
11 |
Correct |
6 ms |
5684 KB |
Output is correct |
12 |
Correct |
3 ms |
5684 KB |
Output is correct |
13 |
Correct |
0 ms |
5484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5344 KB |
Output is correct |
2 |
Correct |
0 ms |
5344 KB |
Output is correct |
3 |
Correct |
0 ms |
5344 KB |
Output is correct |
4 |
Correct |
0 ms |
5344 KB |
Output is correct |
5 |
Correct |
0 ms |
5344 KB |
Output is correct |
6 |
Correct |
0 ms |
5344 KB |
Output is correct |
7 |
Correct |
0 ms |
5344 KB |
Output is correct |
8 |
Correct |
0 ms |
5344 KB |
Output is correct |
9 |
Correct |
23 ms |
6448 KB |
Output is correct |
10 |
Correct |
16 ms |
6196 KB |
Output is correct |
11 |
Correct |
3 ms |
5684 KB |
Output is correct |
12 |
Correct |
6 ms |
5684 KB |
Output is correct |
13 |
Correct |
3 ms |
5484 KB |
Output is correct |
14 |
Correct |
33 ms |
6964 KB |
Output is correct |
15 |
Correct |
39 ms |
6964 KB |
Output is correct |
16 |
Correct |
6 ms |
5684 KB |
Output is correct |
17 |
Correct |
23 ms |
6196 KB |
Output is correct |
18 |
Correct |
13 ms |
6196 KB |
Output is correct |