답안 #308470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308470 2020-10-01T10:42:48 Z tengiz05 곤돌라 (IOI14_gondola) C++17
100 / 100
148 ms 19704 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int a[N];
int valid(int n, int inputSeq[]){
	for(int i=0;i<n;i++)a[i] = inputSeq[i];
	int i;
	map<int, int> cnt;
	for(i=0;i<n;i++)cnt[a[i]]++;
	for(i=0;i<N*3;i++)if(cnt[i] > 1)return 0;
	for(i=0;i<n;i++){
		if(a[i] < n)break;
	}if(i == n)return 1;
	int now = a[i];
	for(int j=0;j<n;j++){
		if(a[i] <= n && a[i] != now)return 0;
		now++;
		if(now > n)now = 1;
		i++;
		i%=n;
	}
	return 1;
}

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

bool Fixed[N];
int b[N];
int expect[N*3];
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	set<int> not_fixed;
	for(int i=0;i<N*3;i++)expect[i] = -1;
	for(int i=0;i<n;i++)a[i] = gondolaSeq[i];
	int idx = n;
	for(int i=0;i<n;i++){
		if(a[i] <= n){idx = i; break;}
	}if(idx != n){
		int now = a[idx];
		for(int j=0;j<n;j++){
			b[idx] = now;
			idx++;
			idx %= n;
			now++;
			if(now == n+1)now = 1;
		}
	}else {
		for(int i=0;i<n;i++)b[i] = i+1;
	}
	for(int i=0;i<n;i++){
		if(a[i] <= n)Fixed[i] = true;
		else {
			not_fixed.insert(i);
			expect[a[i]] = i;
		}
	}
	vector<int> ans;
	int now = n+1;
	while(not_fixed.size() > 0){
		if(expect[now] == -1){
			ans.push_back(b[*not_fixed.begin()]);
			b[*not_fixed.begin()] = now;
		}else {
			ans.push_back(b[expect[now]]);
			b[expect[now]] = n;
			not_fixed.erase(expect[now]);
		}now++;
	}
	for(int i=0;i<ans.size();i++){
		replacementSeq[i] = ans[i];
	}
	return (int)ans.size();
}
/*

4
7
2 3 4 9 6 7 1

*/

//----------------------
const long long mod = 1e9+9;
long long binpow(long long a, long long b){
	if(b == 0)return 1ll;
	long long temp = binpow(a, b/2ll);
	temp = (1ll*temp*temp)%mod;
	if(b%2==1)temp *= a;
	return temp%mod;
}
int countReplacement(int n, int inputSeq[]){
	if(valid(n, inputSeq) == false)return 0;
	for(int i=0;i<n;i++){
		a[i] = inputSeq[i];
	}vector<int> v;
	for(int i=0;i<n;i++){
		if(a[i] > n)v.push_back(i);
	}sort(a, a+n);
	if(v.size() == 0)return 1;
	long long last = n;
	long long ans = 1;
	if(v.size() == n)ans *= n;
	for(int i=0;i<n;i++){
		if(a[i] <= n)continue;
		long long dist = a[i]-last-1ll;
		ans *= binpow((long long)n-i, dist);
		ans %= mod;
		last = a[i];
	}
	ans %= mod;
	return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:69:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |  for(int i=0;i<ans.size();i++){
      |              ~^~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:102:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  102 |  if(v.size() == n)ans *= n;
      |     ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 14584 KB Output is correct
2 Correct 72 ms 14584 KB Output is correct
3 Correct 74 ms 14584 KB Output is correct
4 Correct 76 ms 14712 KB Output is correct
5 Correct 70 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 14456 KB Output is correct
2 Correct 73 ms 14456 KB Output is correct
3 Correct 75 ms 14396 KB Output is correct
4 Correct 73 ms 14456 KB Output is correct
5 Correct 71 ms 14388 KB Output is correct
6 Correct 77 ms 14760 KB Output is correct
7 Correct 37 ms 4088 KB Output is correct
8 Correct 92 ms 14968 KB Output is correct
9 Correct 75 ms 14584 KB Output is correct
10 Correct 89 ms 15096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 14456 KB Output is correct
2 Correct 74 ms 14420 KB Output is correct
3 Correct 73 ms 14460 KB Output is correct
4 Correct 76 ms 14456 KB Output is correct
5 Correct 70 ms 14424 KB Output is correct
6 Correct 77 ms 14712 KB Output is correct
7 Correct 33 ms 4096 KB Output is correct
8 Correct 90 ms 15096 KB Output is correct
9 Correct 76 ms 14584 KB Output is correct
10 Correct 87 ms 15096 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 70 ms 14456 KB Output is correct
13 Correct 77 ms 14712 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 103 ms 15124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 2 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 2 ms 1536 KB Output is correct
9 Correct 2 ms 1536 KB Output is correct
10 Correct 2 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1512 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 2 ms 1536 KB Output is correct
8 Correct 2 ms 1536 KB Output is correct
9 Correct 2 ms 1536 KB Output is correct
10 Correct 2 ms 1664 KB Output is correct
11 Correct 12 ms 2560 KB Output is correct
12 Correct 13 ms 2688 KB Output is correct
13 Correct 29 ms 4196 KB Output is correct
14 Correct 11 ms 2688 KB Output is correct
15 Correct 33 ms 4424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 14456 KB Output is correct
2 Correct 74 ms 14456 KB Output is correct
3 Correct 73 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 14584 KB Output is correct
2 Correct 75 ms 14460 KB Output is correct
3 Correct 74 ms 14456 KB Output is correct
4 Correct 70 ms 14456 KB Output is correct
5 Correct 72 ms 14456 KB Output is correct
6 Correct 71 ms 14456 KB Output is correct
7 Correct 70 ms 14456 KB Output is correct
8 Correct 70 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 14456 KB Output is correct
2 Correct 74 ms 14456 KB Output is correct
3 Correct 74 ms 14456 KB Output is correct
4 Correct 70 ms 14456 KB Output is correct
5 Correct 71 ms 14456 KB Output is correct
6 Correct 70 ms 14456 KB Output is correct
7 Correct 70 ms 14456 KB Output is correct
8 Correct 70 ms 14456 KB Output is correct
9 Correct 105 ms 14968 KB Output is correct
10 Correct 98 ms 14840 KB Output is correct
11 Correct 74 ms 14628 KB Output is correct
12 Correct 82 ms 14584 KB Output is correct
13 Correct 74 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 14456 KB Output is correct
2 Correct 72 ms 14460 KB Output is correct
3 Correct 74 ms 14456 KB Output is correct
4 Correct 72 ms 14456 KB Output is correct
5 Correct 71 ms 14456 KB Output is correct
6 Correct 70 ms 14456 KB Output is correct
7 Correct 74 ms 14456 KB Output is correct
8 Correct 73 ms 14456 KB Output is correct
9 Correct 106 ms 15032 KB Output is correct
10 Correct 95 ms 14840 KB Output is correct
11 Correct 77 ms 14584 KB Output is correct
12 Correct 80 ms 14584 KB Output is correct
13 Correct 72 ms 14584 KB Output is correct
14 Correct 135 ms 18936 KB Output is correct
15 Correct 148 ms 19704 KB Output is correct
16 Correct 87 ms 15400 KB Output is correct
17 Correct 120 ms 17924 KB Output is correct
18 Correct 97 ms 16376 KB Output is correct