# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
640570 |
2022-09-15T01:06:50 Z |
ymm |
Gondola (IOI14_gondola) |
C++17 |
|
53 ms |
6024 KB |
#include "gondola.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
int valid(int n, int inputSeq[])
{
bool flg = 0;
int off;
set<int> s;
Loop (i,0,n) {
if (s.count(inputSeq[i]))
return 0;
s.insert(inputSeq[i]);
if (inputSeq[i] <= n) {
if (flg && (inputSeq[i]-1 - i + n) % n != off)
return 0;
if (!flg) {
flg = 1;
off = (inputSeq[i]-1 - i + n) % n;
}
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int off = 0;
Loop (i,0,n)
if (gondolaSeq[i] <= n)
off = (gondolaSeq[i]-1 - i + n) % n;
vector<pii> a;
Loop (i,0,n)
a.push_back({gondolaSeq[i]-1, i});
sort(a.begin(), a.end());
int ans = 0;
int nxt = n;
Loop (i,0,n) {
if (a[i].first < n)
continue;
int lst = (a[i].second + off) % n;
while (nxt <= a[i].first) {
replacementSeq[ans++] = lst+1;
lst = nxt;
nxt++;
}
}
return ans;
}
//----------------------
const int mod = 1e9 + 9;
ll mpow(ll x, ll y) {ll ans=1;while(y){ans=y&1?ans*x%mod:ans;x=x*x%mod;y>>=1;}return ans;}
int countReplacement(int n, int inputSeq[])
{
if (!valid(n, inputSeq))
return 0;
int off = 0;
Loop (i,0,n)
if (inputSeq[i] <= n)
off = (inputSeq[i]-1 - i + n) % n;
vector<pii> a;
Loop (i,0,n)
a.push_back({inputSeq[i]-1, i});
sort(a.begin(), a.end());
ll ans = 1;
int nxt = n;
int cnt = n;
Loop (i,0,n) {
--cnt;
if (a[i].first < n)
continue;
ans = ans * mpow(cnt + 1, a[i].first - nxt) % mod;
nxt = a[i].first + 1;
}
if (a[0].first >= n)
ans = ans*n % mod;
return ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:68:6: warning: variable 'off' set but not used [-Wunused-but-set-variable]
68 | int off = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
12 ms |
2096 KB |
Output is correct |
7 |
Correct |
7 ms |
596 KB |
Output is correct |
8 |
Correct |
21 ms |
3936 KB |
Output is correct |
9 |
Correct |
8 ms |
1472 KB |
Output is correct |
10 |
Correct |
30 ms |
4524 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
12 ms |
2132 KB |
Output is correct |
7 |
Correct |
8 ms |
596 KB |
Output is correct |
8 |
Correct |
21 ms |
3912 KB |
Output is correct |
9 |
Correct |
7 ms |
1368 KB |
Output is correct |
10 |
Correct |
29 ms |
4420 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
7 ms |
596 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 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 |
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 |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
300 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 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
16 ms |
1740 KB |
Output is correct |
12 |
Correct |
14 ms |
1740 KB |
Output is correct |
13 |
Correct |
12 ms |
1212 KB |
Output is correct |
14 |
Correct |
9 ms |
1740 KB |
Output is correct |
15 |
Correct |
16 ms |
2204 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 |
# |
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 |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
308 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 |
212 KB |
Output is correct |
9 |
Correct |
39 ms |
4508 KB |
Output is correct |
10 |
Correct |
38 ms |
3752 KB |
Output is correct |
11 |
Correct |
10 ms |
1548 KB |
Output is correct |
12 |
Correct |
13 ms |
1832 KB |
Output is correct |
13 |
Correct |
3 ms |
664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
4384 KB |
Output is correct |
10 |
Correct |
30 ms |
3764 KB |
Output is correct |
11 |
Correct |
10 ms |
1540 KB |
Output is correct |
12 |
Correct |
13 ms |
1816 KB |
Output is correct |
13 |
Correct |
3 ms |
620 KB |
Output is correct |
14 |
Correct |
46 ms |
5324 KB |
Output is correct |
15 |
Correct |
53 ms |
6024 KB |
Output is correct |
16 |
Correct |
9 ms |
1364 KB |
Output is correct |
17 |
Correct |
34 ms |
4160 KB |
Output is correct |
18 |
Correct |
18 ms |
2772 KB |
Output is correct |