# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
637307 | ghostwriter | 곤돌라 (IOI14_gondola) | C++14 | 58 ms | 5964 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
Tran The Bao
CTL - Da Lat
Cay ngay cay dem nhung deo duoc cong nhan
*/
bool checkdistinct(int n, int inputSeq[]) {
map<int, int> c;
FOR(i, 0, n - 1) {
++c[inputSeq[i]];
if (c[inputSeq[i]] > 1) return 0;
}
return 1;
}
int getoriginalpos(int n, int inputSeq[]) {
FOR(i, 0, n - 1)
if (inputSeq[i] <= n)
return i;
return -1;
}
int valid(int n, int inputSeq[]) {
if (!checkdistinct(n, inputSeq)) return 0;
int pos = getoriginalpos(n, inputSeq);
if (pos == -1) return 1;
FOR(i, 0, n - 1) {
if (inputSeq[i] > n || i == pos) continue;
int val = (i - pos + inputSeq[pos] - 1 + n) % n + 1;
if (inputSeq[i] != val) return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
vpi a;
int pos = getoriginalpos(n, gondolaSeq);
if (pos == -1) pos = 0;
FOR(i, 0, n - 1) {
if (gondolaSeq[i] <= n) continue;
int val = (i - pos + gondolaSeq[pos] - 1 + n) % n + 1;
a.pb({gondolaSeq[i], val});
}
sort(all(a));
int cur = n, l = 0;
EACH(i, a) {
replacementSeq[l++] = i.nd;
++cur;
WHILE(cur < i.st) replacementSeq[l++] = cur++;
}
return l;
}
//----------------------
const int M = 1e9 + 9;
int fpow(int a, int b, int M) {
if (b == 0) return 1;
int tmp = fpow(a, b >> 1, M);
if (b & 1) return 1LL * tmp * tmp % M * a % M;
return 1LL * tmp * tmp % M;
}
int countReplacement(int n, int inputSeq[]) {
if (!valid(n, inputSeq)) return 0;
vi a;
FOR(i, 0, n - 1) {
if (inputSeq[i] <= n) continue;
a.pb(inputSeq[i]);
}
if (a.empty()) return 1;
sort(all(a));
int pre = n, total = sz(a), rs = 1;
EACH(i, a) {
int cnt = i - pre - 1;
rs = 1LL * rs * fpow(total, cnt, M) % M;
pre = i;
--total;
}
int pos = getoriginalpos(n, inputSeq);
if (pos == -1) rs = 1LL * rs * n % M;
return rs;
}
/*
10
4
4 7 4 7
*/
컴파일 시 표준 에러 (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... |