답안 #903304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
903304 2024-01-11T06:57:07 Z Jawad_Akbar_JJ 곤돌라 (IOI14_gondola) C++17
75 / 100
48 ms 10304 KB
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
 
#include "gondola.h"
 
using namespace std;
const int N = 1e5 + 10;
 
int valid(int n,int s[]){
	int mn = 2e9;
	int ss[n + n + 5] = {0};
 
	map<int,bool> seeen;
	
	for (int i=1;i<=n;i++)
		ss[i] = ss[i + n] = s[i-1];
 
	int ind = 0;
	for (int i=1;i<=n;i++){
		if (ss[i] <= n and ss[i] < mn)
			ind = i;
		mn = min(mn,ss[i]);
	}
 
	for (int i=1;i<=n;i++){
		if (seeen[ss[i]])
			return false;
		seeen[ss[i]] = true;
	}
 
	if (mn > n)
		return 1;
	
	if (ind < mn)
		ind += n;
	
	while (mn>1)
		ind--,mn--;
 
	for (int i=ind;mn<=n;mn++,i++)
		if (ss[i] != mn and ss[i] <= n)
			return 0;
	return 1;
}
 
int replacement(int n,int s[],int sss[]){
	int mn = n + 5;
	int ss[n + n + 5] = {0};
 
	for (int i=1;i<=n;i++)
		ss[i] = ss[i + n] = s[i-1];
 
	map<int,int> seen;
	int ind = 0;
	int mx = 0;
	for (int i=1;i<=n;i++){
		if (ss[i] <= n and ss[i] < mn)
			mn = min(mn,ss[i]),ind = i;
		mx = max(mx,ss[i]);
	}
 
	if (ind==0){
		int cur = 0;
		for (int i=1;i<=n;i++)
			seen[ss[i]] = i;
		
		for (int i=n+1;i<=mx;i++){
			if (seen[i]==0)
				sss[cur++] = seen[mx],seen[mx] = i;
			else
				sss[cur++] = seen[i];
		}
		return cur;
	}
 
 
	if (ind < mn)
		ind += n;
	
	while (mn>1)
		ind--,mn--;
 
	for (int i=ind ; mn<=n ; i++,mn++)
		seen[ss[i]] = mn;
	// 
	int cur = 0;
	for (int i=n+1;i<=mx;i++){
		// cout<<i<<" dd "<<seen[i]<<endl;
		if (seen[i]!=0)
			sss[cur++] = seen[i];
		else
			sss[cur++] = seen[mx],seen[mx] = i;
	}
 
	return cur;
}
 
 
long long power(int a,int b,long long m){
	if (b==0)
		return 1;
	if (b==1)
		return a;
	long long ans = power(a,b/2,m);
	ans = 1LL * ans * ans % m;
	if (b%2)
		ans = 1LL * a * ans % m;
	return ans % m;
}
 
 
int countReplacement(int n,int s[]){
	int mn = n + 5;
	int ss[n + 5] = {0};
 
	for (int i=1;i<=n;i++)
		ss[i] = s[i-1];
 
	int ind = 0;
	int mx = 0;
	
	for (int i=1;i<=n;i++)
		mx = max(mx,ss[i]);
	
	if (!valid(n,s))
		return 0;
	if (mx == n)
		return 1;
 
 
	vector<int> v;
	for (int i=1;i<=n;i++)
		if (ss[i] > n)
			v.push_back(ss[i]);
 
	v.push_back(n);
 
	sort(begin(v),end(v));
 
	int sz = v.size();
 
	long long ans = 1;
	long long mod = 1000000009;
 
	for (int i=1;i<sz;i++){
		int msng = v[i] - v[i-1] - 1;
		int rem = sz - i;
		ans = 1LL * ans * power(rem,msng,mod) % mod;
	}
	return ans % mod;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:115:6: warning: unused variable 'mn' [-Wunused-variable]
  115 |  int mn = n + 5;
      |      ^~
gondola.cpp:121:6: warning: unused variable 'ind' [-Wunused-variable]
  121 |  int ind = 0;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 444 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 15 ms 2652 KB Output is correct
7 Correct 7 ms 1980 KB Output is correct
8 Correct 28 ms 4956 KB Output is correct
9 Correct 6 ms 2036 KB Output is correct
10 Correct 30 ms 5712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 10 ms 2704 KB Output is correct
7 Correct 7 ms 1852 KB Output is correct
8 Correct 20 ms 4960 KB Output is correct
9 Correct 6 ms 1788 KB Output is correct
10 Correct 25 ms 5608 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 14 ms 2556 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 33 ms 6000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 436 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 17 ms 5464 KB Output is correct
12 Correct 20 ms 5980 KB Output is correct
13 Correct 27 ms 5200 KB Output is correct
14 Correct 16 ms 5416 KB Output is correct
15 Correct 48 ms 10304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 440 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 43 ms 5460 KB Output is correct
10 Correct 27 ms 4432 KB Output is correct
11 Correct 10 ms 1844 KB Output is correct
12 Correct 14 ms 2136 KB Output is correct
13 Incorrect 3 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 444 KB Output is correct
9 Correct 34 ms 5324 KB Output is correct
10 Correct 27 ms 4628 KB Output is correct
11 Correct 10 ms 1880 KB Output is correct
12 Correct 13 ms 2140 KB Output is correct
13 Incorrect 4 ms 860 KB Output isn't correct
14 Halted 0 ms 0 KB -