QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#421209 | #6822. Bracket Query | kjhhjki | WA | 1ms | 4028kb | C++20 | 1.7kb | 2024-05-25 15:21:50 | 2024-05-25 15:21:50 |
Judging History
answer
#include <bits/stdc++.h>
#define For(i, a, b) for(i32 i = (a), endi = (b); i <= endi; ++i)
#define foR(i, a, b) for(i32 i = (a), endi = (b); i >= endi; --i)
using namespace std;
template<typename T, typename U>
void chkmin(T &a, U b) { if(a > b) a = b; }
using i32 = int;
using i64 = long long;
using f64 = long double;
using pii = pair<i32, i32>;
void init() { }
void solve()
{
i32 n, m;
cin >> n >> m;
vector<vector<pii>> adj(n+2);
adj[n].emplace_back(0, 0); adj[0].emplace_back(n, 0);
For(i, 1, n) adj[i-1].emplace_back(i, 1), adj[i].emplace_back(i-1, 1);
For(i, 1, m)
{
i32 u, v, c;
cin >> u >> v >> c;
--u;
adj[v].emplace_back(u, -c);
adj[u].emplace_back(v, c);
}
deque<i32> q;
vector<i32> dis(n+2, 1e9);
dis[n] = 0;
q.emplace_back(n);
vector<i32> cnt(n+2);
vector<bool> inq(n+2); inq[n] = true;
while(!q.empty())
{
i32 u = q.front(); q.pop_front(); inq[u] = false;
for(auto [v, c]: adj[u])
{
if(dis[v] <= dis[u] + c) continue;
dis[v] = dis[u] + c;
if(inq[v]) continue;
if(!q.empty() && dis[v] > dis[q.front()]) q.push_back(v);
else q.push_front(v);
cnt[v]++; inq[v] = true;
if(cnt[v] > n+2)
{
cout << "?\n";
return;
}
}
}
cout << "! ";
For(i, 1, n)
{
if(dis[i] > dis[i-1]) cout << '(';
else cout << ')';
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
init();
i32 T = 1;
// cin >> T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
4 1 1 2 0
output:
! ()()
result:
ok ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
4 1 1 2 2
output:
! (())
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 2 1 1 1 2 2 -1
output:
! ()
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
2 1 1 1 2
output:
?
result:
ok ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
4 0
output:
! (())
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
8 2 1 5 1 3 7 1
output:
! ()(()())
result:
ok ok
Test #7:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
3000 0
output:
! ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
result:
ok ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
2 1 1 2 2
output:
?
result:
ok ok
Test #9:
score: 0
Accepted
time: 1ms
memory: 4028kb
input:
3000 1 1 3000 0
output:
! ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
result:
ok ok
Test #10:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
8 2 1 6 2 3 7 1
output:
! ()((()))
result:
ok ok
Test #11:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
3000 3 1111 1113 3 1112 1114 -1 1113 1115 3
output:
?
result:
ok ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
2 1 1 2 -2
output:
?
result:
ok ok
Test #13:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
114 13 3 98 14 5 100 10 7 102 6 12 107 -4 11 106 -2 14 109 -8 6 101 8 10 105 0 19 114 -18 1 96 18 9 104 2 16 111 -12 18 113 -16
output:
! ((((((((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))))))))))
result:
ok ok
Test #14:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
114 7 3 109 -1 5 111 -1 6 112 1 8 114 1 2 108 1 1 107 1 4 110 1
output:
! (()()))((((((((((((((((((((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))))))))))))))))))()()())
result:
wrong answer bad bracket sequence