#include "gondola.h"
#include <vector>
#include <algorithm>
#define MOD 1000000009
using namespace std;
int valid(int n, int inputSeq[])
{
/* for(int i = 0; i < n; i++)
printf("%d ", inputSeq[i]);
printf("\n");
*/
int bas = -1;
for (int i = 0; i < n; i++)
if(inputSeq[i] <= n) {
bas = i;
break;
}
int s = bas == -1 ? 1 : inputSeq[bas];
bas = bas == -1 ? 0 : bas;
//printf("Bas: %d, s:%d\n", bas, s);
int bayrak = 1;
for (int i = bas; i < n; i++, s++) {
if(s == n+1) s = 1;
if(inputSeq[i] != s && inputSeq[i] < n) {
bayrak = 0;
break;
}
}
for (int i = 0; i < bas; i++, s++) {
if(s == n+1) s = 1;
if(inputSeq[i] != s && inputSeq[i] < n) {
bayrak = 0;
break;
}
}
if(!bayrak) return 0;
vector<int> v (inputSeq, inputSeq+n);
sort(v.begin(), v.end());
for(int i = 1; i < n; i++)
if(v[i] == v[i-1]) {
bayrak = 0;
break;
}
return bayrak;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
return -2;
}
//----------------------
long long us(long long a, long long b) {
if(b == 1) return a;
if(b & 1) return (us(a, b>>1) * us(a, b>>1) * a) % MOD;
return (us(a, b>>1) * us(a, b>>1)) % MOD;
}
int countReplacement(int n, int inputSeq[])
{
vector<int> v;
for (int i = 0; i < n; i++)
if (inputSeq[i] > n) v.push_back(inputSeq[i]);
sort(v.begin(), v.end());
long long sonuc = 1;
if (v.size() == n) sonuc = n;
int onceki = n;
for(int i = 0; i < v.size(); i++) {
sonuc *= us(v.size()-i, v[i]-onceki);
sonuc %= MOD;
onceki = v[i];
}
return sonuc % MOD;
}
Compilation message
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:82:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (v.size() == n) sonuc = n;
^
gondola.cpp:85:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < v.size(); i++) {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3300 KB |
Output is correct |
2 |
Correct |
0 ms |
3300 KB |
Output is correct |
3 |
Correct |
0 ms |
3300 KB |
Output is correct |
4 |
Correct |
0 ms |
3300 KB |
Output is correct |
5 |
Correct |
0 ms |
3300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3300 KB |
Output is correct |
2 |
Correct |
0 ms |
3300 KB |
Output is correct |
3 |
Correct |
0 ms |
3300 KB |
Output is correct |
4 |
Correct |
0 ms |
3300 KB |
Output is correct |
5 |
Correct |
0 ms |
3300 KB |
Output is correct |
6 |
Correct |
9 ms |
3448 KB |
Output is correct |
7 |
Correct |
16 ms |
3300 KB |
Output is correct |
8 |
Correct |
9 ms |
3580 KB |
Output is correct |
9 |
Correct |
3 ms |
3464 KB |
Output is correct |
10 |
Correct |
29 ms |
3628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
3300 KB |
Output is correct |
2 |
Correct |
0 ms |
3300 KB |
Output is correct |
3 |
Correct |
0 ms |
3300 KB |
Output is correct |
4 |
Correct |
0 ms |
3300 KB |
Output is correct |
5 |
Correct |
0 ms |
3300 KB |
Output is correct |
6 |
Correct |
9 ms |
3448 KB |
Output is correct |
7 |
Correct |
9 ms |
3300 KB |
Output is correct |
8 |
Correct |
13 ms |
3580 KB |
Output is correct |
9 |
Correct |
3 ms |
3464 KB |
Output is correct |
10 |
Correct |
19 ms |
3628 KB |
Output is correct |
11 |
Correct |
0 ms |
3300 KB |
Output is correct |
12 |
Incorrect |
0 ms |
3300 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3300 KB |
Integer -2 violates the range [0, 350000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3300 KB |
Integer -2 violates the range [0, 350000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3300 KB |
Integer -2 violates the range [0, 350000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
3300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |