# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1034739 | ArthuroWich | 곤돌라 (IOI14_gondola) | C++17 | 30 ms | 5864 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
int valid(int n, int gondolaSeq[]) {
int mi = INT_MAX, ind = -1;
set<int> c;
for (int i = 0; i < n; i++) {
c.insert(gondolaSeq[i]);
if (mi > gondolaSeq[i]) {
mi = gondolaSeq[i];
ind = i;
}
}
if (c.size() < n) {
return 0;
}
if (mi > n) {
return 1;
}
ind -= (mi-1);
ind += n;
ind %= n;
vector<int> a;
for (int i = ind; i < n; i++) {
a.push_back(gondolaSeq[i]);
}
for (int i = 0; i < ind; i++) {
a.push_back(gondolaSeq[i]);
}
for (int i = 0; i < n; i++) {
if (a[i] <= n && a[i] != i+1) {
return 0;
}
}
return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
int mi = INT_MAX, ind = -1, ma = 0;
set<int> c;
for (int i = 0; i < n; i++) {
ma = max(ma, gondolaSeq[i]);
c.insert(gondolaSeq[i]);
if (mi > gondolaSeq[i]) {
mi = gondolaSeq[i];
ind = i;
}
}
vector<pair<int, int>> num;
if (ma <= n) {
return 0;
}
if (mi > n) {
for (int i = 0; i < n; i++) {
num.push_back({gondolaSeq[i], i+1});
}
int l = 0;
sort(num.begin(), num.end());
l = num.back().first-n;
for (int i = 0; i < l; i++) {
replacementSeq[i] = num.back().second;
}
for (int i = 0; i < num.size(); i++) {
replacementSeq[num[i].first-n-1] = num[i].second;
}
vector<int> ans(n+1, 0);
for (int i = 1; i <= n; i++) {
ans[i] = i;
}
for (int i = 0; i < l; i++) {
int v = replacementSeq[i];
replacementSeq[i] = ans[replacementSeq[i]];
ans[v] = n+i+1;
}
return l;
} else {
ind -= (mi-1);
ind += n;
ind %= n;
vector<int> a;
for (int i = ind; i < n; i++) {
a.push_back(gondolaSeq[i]);
}
for (int i = 0; i < ind; i++) {
a.push_back(gondolaSeq[i]);
}
for (int i = 0; i < n; i++) {
if (a[i] > n) {
num.push_back({a[i], i+1});
}
}
int l = 0;
sort(num.begin(), num.end());
l = num.back().first-n;
for (int i = 0; i < l; i++) {
replacementSeq[i] = num.back().second;
}
for (int i = 0; i < num.size(); i++) {
replacementSeq[num[i].first-n-1] = num[i].second;
}
vector<int> ans(n+1, 0);
for (int i = 1; i <= n; i++) {
ans[i] = i;
}
for (int i = 0; i < l; i++) {
int v = replacementSeq[i];
replacementSeq[i] = ans[replacementSeq[i]];
ans[v] = n+i+1;
}
return l;
}
}
int countReplacement(int n, int gondolaSeq[]) {
if (!valid(n, gondolaSeq)) {
return 0;
}
vector<int> num;
long long int ans = 1, mod = 1000000009;
for (int i = 0; i < n; i++) {
if (gondolaSeq[i] > n) {
num.push_back(gondolaSeq[i]);
}
}
if (num.size() == 0) {
return ans;
}
sort(num.rbegin(), num.rend());
int l = n+1;
while(num.size() > 1) {
if (num.back() == l) {
num.pop_back();
l++;
} else {
ans *= (long long int) num.size();
ans %= mod;
l++;
}
}
return ans;
}
컴파일 시 표준 에러 (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... |