답안 #336840

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336840 2020-12-17T01:42:08 Z arwaeystoamneg 곤돌라 (IOI14_gondola) C++17
100 / 100
84 ms 6124 KB
#include "gondola.h"
/*
ID: awesome35
LANG: C++14
TASK: vans
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<chrono>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;

#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)

#define pb push_back
#define mp make_pair
#define rsz resize
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define cont continue
#define endl '\n'
#define ednl '\n'
#define test int testc;cin>>testc;while(testc--)
#define pr(a, b) trav(x,a)cerr << x << b; cerr << endl;
#define message cout << "Hello World" << endl;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4000000000000000000LL;
const ll inf = 1000000009;//998244353
const ld pi = 3.1415926535;

void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) {
	F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; }
}void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; }

int valid(int n, int* a)
{
	set<int>t;
	F0R(i, n)t.insert(a[i]);
	if (sz(t) != n)return 0;
	int index = 0;
	for (; index < n; index++)
	{
		if (a[index] <= n)break;
	}
	if (index == n)return 1;
	vi b(n);
	F0R(i, n)
	{
		b[(i - index + a[index] - 1 + n) % n] = a[i];
	}
	F0R(i, n)
	{
		if (b[i] <= n)
		{
			if (b[i] - i != 1)return 0;
		}
	}
	return 1;
}
int replacement(int n, int* a, int* ans)
{
	int index = 0;
	for (; index < n; index++)
	{
		if (a[index] <= n)break;
	}
	vi b(n);
	F0R(i, n)b[i] = a[i];
	if (index != n)
	{
		F0R(i, n)
		{
			b[(i - index + a[index] - 1 + n) % n] = a[i];
		}
	}
	F0R(i, n)a[i] = b[i];
	vi cur(n);
	iota(all(cur), 1);
	set<int>next;
	map<int, int>last;
	F0R(i, n)last.insert({ a[i],i });
	F0R(i, n)if (a[i] != i + 1)next.insert(i);
	index = 0;// ptr in ans
	int t = *max_element(a, a + n);
	FOR(i, n + 1, t + 1)
	{
		if (last.count(i))
		{
			ans[index++] = cur[last[i]];
			next.erase(last[i]);
		}
		else
		{
			ans[index++] = cur[*next.begin()];
			cur[*next.begin()] = i;
		}
	}
	return t - n;
}
ll power(ll x, ll y)
{
	ll k = 1LL << 60;
	ll z = 1;
	while (k != 0)
	{
		z *= z;
		z %= inf;
		if (y >= k)
		{
			z *= x;
			z %= inf;
			y -= k;
		}
		k >>= 1;
	}
	return z;
}
int countReplacement(int n, int* a)
{
	if (!valid(n, a))return 0;
	int index = 0;
	for (; index < n; index++)
	{
		if (a[index] <= n)break;
	}
	vi b(n);
	F0R(i, n)b[i] = a[i];
	if (index != n)
	{
		F0R(i, n)
		{
			b[(i - index + a[index] - 1 + n) % n] = a[i];
		}
	}
	F0R(i, n)a[i] = b[i];
	vi cur(n);
	iota(all(cur), 1);
	int next = 0;
	vi last;
	F0R(i, n)last.pb(a[i]);
	sort(all(last));
	F0R(i, n)if (a[i] != i + 1)next++;
	ll ans = 1;
	int i = lower_bound(all(last), n + 1) - last.begin();
	if (i == n)return 1;
	ans = power(next, last[i] - n - 1);
	next--;
	for (; i < n - 1; i++)
	{
		int j = i + 1;
		ans *= power(next, last[j] - last[i] - 1);
		ans %= inf;
		next--;
	}
	if (index == n)
	{
		ans *= n;
		ans %= inf;
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 12 ms 2412 KB Output is correct
7 Correct 38 ms 3692 KB Output is correct
8 Correct 25 ms 4204 KB Output is correct
9 Correct 10 ms 1516 KB Output is correct
10 Correct 30 ms 4844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 12 ms 2412 KB Output is correct
7 Correct 31 ms 3692 KB Output is correct
8 Correct 26 ms 4204 KB Output is correct
9 Correct 7 ms 1516 KB Output is correct
10 Correct 27 ms 4844 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 16 ms 2284 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 43 ms 4972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 380 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 28 ms 4972 KB Output is correct
12 Correct 32 ms 5612 KB Output is correct
13 Correct 47 ms 4316 KB Output is correct
14 Correct 31 ms 4972 KB Output is correct
15 Correct 40 ms 3820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 61 ms 4332 KB Output is correct
10 Correct 45 ms 3692 KB Output is correct
11 Correct 17 ms 1516 KB Output is correct
12 Correct 22 ms 1772 KB Output is correct
13 Correct 5 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 60 ms 4332 KB Output is correct
10 Correct 44 ms 3692 KB Output is correct
11 Correct 18 ms 1516 KB Output is correct
12 Correct 22 ms 1772 KB Output is correct
13 Correct 5 ms 620 KB Output is correct
14 Correct 73 ms 4588 KB Output is correct
15 Correct 84 ms 6124 KB Output is correct
16 Correct 14 ms 1388 KB Output is correct
17 Correct 53 ms 4204 KB Output is correct
18 Correct 29 ms 2540 KB Output is correct