QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#400706#6822. Bracket Querysgweo8ysWA 1ms3880kbC++142.0kb2024-04-27 15:18:532024-04-27 15:18:53

Judging History

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

  • [2024-04-27 15:18:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3880kb
  • [2024-04-27 15:18:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 300010;
const int M = 2000010;
const int inf = 0x3f3f3f3f;

int n, m, dis[N], tms[N], vis[N], flag = 1;
int head[N], nxt[M], to[M], w[M], cnt;

inline int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

void addedge(int u, int v, int k)
{
    to[++cnt] = v, w[cnt] = k;
    nxt[cnt] = head[u], head[u] = cnt;
}

int main()
{
    n = read(), m = read();
    if(n & 1) flag = 0;
    for(int i = 1; i <= m; i++){
        int u = read(), v = read(), c = read();
        int d = v - u + 1 + c;
        if(d & 1) flag = 0;
        d >>= 1;
        addedge(u - 1, v, d);
        addedge(v, u - 1, -d);
    }
    for(int i = 1; i <= n; i++) addedge(i - 1, i, 1);
    for(int i = 1; i <= n; i++) addedge(i, i - 1, 0);
    for(int i = 1; i <= n; i++) addedge(i, 0, -((i - 1) / 2 + 1));
    addedge(0, n, n / 2);

    if(!flag) return puts("?"), 0;
    dis[n + 1] = 0;
    for(int i = 0; i <= n; i++) dis[i] = inf;
    for(int i = 0; i <= n; i++) addedge(n + 1, i, 0);

    queue <int> q;
    q.push(n + 1), vis[n + 1] = 1;
    while(!q.empty()){
        int u = q.front(); q.pop(); vis[u] = 0;
        tms[u]++;
        if(tms[u] > n + 1) return puts("?"), 0;
        for(int i = head[u]; i; i = nxt[i]){
            int v = to[i];
            if(dis[v] > dis[u] + w[i]){
                dis[v] = dis[u] + w[i];
                if(dis[v] < ((i - 1) / 2 + 1)) return puts("?"), 0;
                if(!vis[v]) vis[v] = 1, q.push(v);
                if(tms[v] > n) return puts("?"), 0;
            }
        }
    }

    int dt = 0 - dis[0];
    for(int i = 0; i <= n; i++) dis[i] += dt;
    putchar('!'), putchar(' ');
    for(int i = 1; i <= n; i++) putchar(dis[i] - dis[i - 1] > 0 ? '(' : ')');
    puts("");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3880kb

input:

4 1
1 2 0

output:

?

result:

wrong answer participant reports no solution but jury has one