답안 #1006579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006579 2024-06-24T04:01:15 Z vjudge1 Knjige (COCI20_knjige) C++17
50 / 50
24 ms 1492 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
int const N=5e5+5;
int const mod=1e9+7;

int main(){
    int n;
    cin>>n;
    stack<int> lst,rst;
    vector<int> v;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        v.push_back(a);
    }
    for(int i=n-1;i>=0;i--)
        lst.push(v[i]);
    vector<string> move;
    for(int i=0;i<n;i++){
        int rh=-1;
        while(lst.size()>i){
            if(rh==-1){
                //take the book on top of left in your rh
                move.push_back("UZMI D L");
                rh=lst.top();
                lst.pop();
            }
            else if(rh<=lst.top()){
                //put rh book on top of right.
                move.push_back("STAVI D D");
                rst.push(rh);
                //take the book from top of left in your rh
                move.push_back("UZMI D L");
                rh=lst.top();
                lst.pop();
            }
            else{
                rst.push(lst.top());
                //take the book from top of left in your lh
                move.push_back("UZMI L L");
                lst.pop();
                //put lh book on top of right.
                move.push_back("STAVI L D");
            }
        }
        //place book in your rh on top of left
        move.push_back("STAVI D L");
        lst.push(rh);
        while(!rst.empty()){
            lst.push(rst.top());
            //take book in your lh from top of right
            move.push_back("UZMI L D");
            rst.pop();
            //place book in your lh on top of left.
            move.push_back("STAVI L L");
        }
    }
    cout<<move.size()<<endl;
    for (string s:move)
        cout<<s<<endl;
    return 0;
}

Compilation message

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