# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
589241 |
2022-07-04T10:54:58 Z |
fuad27 |
Gondola (IOI14_gondola) |
C++17 |
|
22 ms |
3112 KB |
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define prev(i) ((i-1+n)%n)
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const ll mod = 1e9+9;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define rep(i, a, b) for(int i = (a);i<(b);i++)
#define repn(i, a, b) for(int i = (a);i>=(b);i--)
#define ss second
#define ff first
#define mkp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
ll binpow(ll a, ll b) {
a%=mod;
ll ans = 1;
while(b) {
if(b&1ll) {
ans=(ans*a)%mod;
}
a=(a*a)%mod;
b>>=1ll;
}
return ans;
}
int valid(int n, int a[])
{
int cnt = a[0]-1;
for(int i = 1;i<n-cnt;i++) {
if(a[i] != a[i-1]+1) {
return 0;
}
}
for(int i = n-cnt+1;i<n;i++) {
if(a[i]!=a[i-1]+1)return 0;
}
if(cnt==0)return 1;
if(a[0] != a[n-1]+1)return 0;
return 1;
return -1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int cnt=0;
for(int i = 0;i<n;i++) {
if(gondolaSeq[i]>n)cnt++;
}
if(cnt == 0)return 0;
else if(cnt == n) {
vector<pair<int,int>> res;
res.push_back(mkp(n,n));
for(int i = 0;i<n;i++) {
res.push_back(mkp(gondolaSeq[i], i+1));
}
sort(res.begin(), res.end());
vector<int> ans;
for(int i=1;i<(int)res.size();i++) {
ans.push_back(res[i].second);
for(int j = res[i-1].first;j<res[i].first-1;j++) {
ans.push_back(j+1);
}
}
for(int i=0;i<(int)ans.size();i++) {
replacementSeq[i]=ans[i];
}
return (int)ans.size();
}
else {
vector<pair<int,int>> res;
res.push_back(make_pair(n,n));
for(int i = 0;i<n;i++) {
if(gondolaSeq[i] > n and gondolaSeq[prev(i)]<=n) {
int tmp = gondolaSeq[i];
gondolaSeq[i] = (gondolaSeq[prev(i)]%n)+1;
res.push_back(make_pair(tmp, gondolaSeq[i]));
}
}
for(int i = 0;i<n;i++) {
if(gondolaSeq[i] > n and gondolaSeq[prev(i)]<=n) {
int tmp = gondolaSeq[i];
gondolaSeq[i] = (gondolaSeq[prev(i)]%n)+1;
res.push_back(make_pair(tmp, gondolaSeq[i]));
}
}
sort(res.begin(), res.end());
vector<int> ans;
for(int i=1;i<(int)res.size();i++) {
ans.push_back(res[i].second);
for(int j = res[i-1].first;j<res[i].first-1;j++) {
ans.push_back(j+1);
}
}
for(int i=0;i<(int)ans.size();i++) {
replacementSeq[i]=ans[i];
}
return (int)ans.size();
}
return 0;
}
int countReplacement(int n, int inputSeq[])
{
vll diff;
int gondolaSeq[n];
bool check=1;
for(int i = 0;i<n;i++) {
if(inputSeq[i]<=n)check=0;
}
rep(i, 0, n)gondolaSeq[i]=inputSeq[i];
vector<pair<ll,ll>> res;
res.push_back(make_pair(n,n));
for(int i = 0;i<n;i++) {
if(gondolaSeq[i] > n and gondolaSeq[prev(i)]<=n) {
ll tmp = gondolaSeq[i];
gondolaSeq[i] = (gondolaSeq[prev(i)]%n)+1;
}
}
for(int i = 0;i<n;i++) {
if(gondolaSeq[i] > n and gondolaSeq[prev(i)]<=n) {
ll tmp = gondolaSeq[i];
gondolaSeq[i] = (gondolaSeq[prev(i)]%n)+1;
}
}
ll ans = 1;
diff.pb(n);
rep(i, 0, n) {
if(inputSeq[i] > n)diff.pb(inputSeq[i]);
}
sort(all(diff));
rep(i, 1, diff.size()) {
ll d = diff[i]-diff[i-1]-1;
if(d>0)ans=(ans*binpow(diff.size()-i, d))%mod;
}
if(!check and !valid(n, gondolaSeq))return 0;
if(check) {
ll fc=n;
ans=(ans*fc)%mod;
}
return ans;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:123:7: warning: unused variable 'tmp' [-Wunused-variable]
123 | ll tmp = gondolaSeq[i];
| ^~~
gondola.cpp:129:7: warning: unused variable 'tmp' [-Wunused-variable]
129 | ll tmp = gondolaSeq[i];
| ^~~
gondola.cpp:13:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | #define rep(i, a, b) for(int i = (a);i<(b);i++)
| ^
gondola.cpp:139:2: note: in expansion of macro 'rep'
139 | rep(i, 1, diff.size()) {
| ^~~
# |
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 |
1 ms |
304 KB |
Output is correct |
5 |
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 |
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 |
3 ms |
596 KB |
Output is correct |
7 |
Correct |
7 ms |
760 KB |
Output is correct |
8 |
Correct |
7 ms |
700 KB |
Output is correct |
9 |
Correct |
3 ms |
480 KB |
Output is correct |
10 |
Correct |
8 ms |
696 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
468 KB |
Output is correct |
7 |
Correct |
9 ms |
784 KB |
Output is correct |
8 |
Correct |
7 ms |
780 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
9 ms |
724 KB |
Output is correct |
11 |
Correct |
1 ms |
304 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
4 ms |
524 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
9 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
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 |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 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 |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
0 ms |
212 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 |
11 |
Correct |
9 ms |
684 KB |
Output is correct |
12 |
Correct |
10 ms |
684 KB |
Output is correct |
13 |
Correct |
19 ms |
1448 KB |
Output is correct |
14 |
Correct |
7 ms |
804 KB |
Output is correct |
15 |
Correct |
20 ms |
2312 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 |
# |
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 |
1 ms |
308 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
17 ms |
1648 KB |
Output is correct |
10 |
Correct |
12 ms |
1580 KB |
Output is correct |
11 |
Correct |
5 ms |
960 KB |
Output is correct |
12 |
Correct |
6 ms |
948 KB |
Output is correct |
13 |
Correct |
2 ms |
448 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 |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
18 ms |
1564 KB |
Output is correct |
10 |
Correct |
17 ms |
1548 KB |
Output is correct |
11 |
Correct |
5 ms |
980 KB |
Output is correct |
12 |
Correct |
6 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
468 KB |
Output is correct |
14 |
Correct |
18 ms |
2892 KB |
Output is correct |
15 |
Correct |
22 ms |
3112 KB |
Output is correct |
16 |
Correct |
7 ms |
980 KB |
Output is correct |
17 |
Correct |
15 ms |
1968 KB |
Output is correct |
18 |
Correct |
13 ms |
1472 KB |
Output is correct |