QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#421207 | #6822. Bracket Query | kjhhjki | WA | 0ms | 3864kb | C++20 | 1.7kb | 2024-05-25 15:20:19 | 2024-05-25 15:20:20 |
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);
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: 0ms
memory: 3820kb
input:
4 1 1 2 0
output:
! ()()
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4 1 1 2 2
output:
! (())
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 2 1 1 1 2 2 -1
output:
! ()
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
2 1 1 1 2
output:
?
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
4 0
output:
! (())
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
8 2 1 5 1 3 7 1
output:
! ()(()())
result:
ok ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
3000 0
output:
! ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...
result:
ok ok
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3624kb
input:
2 1 1 2 2
output:
! ((
result:
wrong answer bad bracket sequence