# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
131380 |
2019-07-17T05:47:52 Z |
MAMBA |
Gondola (IOI14_gondola) |
C++17 |
|
77 ms |
6024 KB |
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j , k) for(int i = j; i < (int) k; i++)
typedef vector<int> vi;
const int N = 3e5 + 10;
int pos[N];
map<int , int> mp;
int valid(int n, int A[])
{
mp.clear();
rep(i , 0 , n) {
if (mp.count(A[i])) return 0;
mp[A[i]] = i;
}
int last = -1;
rep(i , 1 , n + 1)
if(mp.count(i)) {
if (!~last) {
last = i;
continue;
}
if ((i - last) != (mp[i] - mp[last] + n) % n)
return 0;
}
return 1;
}
//----------------------
int lo[N];
set<int> st;
int replacement(int n, int A[], int B[])
{
st.clear();
memset(pos , -1, sizeof(pos));
int mx = -1;
rep(i , 0 , n) {
pos[A[i]] = i;
mx = max(mx , A[i]);
}
bool flag = false;
rep(i , 1 , n + 1)
if (~pos[i]) {
rep(j , 1 , n + 1) {
lo[(pos[i] + j - i + n) % n] = j;
if(!~pos[j])
st.insert((pos[i] + j - i + n) % n);
}
flag = true;
break;
}
if (!flag)
rep(i , 1 , n + 1) {
lo[i - 1] = i;
st.insert(i - 1);
}
int L = 0;
rep(i , n + 1, mx + 1) {
if (~pos[i]) {
B[L++] = lo[pos[i]];
st.erase(pos[i]);
}
else {
int v = *st.begin();
B[L++] = lo[v];
lo[v] = i;
}
}
return L;
}
//----------------------
const int MOD = 1e9 + 9;
typedef long long ll;
ll po(ll a , ll b) { return b ? po(a * a % MOD, b >> 1) * (b & 1 ? a : 1) % MOD : 1; }
int countReplacement(int n, int A[])
{
if(!valid(n , A)) return 0;
ll res = 1;
int cnt = n;
int last = -1;
while (!mp.empty() && mp.begin()->first <= n) {
cnt--;
last = mp.begin()->first;
mp.erase(mp.begin());
}
if(last == -1) res = n;
last = n;
int pp;
while(!mp.empty()) {
int me = mp.begin()->first;
assert(me - last - 1 >= 0);
res = (res * po(cnt , me - last - 1)) % MOD;
last = me;
cnt--;
pp = mp.size();
mp.erase(mp.begin());
assert(pp != mp.size());
}
return res;
}
Compilation message
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from gondola.cpp:2:
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:125:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(pp != mp.size());
~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
30 ms |
2192 KB |
Output is correct |
7 |
Correct |
15 ms |
760 KB |
Output is correct |
8 |
Correct |
53 ms |
4088 KB |
Output is correct |
9 |
Correct |
17 ms |
1528 KB |
Output is correct |
10 |
Correct |
72 ms |
4632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
27 ms |
2344 KB |
Output is correct |
7 |
Correct |
13 ms |
632 KB |
Output is correct |
8 |
Correct |
52 ms |
3960 KB |
Output is correct |
9 |
Correct |
17 ms |
1528 KB |
Output is correct |
10 |
Correct |
70 ms |
4600 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
348 KB |
Output is correct |
13 |
Correct |
23 ms |
2040 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
59 ms |
4720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1532 KB |
Output is correct |
6 |
Correct |
3 ms |
1528 KB |
Output is correct |
7 |
Correct |
3 ms |
1528 KB |
Output is correct |
8 |
Correct |
3 ms |
1528 KB |
Output is correct |
9 |
Correct |
3 ms |
1528 KB |
Output is correct |
10 |
Correct |
3 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
2 |
Correct |
3 ms |
1528 KB |
Output is correct |
3 |
Correct |
3 ms |
1528 KB |
Output is correct |
4 |
Correct |
3 ms |
1528 KB |
Output is correct |
5 |
Correct |
3 ms |
1528 KB |
Output is correct |
6 |
Correct |
3 ms |
1528 KB |
Output is correct |
7 |
Correct |
3 ms |
1528 KB |
Output is correct |
8 |
Correct |
3 ms |
1528 KB |
Output is correct |
9 |
Correct |
3 ms |
1528 KB |
Output is correct |
10 |
Correct |
3 ms |
1528 KB |
Output is correct |
11 |
Correct |
14 ms |
2168 KB |
Output is correct |
12 |
Correct |
16 ms |
2168 KB |
Output is correct |
13 |
Correct |
33 ms |
3832 KB |
Output is correct |
14 |
Correct |
15 ms |
2168 KB |
Output is correct |
15 |
Correct |
32 ms |
4216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
276 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
58 ms |
4600 KB |
Output is correct |
10 |
Correct |
47 ms |
3832 KB |
Output is correct |
11 |
Correct |
16 ms |
1656 KB |
Output is correct |
12 |
Correct |
20 ms |
1912 KB |
Output is correct |
13 |
Correct |
6 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
61 ms |
4576 KB |
Output is correct |
10 |
Correct |
48 ms |
3840 KB |
Output is correct |
11 |
Correct |
16 ms |
1536 KB |
Output is correct |
12 |
Correct |
20 ms |
1912 KB |
Output is correct |
13 |
Correct |
6 ms |
760 KB |
Output is correct |
14 |
Correct |
74 ms |
5368 KB |
Output is correct |
15 |
Correct |
77 ms |
6024 KB |
Output is correct |
16 |
Correct |
13 ms |
1400 KB |
Output is correct |
17 |
Correct |
48 ms |
4216 KB |
Output is correct |
18 |
Correct |
27 ms |
2552 KB |
Output is correct |