# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
297800 | juckter | Gondola (IOI14_gondola) | C++14 | 34 ms | 4728 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXV = 3e5 + 10;
const ll MOD = 1e9 + 7;
ll mpow(ll b, ll e) {
ll res = 1;
for(ll k = 1; k <= b; k *= 2) {
if(k & e) res = (res * b) % MOD;
b = (b * b) % MOD;
}
return res;
}
int valid(int n, int inputSeq[]) {
set<int> seen;
int rot = -1;
for(int i = 0; i < n; i++) {
if(seen.count(inputSeq[i]))
return 0;
seen.insert(inputSeq[i]);
if(inputSeq[i] <= n) {
int nr = (inputSeq[i] - i + n) % n;
if(rot != -1 && rot != nr)
return 0;
rot = nr;
}
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
if(*min_element(gondolaSeq, gondolaSeq + n) <= n) {
int rot;
for(int i = 0; i < n; i++)
if(gondolaSeq[i] <= n)
rot = (gondolaSeq[i] - i + n - 1) % n;
rotate(gondolaSeq, gondolaSeq + (n - rot) % n, gondolaSeq + n);
}
//for(int i = 0; i < n; i++)
// cerr << gondolaSeq[i] << " ";
//cerr << '\n';
int mx = *max_element(gondolaSeq, gondolaSeq + n);
int mpos = -1;
vector<int> pos(300000);
for(int i = 0; i < n; i++) {
pos[gondolaSeq[i]] = i + 1;
if(gondolaSeq[i] == mx)
mpos = i;
}
int st = 0, len = mx - n;
int pv = mpos + 1;
for(int i = n + 1; i <= mx; i++) {
if(i != mx && pos[i])
replacementSeq[st++] = pos[i];
else {
replacementSeq[st++] = pv;
pv = i;
}
}
return len;
}
//----------------------
int countReplacement(int n, int inputSeq[]) {
if(!valid(n, inputSeq))
return 0;
ll cntBig = 0;
vector<ll> bigs;
for(int i = 0; i < n; i++)
if(inputSeq[i] > n) {
cntBig++;
bigs.push_back(inputSeq[i]);
}
ll cntSmall = n - cntBig;
bigs.push_back(n);
sort(bigs.begin(), bigs.end());
ll ways = 1, cur = cntBig;
for(int i = 1; i < bigs.size(); i++)
ways = (ways * mpow(cur, bigs[i] - bigs[i - 1] - 1)) % MOD;
if(cntBig == n)
ways = (ways * (ll)n) % MOD;
return ways;
}
컴파일 시 표준 에러 (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... |