답안 #903360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
903360 2024-01-11T07:18:27 Z Muhammad_Aneeq 곤돌라 (IOI14_gondola) C++17
75 / 100
64 ms 10444 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include "gondola.h"
using namespace std;
int mod=1e9+9;
long long power(long long x,int y)
{
	long long res=1;
	while (y)
	{
		if (y%2)
			res=(res*x)%mod;
		x=(x*x)%mod;
		y/=2;
	}
	return res;
}
int valid(int n, int inputSeq[])
{
	vector<pair<int,int>>s={};
	map<int,int>d;
	for (int i=0;i<n;i++)
	{
		d[inputSeq[i]]++;
		if (inputSeq[i]<=n)
			s.push_back({inputSeq[i],i});
	}
	for (auto i:d)
	{
		if (i.second>1)
			return 0;
	}
	for (int i=0;i<s.size()-1;i++)
	{
		int z=s[i+1].second-s[i].second;
		if (((s[i+1].first-z+n-1)%n)+1==s[i].first)
			continue;
		return 0;
	}	
	return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	int z=0;
	map<int,int>d;
	for (int i=0;i<n;i++)	
	{
		d[gondolaSeq[i]]++;
		z=max(z,gondolaSeq[i]);
	}
	vector<int>f;
	for (int i=n+1;i<z;i++)
	{
		if (d.find(i)==d.end())
			f.push_back(i);
		else
			if (d[i]>1)
				return 0;
	}
	int ind=0,val=1;
	for (int i=0;i<n;i++)
	{
		if (gondolaSeq[i]<=n)
		{
			ind=i;
			val=gondolaSeq[i];
		}
	}
	int req=(ind+n+1-val)%n;
	vector<pair<int,int>>w;
	for (int i=0;i<n;i++)
		w.push_back({gondolaSeq[i],i});
	sort(begin(w),end(w));
	map<int,int>in;
	for (int i=1;i<=n;i++)
	{
		in[req++]=i;
		req%=n;
	}
	int g=0;
	reverse(begin(f),end(f));
	for (int i=0;i<n;i++)
	{
		if (d[in[w[i].second]]==0)
		{
			replacementSeq[g++]=in[w[i].second];
		}
		while (f.size()&&f.back()<w[i].first)
		{
			replacementSeq[g++]=f.back();
			f.pop_back();
		}
	}
	return g;
}
int countReplacement(int n, int inputSeq[])
{
	if (!valid(n,inputSeq))
		return 0;
	vector<int>s;
	for (int i=0;i<n;i++)
	{
		if (inputSeq[i]>n)
			s.push_back(inputSeq[i]);
	}
	s.push_back(n);
	sort(begin(s),end(s));
	long long ans=power(n,(s.size()==n+1));
	for (int i=1;i<s.size();i++)
		ans=(ans*power(s.size()-i,s[i]-s[i-1]-1))%mod;
	return (int)(ans);
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:36:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i=0;i<s.size()-1;i++)
      |               ~^~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:111:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  111 |  long long ans=power(n,(s.size()==n+1));
      |                         ~~~~~~~~^~~~~
gondola.cpp:112:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |  for (int i=1;i<s.size();i++)
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 448 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 8 ms 2788 KB Output is correct
7 Correct 28 ms 4820 KB Output is correct
8 Correct 16 ms 5088 KB Output is correct
9 Correct 7 ms 1764 KB Output is correct
10 Correct 26 ms 5728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 360 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 8 ms 2748 KB Output is correct
7 Correct 24 ms 4820 KB Output is correct
8 Correct 24 ms 5088 KB Output is correct
9 Correct 5 ms 1764 KB Output is correct
10 Correct 20 ms 5768 KB Output is correct
11 Correct 1 ms 456 KB Output is correct
12 Correct 1 ms 360 KB Output is correct
13 Correct 11 ms 2248 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 38 ms 5788 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 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 416 KB Output is correct
2 Correct 1 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 348 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 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 392 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 39 ms 9100 KB Output is correct
12 Correct 64 ms 10444 KB Output is correct
13 Correct 48 ms 6044 KB Output is correct
14 Correct 53 ms 9088 KB Output is correct
15 Correct 32 ms 4716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 440 KB Output is correct
3 Correct 1 ms 348 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 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 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 344 KB Output is correct
2 Correct 0 ms 396 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 32 ms 4764 KB Output is correct
10 Correct 22 ms 3944 KB Output is correct
11 Correct 8 ms 1616 KB Output is correct
12 Correct 11 ms 2012 KB Output is correct
13 Runtime error 3 ms 1112 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 544 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 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 0 ms 348 KB Output is correct
9 Correct 29 ms 4712 KB Output is correct
10 Correct 25 ms 4212 KB Output is correct
11 Correct 11 ms 1624 KB Output is correct
12 Correct 11 ms 1880 KB Output is correct
13 Runtime error 3 ms 1116 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -