QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141604 | #2143. Railroad sorting | emailam# | WA | 1ms | 3588kb | C++20 | 1.6kb | 2023-08-17 17:47:02 | 2023-08-17 17:47:05 |
Judging History
answer
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cin.tie(nullptr), cout.tie(nullptr);
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;
void solve() {
int n;
cin >> n;
int arr[n];
int inStack[n + 1];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
inStack[arr[i]] = -1;
}
stack<int> s1, s2;
int now = 1;
for (int i = 0; i < n; ++i) {
inStack[arr[i]] = 1;
s1.push(arr[i]);
cout << "1\n";
if (inStack[now] != -1) {
stack<int> &s = (inStack[now] == 1 ? s1 : s2);
stack<int> &other = (inStack[now] == 1 ? s2 : s1);
string cmd = (inStack[now] == 1 ? "12\n" : "21\n");
while (s.top() != now) {
cout << cmd;
inStack[s.top()] = cmd[1] - '0';
other.push(s.top());
s.pop();
}
s.pop();
cout << (inStack[now] == 1 ? "-1\n" : "-2\n");
now++;
}
}
while (now != n + 1) {
stack<int> &s = (inStack[now] == 1 ? s1 : s2);
stack<int> &other = (inStack[now] == 1 ? s2 : s1);
string cmd = (inStack[now] == 1 ? "12\n" : "21\n");
while (s.top() != now) {
cout << cmd;
inStack[s.top()] = cmd[1] - '0';
other.push(s.top());
s.pop();
}
cout << (inStack[now] == 1 ? "-1\n" : "-2\n");
now++;
}
}
signed main() {
io
int t;
t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3572kb
input:
5 3 1 5 2 4
output:
1 1 -1 1 1 -1 1 12 12 -1 21 -2 -1
result:
ok 13 steps
Test #2:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
1 1
output:
1 -1
result:
ok 2 steps
Test #3:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
2 1 2
output:
1 -1 1 -1
result:
ok 4 steps
Test #4:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
2 2 1
output:
1 1 -1 -1
result:
ok 4 steps
Test #5:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
3 1 2 3
output:
1 -1 1 -1 1 -1
result:
ok 6 steps
Test #6:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
3 1 3 2
output:
1 -1 1 1 -1 -1
result:
ok 6 steps
Test #7:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
3 2 1 3
output:
1 1 -1 1 12 -1 -2
result:
ok 7 steps
Test #8:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
3 2 3 1
output:
1 1 1 -1 12 -1 -2
result:
ok 7 steps
Test #9:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
3 3 1 2
output:
1 1 -1 1 -1 -1
result:
ok 6 steps
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 3572kb
input:
3 3 2 1
output:
1 1 1 -1 -1 12 -1
result:
wrong answer no car to take from stack 1, step 7