# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378908 | topovik | Knjige (COCI20_knjige) | C++14 | 98 ms | 2684 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 ", "D "};
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |