답안 #489274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489274 2021-11-21T21:45:08 Z inksamurai Knjige (COCI20_knjige) C++17
50 / 50
5 ms 844 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _3HIYw7x ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;

int main(){
_3HIYw7x;
	int n;
	cin>>n;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	vi _a=a;
	sort(all(_a));
	reverse(all(_a));
	vi l,r;
	l=a;
	reverse(all(l));
	vec(tuple<int,int,int>) pans;
	auto take=[&](int t,int t1){
		pans.pb({0,t,t1});
	};
	auto put=[&](int t,int t1){
		pans.pb({1,t,t1});
	};
	rep(i,n){
		int x=_a[i];
		while(sz(l) and l.back()!=x){
			take(0,0);
			put(0,1);
			r.pb(l.back());
			l.pop_back();
		}
		take(1,0);
		l.pop_back();
		while(sz(l)){
			take(0,0);
			put(0,1);
			r.pb(l.back());
			l.pop_back();
		}
		put(1,0);
		while(sz(r)){
			take(0,1);
			put(0,0);
			l.pb(r.back());
			r.pop_back();
		}
	}
	cout<<sz(pans)<<"\n";
	for(auto [t,h,b] : pans){
		if(t==0){
			cout<<"UZMI ";
		}else{
			cout<<"STAVI ";
		}
		cout<<(h==0?"L":"D")<<" "<<(b==0?"L":"D")<<"\n";
	}
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 844 KB Output is correct
3 Correct 3 ms 844 KB Output is correct
4 Correct 5 ms 844 KB Output is correct
5 Correct 3 ms 844 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
7 Correct 3 ms 844 KB Output is correct
8 Correct 3 ms 844 KB Output is correct
9 Correct 3 ms 844 KB Output is correct
10 Correct 5 ms 844 KB Output is correct