# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378409 |
2021-03-16T17:22:57 Z |
Araragi |
Knjige (COCI20_knjige) |
C++17 |
|
10 ms |
1772 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("00")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
ll time() {return chrono::system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
const int inf = 1e9;
const ll inf64 = 1e18;
#define ft first
#define fin(x) ifstream cin("x.in");
#define fout(x) ofstream cout("x.out");
#define sd second
#define pb push_back
#define sz(x) (int)x.size()
int hand[2];
vector<int> a[2];
vector<string> cmd;
vector<int> num;
bool cmp(int& x, int& y) {return (a[0][x] < a[0][y]);}
void get(int fst, int scd) {
cmd.pb((string)"UZMI " + (fst ? "D" : "L") + " " + (scd ? "D" : "L"));
hand[fst] = a[scd].back();
a[scd].pop_back();
}
void put(int fst, int scd) {
cmd.pb((string)"STAVI " + (fst ? "D" : "L") + " " + (scd ? "D" : "L"));
a[scd].pb(hand[fst]);
hand[fst] = 0;
}
void nande(int where) {cerr << "called debug procedure...\n"; for (auto it : a[where]) cerr << it << " "; cerr << '\n'; cerr << "ended'\n";}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
system("color 2");
int n;
cin >> n;
a[0].resize(n);
num.resize(n);
for (int i = 0; i < n; i++)
cin >> a[0][i];
if (is_sorted(a[0].begin(), a[0].end()))
{
cout << "0";
return 0;
}
iota(num.begin(), num.end(), 0);
sort(num.begin(), num.end(), cmp);
for (int i = 0; i < n; i++)
a[0][num[i]] = i + 1;
reverse(a[0].begin(), a[0].end());
// 0 - LEFT, 1 - DANTE
// get(fst, scd), put(fst, scd) (fst - hand, scd - shelf)
//int cnt = 0;
for (int i = 0; i < n; i++)
{
//nande(0);
while (a[0].back() != i + 1)
{
get(0, 0);
put(0, 1);
// cnt++;
}
get(1, 0);
//nande(0);
//nande(1);
while ((i > 0 ? a[1].back() != i : !a[1].empty()))
{
get(0, 1);
put(0, 0);
}
//nande(0);
//nande(1);
put(1, 0);
//nande(0);
//nande(1);
while (!a[1].empty())
{
get(0, 1);
put(0, 0);
}
//nande(0);
//nande(1);
}
cout << sz(cmd) << '\n';
for (auto it : cmd)
cout << it << '\n';
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:43:11: warning: ignoring return value of 'int system(const char*)', declared with attribute warn_unused_result [-Wunused-result]
43 | system("color 2");
| ~~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1772 KB |
Output is correct |
2 |
Correct |
10 ms |
1752 KB |
Output is correct |
3 |
Correct |
8 ms |
1752 KB |
Output is correct |
4 |
Correct |
8 ms |
1752 KB |
Output is correct |
5 |
Correct |
8 ms |
1752 KB |
Output is correct |
6 |
Correct |
7 ms |
1752 KB |
Output is correct |
7 |
Correct |
8 ms |
1752 KB |
Output is correct |
8 |
Correct |
7 ms |
1752 KB |
Output is correct |
9 |
Correct |
8 ms |
1752 KB |
Output is correct |
10 |
Correct |
8 ms |
1752 KB |
Output is correct |