QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406592#6822. Bracket Queryjames1BadCreeperWA 0ms3872kbC++171.6kb2024-05-07 14:51:082024-05-07 14:51:10

Judging History

你现在查看的是最新测评结果

  • [2024-05-07 14:51:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3872kb
  • [2024-05-07 14:51:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5; 

int n, q; 
int fa[N], d[N], inq[N], cnt[N]; 
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
vector<pair<int, int>> G[N]; 
vector<tuple<int, int, int>> chk; 

int main(void) {
    ios::sync_with_stdio(0); 
    cin >> n >> q; 

    for (int i = 1; i <= n; ++i) G[i].emplace_back(i - 1, 1), G[i - 1].emplace_back(i, 1); 
    for (int i = 1; i < n; ++i) G[i].emplace_back(0, 0); 
    G[0].emplace_back(n, 0); G[n].emplace_back(0, 0); 

    for (int i = 1; i <= n; ++i) fa[i] = i; 
    for (int i = 1; i <= q; ++i) {
        int x, y, z; cin >> x >> y >> z; 
        if ((x + y + 1) % 2 != z % 2) return cout << "?", 0; 
        if (find(x - 1) != find(y))
            fa[find(x - 1)] = find(y), 
            G[y].emplace_back(x - 1, -z), 
            G[x - 1].emplace_back(y, z); 
        else chk.emplace_back(x, y, z); 
    }

    memset(d, 0x3f, sizeof d); queue<int> q; 
    d[0] = 0; inq[0] = 1; q.push(0); 
    while (!q.empty()) {
        int u = q.front(); q.pop(); inq[u] = 0; 
        for (auto [v, w] : G[u]) if (d[v] > d[u] + w) {
            d[v] = d[u] + w; cnt[v] = cnt[u] + 1; 
            if (cnt[v] > n + 2) return cout << "?\n", 0; 
            if (!inq[v]) q.push(v); 
        }
    }

    for (auto [x, y, z] : chk)
        if (d[y] - d[x - 1] != z) return cout << "?\n", 0; 
     
    cout << "! "; 
    for (int i = 1; i <= n; ++i)
        if (d[i] > d[i - 1]) cout << '('; 
        else cout << ')'; 
    cout << "\n"; 
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3656kb

input:

4 1
1 2 0

output:

! ()()

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

4 1
1 2 2

output:

! (())

result:

ok ok

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3608kb

input:

2 2
1 1 1
2 2 -1

output:

?

result:

wrong answer participant reports no solution but jury has one