Submission #832493

# Submission time Handle Problem Language Result Execution time Memory
832493 2023-08-21T10:53:51 Z ttamx Gondola (IOI14_gondola) C++14
100 / 100
51 ms 6308 KB
#include "gondola.h"
#include<bits/stdc++.h>

using namespace std;

int valid(int n, int Seq[]){
	vector<int> s(n);
	map<int,bool> mp;
	for(int i=0;i<n;i++){
		if(mp[Seq[i]])return 0;
		mp[Seq[i]]=true;
		if(Seq[i]<=n)s[i]=Seq[i];
	}
	for(int t=0;t<2;t++){
		for(int i=0;i<n;i++){
			if(s[i]>0){
				auto &x=s[(i+1)%n];
				int val=s[i]%n+1;
				if(x==0)x=val;
				else if(x!=val)return 0;
			}
		}
	}
	return 1;
}

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

int replacement(int n, int Seq[], int Ans[]){
	vector<int> s(n);
	vector<pair<int,int>> vec;
	for(int i=0;i<n;i++){
		if(Seq[i]<=n)s[i]=Seq[i];
		else vec.emplace_back(Seq[i],i);
	}
	for(int t=0;t<2;t++)for(int i=0;i<n;i++)if(s[i]>0)s[(i+1)%n]=s[i]%n+1;
	if(s[0]==0)iota(s.begin(),s.end(),1);
	sort(vec.begin(),vec.end());
	int nxt=n+1;
	int sz=0;
	for(auto [num,pos]:vec){
		while(s[pos]!=num){
			Ans[sz++]=s[pos];
			s[pos]=nxt++;
		}
	}
	return sz;
}

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

typedef long long ll;

const ll mod=1e9+9;

ll binpow(ll a,ll b){
	ll res=1;
	while(b>0){
		if(b&1)res*=a,res%=mod;
		a*=a,a%=mod;
		b>>=1;
	}
	return res;
}

int countReplacement(int n, int Seq[]){
	if(!valid(n,Seq))return 0;
	vector<int> s(n);
	vector<int> vec;
	ll ans=n;
	for(int i=0;i<n;i++){
		if(Seq[i]<=n)s[i]=Seq[i],ans=1;
		else vec.emplace_back(Seq[i]);
	}
	sort(vec.rbegin(),vec.rend());
	vec.emplace_back(n);
	for(int i=1;i<vec.size();i++){
		ans*=binpow(i,vec[i-1]-vec[i]-1);
		ans%=mod;
	}
	return (int)ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:41:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   41 |  for(auto [num,pos]:vec){
      |           ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:77:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  for(int i=1;i<vec.size();i++){
      |              ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 2516 KB Output is correct
7 Correct 7 ms 1492 KB Output is correct
8 Correct 26 ms 4524 KB Output is correct
9 Correct 7 ms 1620 KB Output is correct
10 Correct 24 ms 5236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 10 ms 2516 KB Output is correct
7 Correct 7 ms 1492 KB Output is correct
8 Correct 26 ms 4584 KB Output is correct
9 Correct 7 ms 1684 KB Output is correct
10 Correct 25 ms 5220 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 304 KB Output is correct
13 Correct 14 ms 2484 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 33 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 10 ms 980 KB Output is correct
12 Correct 9 ms 1176 KB Output is correct
13 Correct 14 ms 1396 KB Output is correct
14 Correct 8 ms 1068 KB Output is correct
15 Correct 19 ms 2404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 220 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 36 ms 4788 KB Output is correct
10 Correct 30 ms 3940 KB Output is correct
11 Correct 11 ms 1580 KB Output is correct
12 Correct 12 ms 1876 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 35 ms 4776 KB Output is correct
10 Correct 28 ms 4040 KB Output is correct
11 Correct 10 ms 1612 KB Output is correct
12 Correct 14 ms 1900 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 43 ms 5580 KB Output is correct
15 Correct 51 ms 6308 KB Output is correct
16 Correct 8 ms 1408 KB Output is correct
17 Correct 31 ms 4356 KB Output is correct
18 Correct 17 ms 2548 KB Output is correct