QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#362639 | #8509. Expanding STACKS! | ucup-team1191# | WA | 0ms | 3752kb | C++20 | 1.5kb | 2024-03-23 16:27:48 | 2024-03-23 16:27:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)
const int M = 1010;
bool edge(int l1, int r1, int l2, int r2) {
if (l2 < l1) {
swap(l1, l2);
swap(r1, r2);
}
return l2 < r1 && r2 > r1;
}
int n;
int l[M], r[M];
int seq[2 * M];
int col[M];
void dfs(int p, int c) {
col[p] = c;
for (int i = 0; i < n; i++) {
if (i == p || !edge(l[i], r[i], l[p], r[p])) {
continue;
}
if (col[i] == -1) {
dfs(i, 1 - c);
} else {
if (col[i] == col[p]) {
cout << "*\n";
exit(0);
}
}
}
}
void solve() {
cin >> n;
for (int i = 0; i < 2 * n; i++) {
cin >> seq[i];
if (seq[i] > 0) {
l[seq[i] - 1] = i;
} else {
r[-seq[i] - 1] = i;
}
}
for (int i = 0; i < n; i++) {
col[i] = -1;
}
for (int i = 0; i < n; i++) {
if (col[i] == -1) {
dfs(i, 0);
}
}
for (int i = 0; i < 2 * n; i++) {
if (seq[i] < 0) {
int p = -seq[i] - 1;
cout << "GS"[col[p]];
}
}
cout << "\n";
}
int main() {
#ifdef ONPC
freopen("input", "r", stdin);
#endif
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
input:
2 +2 +1 -1 -2
output:
GG
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
2 +1 +2 -1 -2
output:
GS
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
3 +1 +2 +3 -1 -2 -3
output:
*
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
10 +3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10
output:
GGGGGGGGGG
result:
ok correct
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3696kb
input:
10 +8 -8 +2 +10 -2 -10 +7 -7 +1 -1 +6 -6 +5 +3 +4 +9 -9 -4 -3 -5
output:
GGSGGGGGGG
result:
wrong answer client leaving is not the top of its stack