# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
239912 |
2020-06-17T13:42:18 Z |
abacaba |
Gondola (IOI14_gondola) |
C++14 |
|
97 ms |
6392 KB |
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include "gondola.h"
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline T range(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
inline void setin(string s) {
freopen(s.c_str(), "r", stdin);
}
inline void setout(string s) {
freopen(s.c_str(), "w", stdout);
}
template <typename T> void Min(T &a, T b) {
a = min(a, b);
}
template <typename T> void Max(T &a, T b) {
a = max(a, b);
}
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 9;
const int N = 3e5 + 15;
inline int add(int a, int b) {
a = (a + b) % mod;
return (a + mod) % mod;
}
inline int mt(int a, int b) {
return 1ll * a * b % mod;
}
inline int binpow(int n, int k) {
int res = 1;
while(k) {
if(k & 1)
res = mt(res, n);
n = mt(n, n);
k >>= 1;
}
return res;
}
int a[N], b[N];
int valid(int n, int inputSeq[]) {
map <int, int> cnt = {};
for(int i = 0; i < n; ++i) {
a[i] = inputSeq[i] - 1;
if(cnt[a[i]])
return 0;
++cnt[a[i]];
}
for(int i = 0; i < n; ++i) {
if(a[i] < n) {
int cnt = a[i];
for(int j = i; j < n; ++j, cnt = (cnt + 1) % n)
b[j] = cnt;
for(int j = 0; j < i; ++j, cnt = (cnt + 1) % n)
b[j] = cnt;
break;
}
}
for(int i = 0; i < n; ++i)
if(a[i] < n && b[i] < n && a[i] != b[i])
return 0;
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
for(int i = 0; i < n; ++i)
b[i] = i;
for(int i = 0; i < n; ++i)
a[i] = gondolaSeq[i] - 1;
int cnt = n - 1;
for(int i = 0; i < n; ++i) {
if(a[i] < n) {
int cnt = a[i];
for(int j = i; j < n; ++j, cnt = (cnt + 1) % n)
b[j] = cnt;
for(int j = 0; j < i; ++j, cnt = (cnt + 1) % n)
b[j] = cnt;
break;
}
}
vector <pii> now = {};
for(int i = 0; i < n; ++i)
if(a[i] >= n)
now.pb({a[i], i});
sort(now.begin(), now.end());
int sz = 0;
for(int k = 0; k < now.size(); ++k) {
int val = now[k].f, i = now[k].se;
int &cur = b[i];
while(cnt < val) {
replacementSeq[sz++] = cur + 1;
cur = ++cnt;
}
}
return sz;
}
int countReplacement(int n, int inputSeq[]) {
if(!valid(n, inputSeq))
return 0;
for(int i = 0; i < n; ++i)
a[i] = inputSeq[i] - 1;
vector <int> now = {};
for(int i = 0; i < n; ++i)
if(a[i] >= n)
now.pb(a[i]);
now.pb(n-1);
sort(now.begin(), now.end());
int res = 1;
for(int i = 1; i < now.size(); ++i)
res = mt(res, binpow(now.size() - i, now[i] - now[i-1] - 1));
if(now.size() == n + 1) {
res = mt(res, n);
}
return res;
}
Compilation message
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:134:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k = 0; k < now.size(); ++k) {
~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:157:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 1; i < now.size(); ++i)
~~^~~~~~~~~~~~
gondola.cpp:159:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(now.size() == n + 1) {
~~~~~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
19 ms |
2560 KB |
Output is correct |
7 |
Correct |
18 ms |
768 KB |
Output is correct |
8 |
Correct |
33 ms |
4472 KB |
Output is correct |
9 |
Correct |
13 ms |
1664 KB |
Output is correct |
10 |
Correct |
41 ms |
5240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
19 ms |
2560 KB |
Output is correct |
7 |
Correct |
18 ms |
768 KB |
Output is correct |
8 |
Correct |
37 ms |
4476 KB |
Output is correct |
9 |
Correct |
16 ms |
1664 KB |
Output is correct |
10 |
Correct |
44 ms |
5240 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
25 ms |
2432 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
63 ms |
5368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
16 ms |
1280 KB |
Output is correct |
12 |
Correct |
18 ms |
1408 KB |
Output is correct |
13 |
Correct |
21 ms |
1552 KB |
Output is correct |
14 |
Correct |
15 ms |
1280 KB |
Output is correct |
15 |
Correct |
25 ms |
2424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
53 ms |
4600 KB |
Output is correct |
10 |
Correct |
46 ms |
4040 KB |
Output is correct |
11 |
Correct |
18 ms |
1664 KB |
Output is correct |
12 |
Correct |
22 ms |
1920 KB |
Output is correct |
13 |
Correct |
8 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
384 KB |
Output is correct |
9 |
Correct |
66 ms |
4600 KB |
Output is correct |
10 |
Correct |
51 ms |
3960 KB |
Output is correct |
11 |
Correct |
18 ms |
1664 KB |
Output is correct |
12 |
Correct |
22 ms |
1920 KB |
Output is correct |
13 |
Correct |
8 ms |
640 KB |
Output is correct |
14 |
Correct |
70 ms |
5752 KB |
Output is correct |
15 |
Correct |
97 ms |
6392 KB |
Output is correct |
16 |
Correct |
16 ms |
1536 KB |
Output is correct |
17 |
Correct |
58 ms |
4472 KB |
Output is correct |
18 |
Correct |
30 ms |
2680 KB |
Output is correct |