답안 #138802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138802 2019-07-30T10:42:32 Z Mahmoud_Adel 곤돌라 (IOI14_gondola) C++14
100 / 100
135 ms 8180 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5, mod = 1e9+9;
int mep[N];
map<ll, ll> mark;
ll power(ll a, ll b)
{
	if(!b) return 1;
	ll temp = power(a, b/2);
	temp = (temp*temp)%mod;
	if(b%2) temp *= a, temp %= mod;
	return temp;
}
int valid(int n, int inputSeq[])
{
	for(int i=0; i<n; i++)
	{
		if(mark[inputSeq[i]]) return 0;
		else mark[inputSeq[i]] = 1;
	}
	int j = -1;
	for(int i=0; i<n; i++) if(inputSeq[i] > 0 && inputSeq[i] <= n) j = i;
	if(j == -1) return 1;
	for(int i=0; i<n; i++)
	{
		int id = (i+j)%n, jd = (i+j+1)%n;
		if(inputSeq[jd] > n) inputSeq[jd] = inputSeq[id]%n + 1;
		if(inputSeq[jd] != inputSeq[id]%n + 1) return 0;
	}
	return 1;
}

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

int replacement(int n, int inputSeq[], int replacementSeq[])
{
	memset(mep, 0, sizeof mep);
	vector<int> vec;
	int j = -1;
	for(int i=0; i<n; i++) if(inputSeq[i] <= n) j = i;
	if(j == -1) for(int i=0; i<n; i++) vec.push_back(inputSeq[i]), 
	mep[inputSeq[i]] = i+1;
	else
	{
		for(int i=0; i<n; i++)
		{
			int id = (i+j)%n, jd = (i+j+1)%n;
			if(inputSeq[jd] > n)
			{
				vec.push_back(inputSeq[jd]);
				mep[inputSeq[jd]] = inputSeq[id]%n + 1;
				inputSeq[jd] = inputSeq[id]%n + 1;
			}
		}
	}
	sort(vec.begin(), vec.end());
	int cur = n+1, c = 0;
	for(int i : vec)
	{
		int last = mep[i];
		while(cur <= i) replacementSeq[c++] = last, last = cur, cur++;
		//replacementSeq[c++] = last;
	}
	return c;
}

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

int countReplacement(int n, int inputSeq[])
{
	int tmp[n];
	for(int i=0; i<n; i++) tmp[i] = inputSeq[i];
	if(!valid(n, inputSeq)) return 0;
	for(int i=0; i<n; i++) inputSeq[i] = tmp[i];
	ll j = -1, c = n;
	vector<ll> vec;
	for(int i=0; i<n; i++) if(inputSeq[i] <= n) j  = i;
	else vec.push_back(inputSeq[i]);
	ll ans = 1;
	vec.push_back(n);
	sort(vec.begin(), vec.end());
	for(int i=0; i<vec.size()-1; i++)
	{
		ll tmp = power((ll)vec.size()-i-1, vec[i+1]-vec[i]-1);
		ans = (ans%mod * tmp%mod)%mod;
	}
	return (ans*(j==-1? n:1))%mod;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:84:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vec.size()-1; i++)
               ~^~~~~~~~~~~~~
gondola.cpp:77:13: warning: unused variable 'c' [-Wunused-variable]
  ll j = -1, c = n;
             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 25 ms 2812 KB Output is correct
7 Correct 14 ms 732 KB Output is correct
8 Correct 49 ms 5112 KB Output is correct
9 Correct 15 ms 1784 KB Output is correct
10 Correct 65 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 1 ms 252 KB Output is correct
6 Correct 28 ms 2808 KB Output is correct
7 Correct 13 ms 760 KB Output is correct
8 Correct 49 ms 5116 KB Output is correct
9 Correct 17 ms 1892 KB Output is correct
10 Correct 59 ms 5852 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 24 ms 2680 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 64 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 6 ms 4216 KB Output is correct
4 Correct 6 ms 4220 KB Output is correct
5 Correct 5 ms 4220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 5 ms 4216 KB Output is correct
4 Correct 5 ms 4088 KB Output is correct
5 Correct 5 ms 4216 KB Output is correct
6 Correct 6 ms 4216 KB Output is correct
7 Correct 6 ms 4216 KB Output is correct
8 Correct 6 ms 4216 KB Output is correct
9 Correct 6 ms 4220 KB Output is correct
10 Correct 6 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4216 KB Output is correct
2 Correct 6 ms 4216 KB Output is correct
3 Correct 5 ms 4216 KB Output is correct
4 Correct 6 ms 4216 KB Output is correct
5 Correct 5 ms 4216 KB Output is correct
6 Correct 6 ms 4220 KB Output is correct
7 Correct 5 ms 4216 KB Output is correct
8 Correct 7 ms 4316 KB Output is correct
9 Correct 7 ms 4344 KB Output is correct
10 Correct 6 ms 4344 KB Output is correct
11 Correct 15 ms 4984 KB Output is correct
12 Correct 17 ms 5112 KB Output is correct
13 Correct 21 ms 5364 KB Output is correct
14 Correct 15 ms 4984 KB Output is correct
15 Correct 27 ms 6344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 64 ms 6136 KB Output is correct
10 Correct 51 ms 5240 KB Output is correct
11 Correct 19 ms 2296 KB Output is correct
12 Correct 22 ms 2680 KB Output is correct
13 Correct 6 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 60 ms 6156 KB Output is correct
10 Correct 48 ms 5240 KB Output is correct
11 Correct 18 ms 2296 KB Output is correct
12 Correct 22 ms 2676 KB Output is correct
13 Correct 6 ms 916 KB Output is correct
14 Correct 78 ms 7340 KB Output is correct
15 Correct 135 ms 8180 KB Output is correct
16 Correct 15 ms 1912 KB Output is correct
17 Correct 55 ms 5492 KB Output is correct
18 Correct 35 ms 3576 KB Output is correct