Submission #739175

# Submission time Handle Problem Language Result Execution time Memory
739175 2023-05-10T06:11:20 Z Unforgettablepl Knjige (COCI20_knjige) C++17
50 / 50
2 ms 468 KB
/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
//#define f first
//#define s second
//#define x first
//#define y second
const int INF = INT32_MAX;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("measurement.in","r",stdin);
//    freopen("measurement.out","w",stdout);
    int n;
    cin >> n;
    vector<ll> arr(n);
    for(ll&i:arr)cin>>i;
    stack<ll> left;
    stack<ll> right;
    for (int i = n-1; i >= 0; i--) {
        left.emplace(arr[i]);
    }
    sort(all(arr));
    vector<array<bool,3>> instructions;
    for (int i = 0; i < n; i++) {
        ll target = arr[i];
        int mis = 0;
        while(left.top()!=target){
//            cout << "UZMI L L\nSTAVI L R\n";
            instructions.push_back({false,false,false});
            instructions.push_back({true,false,true});
            right.emplace(left.top());
            left.pop();
            mis++;
        }
//        cout << "UZMI R L\n";
        instructions.push_back({false,true,false});
        left.pop();
        while(mis--){
//            cout << "UZMI L R\nSTAVI L L\n";
            instructions.push_back({false,false,true});
            instructions.push_back({true,false,false});
            left.emplace(right.top());
            right.pop();
        }
//        cout << "STAVI R R\n";
        instructions.push_back({true,true,true});
        right.emplace(target);
    }
    assert(left.empty());
    assert(right.size()==n);
    for (int i = 0; i < n; i++) {
//        cout << "UZMI L R\nSTAVI L L\n";
        instructions.push_back({false,false,true});
        instructions.push_back({true,false,false});
    }
    cout << instructions.size() << '\n';
    for(auto&i:instructions) {
        if(i[0]){
            cout << "STAVI ";
        } else {
            cout << "UZMI ";
        }
        if(i[1]){
            cout << "D ";
        } else {
            cout << "L ";
        }
        if(i[2]){
            cout << "D\n";
        } else {
            cout << "L\n";
        }
    }
}

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:6:
Main.cpp: In function 'int main()':
Main.cpp:60:24: warning: comparison of integer expressions of different signedness: 'std::stack<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |     assert(right.size()==n);
      |            ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct