#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
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;
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
1768 KB |
Output is correct |
2 |
Correct |
85 ms |
2684 KB |
Output is correct |
3 |
Correct |
80 ms |
2536 KB |
Output is correct |
4 |
Correct |
98 ms |
2536 KB |
Output is correct |
5 |
Correct |
81 ms |
2536 KB |
Output is correct |
6 |
Correct |
73 ms |
2536 KB |
Output is correct |
7 |
Correct |
47 ms |
1516 KB |
Output is correct |
8 |
Correct |
66 ms |
1768 KB |
Output is correct |
9 |
Correct |
78 ms |
2536 KB |
Output is correct |
10 |
Correct |
96 ms |
2536 KB |
Output is correct |