# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
250738 | ant101 | 곤돌라 (IOI14_gondola) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include <complex>
#include "gondola.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define mp make_pair
#define f first
#define s second
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
namespace input {
template<class T> void re(complex<T>& x);
template<class T1, class T2> void re(pair<T1,T2>& p);
template<class T> void re(vector<T>& a);
template<class T, size_t SZ> void re(array<T,SZ>& a);
template<class T> void re(T& x) { cin >> x; }
void re(double& x) { string t; re(t); x = stod(t); }
void re(ld& x) { string t; re(t); x = stold(t); }
template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
re(first); re(rest...);
}
template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}
namespace output {
template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
pr("{",x.f,", ",x.s,"}");
}
template<class T> void prContain(const T& x) {
pr("{");
bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }
void ps() { pr("\n"); }
template<class Arg> void ps(const Arg& first) {
pr(first); ps(); // no space at end of line
}
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
pr(first," "); ps(rest...); // print w/ spaces
}
}
using namespace output;
using namespace input;
ll add(ll a, ll b) {
a += b;
if(a >= MOD) {
a -= MOD;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if(a < 0) {
a += MOD;
}
return a;
}
ll mul(ll a, ll b) {
return (a * b)%MOD;
}
void add_self(ll& a, ll b) {
a = add(a, b);
}
void sub_self(ll& a, ll b) {
a = sub(a, b);
}
void mul_self(ll& a, ll b) {
a = mul(a, b);
}
using namespace std;
ll valid(ll n, ll inputSeq[]) {
set<ll> s;
for (ll i = 0; i<n; i++) {
if (s.find(inputSeq[i]) != s.end()) {
return 0;
}
s.insert(inputSeq[i]);
}
ll piv = -1;
for (ll i = 0; i<n; i++) {
if (inputSeq[i] <= n){
if (piv == -1) {
piv = i;
} else {
ll res = i+(inputSeq[piv]-piv)+n;
res %= n;
if (res == 0) {
res = n;
}
if (inputSeq[i] != res) {
return 0;
}
}
}
}
return 1;
}
priority_queue<pl, vector<pl>, greater<pl>> pq, pq2;
ll replacement(ll n, ll gondolaSeq[], ll replacementSeq[]){
ll piv = 0, piv2 = n+1, piv3 = 0;
for (ll i = 0; i<n; i++) {
if (gondolaSeq[i] <= n){
piv = gondolaSeq[i]-i-1+n;
piv%=n;
}
}
ll newSeq[100005] = {};
for (ll i = 0; i<n; i++) {
newSeq[i] = gondolaSeq[(i+n-piv)%n];
if (newSeq[i] > n) pq.push(pi(newSeq[i], i+1));
}
while (!pq.empty()) {
pl x = pq.top();
pq.pop();
replacementSeq[piv3++] = x.second;
for (ll i = piv2; i<x.first; i++) {
replacementSeq[piv3++] = i;
}
piv2 = x.first + 1;
}
return piv3;
}
ll pow(ll x, ll time){
ll res = 1, piv = x, mod = 1e9 + 9;
while (time) {
if (time&1) {
res *= piv;
}
piv*=piv;
res%=mod;
piv%=mod;
time>>=1;
}
return res;
}
ll newSeq[100005];
ll countReplacement(ll n, ll inputSeq[]){
if (!valid(n, inputSeq)) {
return 0;
}
ll piv = 0, piv2 = n, cnt = 0;
ll res = 1;
for (ll i = 0; i<n; i++) {
if (inputSeq[i] > n) {
newSeq[piv++] = inputSeq[i];
}
}
if (piv == n) {
res = piv;
}
if (piv == 0) {
return 1;
}
cnt = piv;
sort(newSeq,newSeq+piv);
for (ll i = 0; i<piv; i++) {
res*=pow(cnt,newSeq[i] - piv2 - 1);
piv2 = newSeq[i];
cnt--;
res%=1000000009;
}
return (ll)res;
}