답안 #274611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
274611 2020-08-19T13:08:39 Z faresbasbs 곤돌라 (IOI14_gondola) C++14
100 / 100
78 ms 6008 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;

int valid(int n, int a[]){
	vector<pair<int,int>> v;
	for(int i = 0 ; i < n ; i += 1){
		if(a[i] <= n){
			v.push_back({a[i],i});
		}
	}
	sort(v.begin(),v.end());
	for(int i = 1 ; i < v.size() ; i += 1){
		int diff1 = v[i].first-v[i-1].first , diff2;
		if(v[i].second > v[i-1].second){
			diff2 = v[i].second-v[i-1].second;
		}else{
			diff2 = n-v[i-1].second+v[i].second;
		}
		if(diff1 != diff2){
			return 0;
		}
	}
	set<int> st;
	for(int i = 0 ; i < n ; i += 1){
		if(st.count(a[i])){
			return 0;
		}
		st.insert(a[i]);
	}
	return 1;
}

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

int replacement(int n, int a[], int replacementSeq[]){
	int in[n];
	for(int i = 0 ; i < n ; i += 1){
		in[i] = i+1;
	}
	pair<int,int> v = {-1,-1};
	vector<pair<int,int>> g;
	for(int i = 0 ; i < n ; i += 1){
		if(a[i] <= n){
			v = {a[i],i};
		}else{
			g.push_back({a[i],i});
		}
	}
	if(v.first != -1){
		v.second -= v.first-1;
		if(v.second < 0){
			v.second += n;
		}
		int cnt = 1;
		for(int i = v.second ; i < n ; i += 1){
			in[i] = cnt;
			cnt += 1;
		}
		for(int i = 0 ; i < v.second ; i += 1){
			in[i] = cnt;
			cnt += 1;
		}
	}
	sort(g.begin(),g.end());
	if(g.size() == 0){
		return 0;
	}
	int p = 0 , cnt = 0;
	for(int i = n+1 ; i <= g.back().first ; i += 1){
		cnt += 1;
		replacementSeq[i-n-1] = in[g[p].second];
		in[g[p].second] = i;
		if(i == g[p].first){
			p += 1;
		}
	}
	return cnt;
}

//----------------------
const int mod = 1000000009;

long long pw(long long a , long long b){
	long long ret = 1;
	while(b){
		if(b % 2 == 1){
			ret *= a;
			ret %= mod;
		}
		a *= a;
		a %= mod;
		b /= 2;
	}
	return ret;
}

int countReplacement(int n, int a[]){
	if(!valid(n,a)){
		return 0;
	}
	vector<pair<int,int>> g;
	bool ok = true;
	for(int i = 0 ; i < n ; i += 1){
		if(a[i] > n){
			g.push_back({a[i],i});
		}else{
			ok = false;
		}
	}
	sort(g.begin(),g.end());
	int last = n;
	long long ret = 1;
	for(int i = 0 ; i < g.size() ; i += 1){
		ret *= pw(g.size()-i,g[i].first-last-1);
		ret %= mod;
		last = g[i].first;
	}
	if(ok){
		ret = (ret*n)%mod;
	}
	return ret;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i = 1 ; i < v.size() ; i += 1){
      |                  ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:114:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |  for(int i = 0 ; i < g.size() ; i += 1){
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 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 256 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 256 KB Output is correct
6 Correct 21 ms 2552 KB Output is correct
7 Correct 23 ms 1784 KB Output is correct
8 Correct 44 ms 4460 KB Output is correct
9 Correct 11 ms 1660 KB Output is correct
10 Correct 43 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 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 1 ms 256 KB Output is correct
6 Correct 18 ms 2552 KB Output is correct
7 Correct 22 ms 1868 KB Output is correct
8 Correct 41 ms 4468 KB Output is correct
9 Correct 11 ms 1692 KB Output is correct
10 Correct 51 ms 5228 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 20 ms 1276 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 256 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 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 384 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 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 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
11 Correct 12 ms 896 KB Output is correct
12 Correct 14 ms 1024 KB Output is correct
13 Correct 17 ms 1424 KB Output is correct
14 Correct 12 ms 896 KB Output is correct
15 Correct 25 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 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 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 52 ms 4600 KB Output is correct
10 Correct 43 ms 3956 KB Output is correct
11 Correct 15 ms 1536 KB Output is correct
12 Correct 19 ms 1920 KB Output is correct
13 Correct 5 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 55 ms 4600 KB Output is correct
10 Correct 42 ms 3956 KB Output is correct
11 Correct 15 ms 1664 KB Output is correct
12 Correct 19 ms 1920 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 67 ms 5496 KB Output is correct
15 Correct 78 ms 6008 KB Output is correct
16 Correct 12 ms 1408 KB Output is correct
17 Correct 50 ms 4140 KB Output is correct
18 Correct 26 ms 2464 KB Output is correct