# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
316958 | VROOM_VARUN | 곤돌라 (IOI14_gondola) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
ID: varunra2
LANG: C++
TASK: gondola
*/
#include<bits/stdc++.h>
#include "gondola.h"
using namespace std;
#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif
#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000009
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second
const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions
int n;
bool good(int val) {
return val >= 1 and val <= n;
}
VI get(int *vals) {
VI ret;
for(int i = 0; i < n; i++) {
if(good(vals[i])) ret.PB(i);
}
return ret;
}
VI brokeget(int *vals) {
VI ret;
}
bool distinct(int *inputSeq) {
MPII mp;
for(int i = 0; i < n; i++) {
mp[inputSeq[i]]++;
if(mp[inputSeq[i]] >= 2) return false;
}
return true;
}
bool valid(int N, int *inputSeq) {
n = N;
VI inds = get(inputSeq);
if(!distinct(inputSeq)) return false;
if(sz(inds) == 0) return true;
for(int i = inds[0], val = inputSeq[inds[0]], cnt = 0; cnt < n; cnt++, val = val%n + 1, i = (i + 1)%n) {
if(!good(inputSeq[i])) continue;
if(inputSeq[i] != val) return false;
}
return true;
}
VII genVals(int n, int *gondolaSeq) {
VII vals;
for(int i = 0; i < n; i++) {
if(!good(gondolaSeq[i])) {
vals.PB(MP(gondolaSeq[i], i));
}
}
return vals;
}
int replacement(int N, int *gondolaSeq, int *replacementSeq) {
assert(valid(n, gondolaSeq));
n = N;
VII vals = genVals(n, gondolaSeq);
if(vals.empty()) return 0;
sort(all(vals));
int lst = n + 1;
int cnt = 0;
for(int i = 0; i < sz(vals); i++) {
while(gondolaSeq[vals[i].y] != vals[i].x) {
replacementSeq[cnt] = gondolaSeq[vals[i].y];
gondolaSeq[vals[i].y] = lst;
lst++;
cnt++;
}
}
return cnt;
}
ll binpow(ll a, ll b) {
if(b == 0) return 1ll;
if(b == 1) return a;
ll mid = binpow(a, b/2);
ll mult = (mid * mid) % MOD;
if(b%2) return (mult * a) % MOD;
return mult;
}
int countReplacement(int N, int *inputSeq) {
n = N;
if(!valid(n, inputSeq)) return 0;
ll ret = 1;
VII vals = genVals(n, inputSeq);
if(vals.empty()) return 1;
sort(all(vals));
int lst = n;
int cnt = sz(vals);
if(cnt == n) ret *= n;
for(int i = 0; i < sz(vals); i++) {
int len = vals[i].x - lst - 1;
ret *= binpow(cnt, len);
ret %= MOD;
}
return ret;
}
// int main() {
// #ifndef ONLINE_JUDGE
// freopen("gondola.in", "r", stdin);
// freopen("gondola.out", "w", stdout);
// #endif
// cin.sync_with_stdio(0); cin.tie(0);
// return 0;
// }