# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
844755 | vjudge1 | Knjige (COCI20_knjige) | C++17 | 3 ms | 1496 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll MAXN = 5005;
vector<int> A, srt;
string put(string hand, string shelf) {
return "STAVI " + hand + " " + shelf + "\n";
}
string take(string hand, string shelf) {
return "UZMI " + hand + " " + shelf + "\n";
}
int main() {
fast
int N;
cin >> N;
A = vector<int>(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
srt.push_back(A[i]);
}
sort(srt.begin(), srt.end());
stack<int> l, r;
vector<string> ans;
for (int i = N-1; i >= 0; i--)
l.push(A[i]);
while (l.size()) {
while (l.size() && srt.back() != l.top()) {
ans.push_back(take("L", "L"));
ans.push_back(put("L", "D"));
r.push(l.top());
l.pop();
}
ans.push_back(take("D", "L"));
l.pop();
while (l.size()) {
ans.push_back(take("L", "L"));
ans.push_back(put("L", "D"));
r.push(l.top());
l.pop();
}
ans.push_back(put("D", "L"));
while (r.size()) {
ans.push_back(take("L", "D"));
ans.push_back(put("L", "L"));
l.push(r.top());
r.pop();
}
srt.pop_back();
}
cout << ans.size() << "\n";
for (auto u : ans)
cout << u;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |