Submission #64313

# Submission time Handle Problem Language Result Execution time Memory
64313 2018-08-04T04:38:19 Z kylych03 Zalmoxis (BOI18_zalmoxis) C++14
100 / 100
463 ms 33196 KB
# include <bits/stdc++.h>

using namespace std;
vector < int > vec[1000001];
int cnt=0;
void fun(int i,int j){
	if(cnt<=0)
	return;
	if(vec[i].size()<=j)
		return;
	if(vec[i][j]<=0)
	{
		fun(i,j+1);
		return;
	}
	
	vec[i][j]--;
	vec[i].insert(vec[i].begin()+j, vec[i][j]);
	cnt--;
	fun(i,j);
		
}
int main(){
	int n,k,i,a[1000001];

	cin>>n>>k;
	
	for(i=0;i<n;i++)
		cin>>a[i];
	deque <int> dq;
	dq.push_back(30);
	i=0;
	while(i<n){
		if(dq.front() > a[i]){
			
			dq.front()--;
			dq.push_front(dq.front());
		}
		else
		if(dq.front()==a[i]){
			i++;
			dq.pop_front();
		}
		else
		if(dq.front() < a[i]){
			
			vec[i].push_back(dq.front());
			dq.pop_front();
			cnt++;
		}
	}
	while(dq.size()>0){
		vec[n].push_back(dq.front());
		dq.pop_front();
		cnt++;
	}
	
	cnt=k-cnt;
	
	
	for(i=0;i<=n;i++){
		
		if(cnt!=0 && vec[i].size()>0)
			fun(i,0);
	}
	for(i=0;i<n;i++){
		for(int j=0;j<vec[i].size();j++)
			cout<<vec[i][j]<<" ";
		cout<<a[i]<<" ";
	}
	for(int j=0;j<vec[n].size();j++)
			cout<<vec[n][j]<<" ";
}

Compilation message

zalmoxis.cpp: In function 'void fun(int, int)':
zalmoxis.cpp:9:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(vec[i].size()<=j)
     ~~~~~~~~~~~~~^~~
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<vec[i].size();j++)
               ~^~~~~~~~~~~~~~
zalmoxis.cpp:71:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j=0;j<vec[n].size();j++)
              ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 463 ms 29772 KB Output is correct
2 Correct 420 ms 29880 KB Output is correct
3 Correct 364 ms 30072 KB Output is correct
4 Correct 416 ms 30072 KB Output is correct
5 Correct 316 ms 30072 KB Output is correct
6 Correct 369 ms 30072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 440 ms 30072 KB Output is correct
2 Correct 381 ms 30152 KB Output is correct
3 Correct 411 ms 30176 KB Output is correct
4 Correct 321 ms 30176 KB Output is correct
5 Correct 429 ms 30176 KB Output is correct
6 Correct 346 ms 30176 KB Output is correct
7 Correct 461 ms 30176 KB Output is correct
8 Correct 317 ms 30216 KB Output is correct
9 Correct 340 ms 33068 KB Output is correct
10 Correct 229 ms 33068 KB Output is correct
11 Correct 311 ms 33196 KB Output is correct
12 Correct 154 ms 33196 KB Output is correct
13 Correct 178 ms 33196 KB Output is correct
14 Correct 167 ms 33196 KB Output is correct