답안 #297955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297955 2020-09-12T08:20:43 Z mieszko11b 곤돌라 (IOI14_gondola) C++14
100 / 100
78 ms 6776 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

using ii = pair<int, int>;
using ll = long long;

const ll MOD = ll(1e9) + 9;

#define X first
#define Y second

vector<int> S;

int valid(int n, int inputSeq[]) {
	vector<int> S(n);
	for(int i = 0 ; i < n ; i++)
		S[i] = inputSeq[i];
		
	set<int> hlp;
	for(int x : S) {
		if(hlp.count(x))
			return 0;
		hlp.insert(x);
	}
	
	for(int i = 0 ; i < n ; i++) {
		if(S[i] <= n) {
			rotate(S.begin(), S.begin() + (i - S[i] + 1 + n) % n, S.end());
			break;
		}
	}
	
	for(int i = 0 ; i < n ; i++)
		if(S[i] <= n && S[i] != i + 1)
			return 0;
			
	::S = S;
	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	valid(n, gondolaSeq);
	vector<int> res;
	
	vector<ii> V;
	for(int i = 0 ; i < n ; i++)
		if(S[i] > n)
			V.emplace_back(S[i], i + 1);
	
	sort(V.begin(), V.end());
	int nxt = n + 1;
	for(auto p : V) {
		res.push_back(p.Y);
		nxt++;
		for( ; nxt <= p.X ; nxt++)
			res.push_back(nxt - 1);
	}
	
	for(int i = 0 ; i < res.size() ; i++)
		replacementSeq[i] = res[i];
	return res.size();
}

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

ll pot(ll a, ll b) {
	if(b == 0)
		return 1;
	if(b % 2)
		return pot(a, b - 1) * a % MOD;
	ll tmp = pot(a, b / 2);
	return tmp * tmp % MOD;
}

int countReplacement(int n, int inputSeq[]) {
	if(!valid(n, inputSeq))
		return 0;
		
	ll res = 1;
	vector<int> V;
	bool any = false;
	for(int x : S)
		if(x > n)
			V.push_back(x);
		else
			any = true;
	V.push_back(n);
			
	sort(V.begin(), V.end());
	for(int i = 0 ; i + 1 < V.size() ; i++) {
		int a = V[i];
		int b = V[i + 1];
		
		//~ cout << V.size() - i - 1 << " " << b - a << endl;
		res = res * pot(V.size() - i - 1, b - a - 1) % MOD;
	}
	
	if(!any)
		res = res * n % MOD;
	
	return res;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int i = 0 ; i < res.size() ; i++)
      |                  ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:94:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |  for(int i = 0 ; i + 1 < V.size() ; i++) {
      |                  ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 17 ms 2560 KB Output is correct
7 Correct 14 ms 1052 KB Output is correct
8 Correct 32 ms 4472 KB Output is correct
9 Correct 9 ms 1664 KB Output is correct
10 Correct 37 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 16 ms 2560 KB Output is correct
7 Correct 15 ms 1024 KB Output is correct
8 Correct 33 ms 4480 KB Output is correct
9 Correct 10 ms 1664 KB Output is correct
10 Correct 40 ms 5244 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 21 ms 2296 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 53 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 36 ms 4984 KB Output is correct
12 Correct 42 ms 5624 KB Output is correct
13 Correct 32 ms 2296 KB Output is correct
14 Correct 39 ms 4944 KB Output is correct
15 Correct 31 ms 3036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 54 ms 4600 KB Output is correct
10 Correct 41 ms 3960 KB Output is correct
11 Correct 15 ms 1664 KB Output is correct
12 Correct 18 ms 1920 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 52 ms 4600 KB Output is correct
10 Correct 42 ms 3964 KB Output is correct
11 Correct 16 ms 1792 KB Output is correct
12 Correct 18 ms 1920 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 67 ms 6140 KB Output is correct
15 Correct 78 ms 6776 KB Output is correct
16 Correct 12 ms 1536 KB Output is correct
17 Correct 48 ms 4732 KB Output is correct
18 Correct 25 ms 2816 KB Output is correct