답안 #445944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445944 2021-07-20T08:37:28 Z Jasiekstrz Knjige (COCI20_knjige) C++17
50 / 50
5 ms 1484 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e5;
int h[2]={-1,-1};
vector<int> st[2];
vector<string> ans;
void take(bool hand,bool shelf)
{
	h[hand]=st[shelf].back();
	st[shelf].pop_back();
	ans.push_back((string)"UZMI "+(hand ? "D":"L")+" "+(shelf ? "D":"L"));
	return;
}
void put(bool hand,bool shelf)
{
	st[shelf].push_back(h[hand]);
	h[hand]=-1;
	ans.push_back((string)"STAVI "+(hand ? "D":"L")+" "+(shelf ? "D":"L"));
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	st[0].resize(n);
	for(int i=1;i<=n;i++)
		cin>>st[0][n-i];
	while(!st[0].empty())
	{
		take(0,0);
		put(0,1);
	}
	for(int i=0;i<n;i++)
	{
		take(0,1);
		while(!st[1].empty())
		{
			if(st[1].back()>h[0])
			{
				put(0,0);
				take(0,1);
			}
			else
			{
				take(1,1);
				put(1,0);
			}
		}
		while(st[0].size()>i)
		{
			take(1,0);
			put(1,1);
		}
		put(0,0);
	}
	cout<<ans.size()<<"\n";
	for(auto v:ans)
		cout<<v<<"\n";
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:54:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |   while(st[0].size()>i)
      |         ~~~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1484 KB Output is correct
2 Correct 4 ms 1484 KB Output is correct
3 Correct 4 ms 1484 KB Output is correct
4 Correct 4 ms 1484 KB Output is correct
5 Correct 4 ms 1484 KB Output is correct
6 Correct 4 ms 1484 KB Output is correct
7 Correct 4 ms 1484 KB Output is correct
8 Correct 5 ms 1356 KB Output is correct
9 Correct 4 ms 1484 KB Output is correct
10 Correct 4 ms 1484 KB Output is correct