This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<algorithm>
#include "gondola.h"
#define DIM 100005
#define mod 1000000009
using namespace std;
static int w[DIM];
static pair<int, int> p[DIM];
static int mult(int x, int e){
if(e == 0){
return 1;
}
else{
int a = mult(x, e / 2);
if(e % 2 == 0){
return a * 1LL * a % mod;
}
else{
return a * 1LL * a % mod * x % mod;
}
}
}
int valid(int n, int v[]){
int i, j, x;
for(i = 0; i < n; i++){
w[i] = v[i];
}
sort(w, w + n);
for(i = 1; i < n; i++){
if(w[i] == w[i - 1]){
return 0;
}
}
for(i = 0; i < n; i++){
if(v[i] <= n){
x = v[i];
for(j = i; j < n; j++){
if(v[j] <= n && v[j] != x){
return 0;
}
x++;
if(x == n + 1){
x = 1;
}
}
for(j = 0; j < i; j++){
if(v[j] <= n && v[j] != x){
return 0;
}
x++;
if(x == n + 1){
x = 1;
}
}
break;
}
}
return 1;
}
int replacement(int n, int v[], int r[]){
int i, nr, x, y, k, j;
for(i = 0; i < n; i++){
if(v[i] <= n){
x = i;
y = v[x];
break;
}
}
if(i == n){
x = 0;
y = 1;
}
nr = k = 0;
for(i = x; i < n; i++){
if(v[i] != y){
p[++nr] = make_pair(v[i], y);
}
y++;
if(y == n + 1){
y = 1;
}
}
for(i = 0; i < x; i++){
if(v[i] != y){
p[++nr] = make_pair(v[i], y);
}
y++;
if(y == n + 1){
y = 1;
}
}
sort(p + 1, p + nr + 1);
p[0].first = n;
for(i = 1; i <= nr; i++){
r[k++] = p[i].second;
for(j = p[i - 1].first + 1; j < p[i].first; j++){
r[k++] = j;
}
}
return k;
}
int countReplacement(int n, int v[]){
if( valid(n, v) == 0){
return 0;
}
int i, ok, sol, nr;
nr = ok = 0;
for(i = 1; i <= n; i++){
if(v[i] > n){
w[++nr] = v[i];
}
else{
ok = 1;
}
}
sort(w + 1, w + nr + 1);
sol = 1;
w[0] = n;
for(i = 1; i <= nr; i++){
sol = sol * 1LL * mult(nr - i + 1, w[i] - w[i - 1] - 1) % mod;
}
if(ok == 0){
sol = sol * 1LL * n % mod;
}
return sol;
}
Compilation message (stderr)
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:81:10: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
81 | y++;
| ~^~
gondola.cpp:86:18: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
86 | for(i = 0; i < x; i++){
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |