답안 #452046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
452046 2021-08-03T16:48:07 Z PiejanVDC Knjige (COCI20_knjige) C++17
25 / 50
2 ms 712 KB
#include <bits/stdc++.h>
using namespace std;

signed main() {
    int n; cin>>n;
    vector<int>sorted(n);
    stack<int>l,r;
    for(int i = 0 ; i < n ; i++) {
        cin>>sorted[i];
    }
    for(int i = n-1 ; i >= 0 ; i--) l.push(sorted[i]);
    vector<string>ans;

    int cnt=0;
    sort(sorted.rbegin(),sorted.rend());
    bool f = true;
    for(int i = 0 ; i < n ; i++) {
        int t = sorted[i];
        if(f) {
            assert(l.size() == n-i);
            for(int j = 0 ; j < n - i ; j++) {
                if(l.top() != t) r.push(l.top()), ans.push_back("UZMI D L\nSTAVI D D\n"),cnt+=2;
                else ans.push_back("UZMI L L\n"),cnt++;
                l.pop();
            }
            ans.push_back("STAVI L L\n");
            cnt++;
            l.push(t);
            f=false;
        } else {
            while(true) {
                if(r.top() == t) break;
                ans.push_back("UZMI D D\nSTAVI D L\n");
                cnt+=2;
                l.push(r.top());
                r.pop();
            }
            ans.push_back("UZMI L D\n");
            cnt++;
            r.pop();
            while(l.size() > i) {
                r.push(l.top());
                l.pop();
                ans.push_back("UZMI D L\nSTAVI D D\n");
                cnt+=2;
            }
            l.push(t);
            ans.push_back("STAVI L L\n");
            cnt++;
        }
    }
    cout << cnt << "\n";
    for(auto z : ans) cout << z;
    return 0;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from Main.cpp:1:
Main.cpp: In function 'int main()':
Main.cpp:20:29: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |             assert(l.size() == n-i);
      |                    ~~~~~~~~~^~~~~~
Main.cpp:41:28: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |             while(l.size() > i) {
      |                   ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Runtime error 1 ms 332 KB Execution killed with signal 11
3 Runtime error 1 ms 332 KB Execution killed with signal 11
4 Correct 1 ms 628 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Runtime error 1 ms 332 KB Execution killed with signal 11
7 Runtime error 1 ms 332 KB Execution killed with signal 11
8 Correct 1 ms 588 KB Output is correct
9 Correct 2 ms 712 KB Output is correct
10 Correct 1 ms 588 KB Output is correct