답안 #881027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881027 2023-11-30T11:22:20 Z HossamHero7 Knjige (COCI20_knjige) C++14
50 / 50
1 ms 988 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
    int n;
    cin>>n;
    deque<int> st1 , st2;
    vector<int> vv;
    for(int i=0;i<n;i++) {
        int x;cin>>x;
        st1.push_back(x);
        vv.push_back(x);
    }
    sort(vv.begin(),vv.end());
    vector<string> ans;
    bool b = 1;
    while(st1.size()){
        if(st1.front() == vv.back() && b){
            ans.push_back("UZMI L L");
            b = 0;
            st1.pop_front();
        }
        else {
            ans.push_back("UZMI D L");
            ans.push_back("STAVI D D");
            st2.push_front(st1.front());
            st1.pop_front();
        }
    }
    ans.push_back("STAVI L L");
    int tar = vv.size();
    tar -= 2;
    while(st2.size() && tar>=0){
        if(st2.front() == vv[tar]){
            ans.push_back("UZMI L D");
            st2.pop_front();
            while(st1.size()){
                ans.push_back("UZMI D L");
                ans.push_back("STAVI D D");
                st2.push_front(st1.front());
                st1.pop_front();
            }
            ans.push_back("STAVI L L");
            tar --;
        }
        else {
            ans.push_back("UZMI D D");
            ans.push_back("STAVI D L");
            st1.push_front(st2.front());
            st2.pop_front();
        }
    }
    cout<<ans.size()<<endl;
    for(auto i : ans) cout<<i<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 988 KB Output is correct
2 Correct 1 ms 988 KB Output is correct
3 Correct 1 ms 984 KB Output is correct
4 Correct 1 ms 984 KB Output is correct
5 Correct 1 ms 988 KB Output is correct
6 Correct 1 ms 988 KB Output is correct
7 Correct 1 ms 728 KB Output is correct
8 Correct 1 ms 988 KB Output is correct
9 Correct 1 ms 988 KB Output is correct
10 Correct 1 ms 988 KB Output is correct