#include "gondola.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
using namespace std;
typedef long long i64;
typedef pair<int, int> pii;
const int MOD = 1000000009;
int valid(int n, int arr[]){
vector<pii> rep;
vector<pii> v;
for (int i = 0; i < n; i++){
arr[i]--;
// cout << arr[i] << ' ';
if (arr[i] >= n){
rep.pb(mp(arr[i] - n, i) );
}
else v.pb(mp(i, arr[i]) );
arr[i]++;
}
if(v.size() > 0){
int diff = v[0].yy - v[0].xx;
int end = (n - 1) - diff;
int diff2 = diff - n;
// cout << diff2;
int vn = v.size();
for (int i = 0; i < vn; i++){
if (v[i].xx <= end){
if (v[i].yy - v[i].xx != diff) return 0;
}
else{
if (v[i].yy - v[i].xx != diff2) return 0;
}
}
}
sort(rep.begin(), rep.end());
for(int i = 0; i + 1 < rep.size(); i++){
if(rep[i].xx == rep[i + 1].xx) return 0;
}
// cout << "veve";
return 1;
}
//----------------------
int replacement(int n, int arr[], int repl[]){
vector<pii> rep;
vector<pii> v;
for (int i = 0; i < n; i++){
arr[i]--;
if (arr[i] >= n){
rep.pb( mp(arr[i] - n, i) );
}
else {
v.pb( mp(i, arr[i]) );
}
arr[i]++;
}
sort(rep.begin(), rep.end() );
if(v.size() > 0){
int diff = v[0].yy - v[0].xx;
int end = (n - 1) - diff;
int diff2 = diff - n;
int repsz = 0;
int last = 0;
for(int i = 0; i < rep.size(); i++){
for(int j = last; j <= rep[i].xx; j++){
int tmp;
if(j == last){
if(rep[i].yy <= end) tmp = rep[i].yy + diff;
else tmp = rep[i].yy + diff2;
}
else{
tmp = n + j - 1;
}
tmp++;
repl[j] = tmp;
repsz++;
}
last = rep[i].xx + 1;
}
return repsz;
// cout << diff2;
}
else{ //wtf evdreegu neg ch bdggu nasss
int repsz = 0;
int last = 0;
for(int i = 0; i < rep.size(); i++){
for(int j = last; j <= rep[i].xx; j++){
int tmp;
if(j == last){
tmp = rep[i].yy;
}
else{
tmp = n + j - 1;
}
tmp++;
// cout << tmp << ' ';
repl[j] = tmp;
repsz++;
}
last = rep[i].xx + 1;
}
return repsz;
}
}
//----------------------
i64 pow2(i64 x, i64 zereg){
if(zereg == 0) return 1LL;
if(zereg == 1) return x;
if(zereg % 2 == 1) return (x * pow2(x, zereg - 1)) % MOD;
i64 tmp = pow2(x, zereg >> 1) % MOD;
return ((tmp * tmp) % MOD);
}
int countReplacement(int n, int arr[]){
if(!valid(n, arr)) return 0; //sha , T1
vector<int> rep;
i64 res = 1;
for (int i = 0; i < n; i++){
if(arr[i] > n) rep.pb(arr[i]);
}
if(rep.size() == n) res = rep.size(); //bugdeere evdreshas
if(rep.size() == 0) return 1; //yu ch evdreegue
int lst = n;
sort(rep.begin(), rep.end());
for (int i = 0; i < rep.size(); i++) {
res *= pow2((rep.size() - i) * 1LL, (rep[i] - lst - 1) * 1LL );
lst = rep[i];
res %= MOD;
}
return (int)res;
}
Compilation message
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:42:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i + 1 < rep.size(); i++){
~~~~~~^~~~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:70:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < rep.size(); i++){
~~^~~~~~~~~~~~
gondola.cpp:92:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < rep.size(); i++){
~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:127:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(rep.size() == n) res = rep.size(); //bugdeere evdreshas
~~~~~~~~~~~^~~~
gondola.cpp:131:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < rep.size(); i++) {
~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
7 ms |
1140 KB |
Output is correct |
7 |
Correct |
16 ms |
1904 KB |
Output is correct |
8 |
Correct |
13 ms |
1780 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
7 ms |
1776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 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 |
7 ms |
1140 KB |
Output is correct |
7 |
Correct |
15 ms |
1776 KB |
Output is correct |
8 |
Correct |
12 ms |
1776 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
14 ms |
1780 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
8 ms |
1140 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
16 ms |
1652 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 |
# |
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 |
380 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 |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 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 |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
13 ms |
1776 KB |
Output is correct |
12 |
Correct |
15 ms |
1772 KB |
Output is correct |
13 |
Correct |
17 ms |
1276 KB |
Output is correct |
14 |
Correct |
13 ms |
1764 KB |
Output is correct |
15 |
Correct |
23 ms |
2272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 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 |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
252 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 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 |
256 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 |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
25 ms |
1780 KB |
Output is correct |
10 |
Correct |
21 ms |
1760 KB |
Output is correct |
11 |
Correct |
10 ms |
888 KB |
Output is correct |
12 |
Correct |
11 ms |
1016 KB |
Output is correct |
13 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
252 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
380 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 |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
27 ms |
1780 KB |
Output is correct |
10 |
Correct |
20 ms |
1780 KB |
Output is correct |
11 |
Correct |
10 ms |
888 KB |
Output is correct |
12 |
Correct |
12 ms |
1020 KB |
Output is correct |
13 |
Correct |
4 ms |
504 KB |
Output is correct |
14 |
Correct |
35 ms |
2672 KB |
Output is correct |
15 |
Correct |
39 ms |
2800 KB |
Output is correct |
16 |
Correct |
9 ms |
884 KB |
Output is correct |
17 |
Correct |
26 ms |
1908 KB |
Output is correct |
18 |
Correct |
16 ms |
1400 KB |
Output is correct |