Submission #378905

# Submission time Handle Problem Language Result Execution time Memory
378905 2021-03-17T07:20:48 Z topovik Knjige (COCI20_knjige) C++14
0 / 50
87 ms 2684 KB
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
//#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e18)
#define el '\n'
#define pii pair <int, int>
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
#define vi vector<int>
#define pb push_back
#define len(x) (int)x.size()
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 1e6;
const string take = "UZMI ";
const string put  = "STAVI ";
const string dir[2] = {"L ", "R "};

bool Check(vector <int> a)
{
    for (int i = 1; i < a.size(); i++)
        if (a[i] > a[i - 1]) return 1;
    return 0;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector <int> a;
	for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a.pb(x);
    }
    reverse(a.begin(), a.end());
	vector <int> b;
	vector <string> ans;
	while (Check(a))
    {
        int val[2] = {-1, -1};
        while (a.size() > 0)
        {
            if (val[0] == -1 || val[1] == -1)
            {
                if (val[0] == -1) ans.pb(take + dir[0] + dir[0]), val[0] = a.back();
                else              ans.pb(take + dir[1] + dir[0]), val[1] = a.back();
            }
            if (val[1] != -1)
            {
                if (val[0] < val[1]) ans.pb(put + dir[0] + dir[1]), b.pb(val[0]), val[0] = -1;
                else                 ans.pb(put + dir[1] + dir[1]), b.pb(val[1]), val[1] = -1;
            }
            a.pop_back();
        }
        if (val[1] != -1) ans.pb(put + dir[1] + dir[1]), b.pb(val[1]);
        else              ans.pb(put + dir[0] + dir[1]), b.pb(val[0]);
        while (b.size() > 0)
        {
            ans.pb(take + dir[1] + dir[1]);
            ans.pb(put + dir[1] + dir[0]);
            a.pb(b.back());
            b.pop_back();
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
}

Compilation message

Main.cpp: In function 'bool Check(std::vector<int>)':
Main.cpp:37:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i = 1; i < a.size(); i++)
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 1768 KB Token "R" doesn't correspond to pattern "(L|D)"
2 Incorrect 87 ms 2536 KB Token "R" doesn't correspond to pattern "(L|D)"
3 Incorrect 75 ms 2536 KB Token "R" doesn't correspond to pattern "(L|D)"
4 Incorrect 86 ms 2536 KB Token "R" doesn't correspond to pattern "(L|D)"
5 Incorrect 80 ms 2536 KB Token "R" doesn't correspond to pattern "(L|D)"
6 Incorrect 74 ms 2536 KB Token "R" doesn't correspond to pattern "(L|D)"
7 Incorrect 49 ms 1516 KB Token "R" doesn't correspond to pattern "(L|D)"
8 Incorrect 81 ms 1896 KB Token "R" doesn't correspond to pattern "(L|D)"
9 Incorrect 77 ms 2536 KB Token "R" doesn't correspond to pattern "(L|D)"
10 Incorrect 80 ms 2684 KB Token "R" doesn't correspond to pattern "(L|D)"