QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363766 | #8509. Expanding STACKS! | ucup-team2000# | WA | 0ms | 3844kb | C++20 | 1.7kb | 2024-03-24 03:04:28 | 2024-03-24 03:04:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define f first
#define s second
#define lep(i,a,b) for (int i=(a); i <= (b); i++)
#define rep(i,b,a) for (int i = (b); i >= (a); i--)
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pi> edges;
vector<int> l(n+1), r(n+1);
lep(i,1,2*n) {
int x;
cin >> x;
if (x > 0) l[x] = i;
else r[-x] = i;
}
auto nest = [&](int l1, int r1, int l2, int r2) -> bool {
if (l1 > l2 and r1 < l2) return true;
if (l1 < l2 and r1 > l2) return true;
return false;
};
auto disj = [&](int l1, int r1, int l2, int r2) {
if (l1 > r2 or r1 < l2) return true;
return false;
};
lep(i,1,n) {
lep(j,i+1,n) {
if (!nest(l[i],r[i],l[j],r[j]) or !disj(l[i],r[i],l[j],r[j])) {
edges.pb({i,j});
}
}
}
vector<vector<int>> adj(n+1);
for (auto [u,v]: edges) {
adj[u].pb(v);
adj[v].pb(u);
}
vector<int> color(n+1);
bool ok = true;
auto dfs = [&](auto &self, int u, int p, int c) -> void {
color[u] = c;
for (int v: adj[u]) {
if (color[v] == color[u]) ok = false;
else if (!color[v]) {
self(self,v,u,3-c);
}
}
};
lep(i,1,n) {
if (!color[i]) {
dfs(dfs,i,0,1);
}
}
if (!ok) {
cout << "*\n";
} else {
lep(i,1,n) {
cout << ((color[i] == 1) ? 'G' : 'S');
}
cout << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
2 +2 +1 -1 -2
output:
GS
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
2 +1 +2 -1 -2
output:
GS
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
3 +1 +2 +3 -1 -2 -3
output:
*
result:
ok correct
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3844kb
input:
10 +3 -3 +4 -4 +6 +2 -2 -6 +7 -7 +5 -5 +10 +1 +9 +8 -8 -9 -1 -10
output:
*
result:
wrong answer team and jury output doesn't agree on whether there's an assignment