답안 #603552

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603552 2022-07-24T08:02:07 Z 8e7 곤돌라 (IOI14_gondola) C++17
100 / 100
21 ms 2216 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
	while (l != r)cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define mod 1000000009
#define pii pair<int, int>
#define ff first
#define ss second
#include "gondola.h"


int valid(int n, int a[]) {
	
	int ret = 1, st = -1;
	for (int i = 0;i < n;i++) {
		if (a[i] > n) continue;	
		int val = (a[i] - i - 1 + n) % n;
		if (st == -1) st = val;
		else if (val != st) {
			ret = 0;
			break;
		}
	}
	sort(a, a + n);
	for (int i = 1;i < n;i++) {
		if (a[i] == a[i-1]) ret = 0;
	}
	return ret;
}

//----------------------

int replacement(int n, int a[], int ret[]) {
	int cur = n+1, ind = 0, dif = 0;	
	for (int i = 0;i < n;i++) {
		if (a[i] <= n) dif = (a[i] - i - 1 + n) % n;
	}
	vector<pii> v;
	for (int i = 0;i < n;i++) {
		if (a[i] > n) {
			v.push_back({a[i], i});
			a[i] = (dif + i)%n + 1;
		}
	}
	sort(v.begin(), v.end());
	for (auto [val, id]:v) {
		while (cur <= val) {
			ret[ind++] = a[id];
			a[id] = cur++;
		}
	}
	return ind;
}

//----------------------

ll modpow(ll a, ll p) {
	ll ret = 1;
	while (p) {
		if (p & 1) ret = ret * a % mod;
		a = a * a % mod;
		p >>= 1;
	}
	return ret;
}
int countReplacement(int n, int a[]) {
	ll ans = 1;
	if (valid(n, a) == 0) return 0;
	int big = 0, cur = n;
	vector<int> v;
	for (int i = 0;i < n;i++) {
		if (a[i] > n) {
			big++;
			v.push_back(a[i]);
		}
	}
	if (big == n) ans *= n;
	sort(v.begin(), v.end());	
	for (int i:v) {
		ans = ans * modpow(big, i - cur - 1) % mod;
		cur = i;
		big--;
	}
	return (int)ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 340 KB Output is correct
7 Correct 14 ms 596 KB Output is correct
8 Correct 9 ms 468 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 13 ms 628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 12 ms 452 KB Output is correct
7 Correct 13 ms 596 KB Output is correct
8 Correct 9 ms 468 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 19 ms 636 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 8 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 13 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 11 ms 596 KB Output is correct
12 Correct 8 ms 624 KB Output is correct
13 Correct 14 ms 1264 KB Output is correct
14 Correct 8 ms 596 KB Output is correct
15 Correct 19 ms 2184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 13 ms 980 KB Output is correct
10 Correct 14 ms 900 KB Output is correct
11 Correct 5 ms 596 KB Output is correct
12 Correct 6 ms 596 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 15 ms 980 KB Output is correct
10 Correct 11 ms 948 KB Output is correct
11 Correct 4 ms 596 KB Output is correct
12 Correct 9 ms 596 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 21 ms 2136 KB Output is correct
15 Correct 20 ms 2216 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 17 ms 1492 KB Output is correct
18 Correct 10 ms 1084 KB Output is correct