# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
363544 | silverfish | Gondola (IOI14_gondola) | C++14 | 51 ms | 4844 KiB |
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 <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define ar array
#define pb push_back
int valid(int n, int a[]){
bool ok = 1, first = 1;
int diff = -1;
map<int, int> cnt;
for(int i = 0; i < n; ++i){
if(cnt[a[i]]) ok = 0;
++cnt[a[i]];
if(a[i] <= n){
if(first) {
diff = (a[i]-(i+1)+n)%n;
first = 0;
continue;
}
//cerr << i+1 << ' ' << (n+a[i]-diff)%n << endl;
if(i != (a[i]-diff-1+n)%n) ok = 0;
}
}
return ok;
}
//----------------------
int replacement(int n, int a[], int r[]){
bool ok = 1, first = 1;
int diff = -1;
vector<ar<int,2>> replaced;
for(int i = 0; i < n; ++i){
if(a[i] <= n){
diff = (a[i]-(i+1)+n)%n;
}else{
replaced.pb({a[i], i});
}
}
if(diff == -1) diff = 0;
sort(replaced.begin(), replaced.end());
int cur = 0, curnum = n+1;
for(auto x : replaced){
int val = x[0], pos = x[1];
int orig = (pos+1 + diff + n) % n;
r[cur++] = orig;
for(; curnum < x[0]; ++curnum) r[cur++] = curnum;
}
return cur;
}
//----------------------
int countReplacement(int n, int a[]){
if(!valid(n, a)) return 0;
return -1;
}
Compilation message (stderr)
# | 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... |