QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#357961 | #6822. Bracket Query | crsfaa# | WA | 0ms | 3784kb | C++14 | 1.3kb | 2024-03-19 15:42:37 | 2024-03-19 15:42:37 |
Judging History
answer
#include<bits/stdc++.h>
#define Yukinoshita namespace
#define Yukino std
using Yukinoshita Yukino;
int read()
{
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9') w=ch=='-'?-1:1,ch=getchar();
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
const int mxn=3005;
vector<pair<int,int>> a[mxn];
int s[mxn];
void dfs(int d)
{
for(auto i:a[d])
{
if(s[d]+i.second<0)
{
cout<<"?";
exit(0);
}
if(s[i.first]==-1)
s[i.first]=s[d]+i.second,dfs(i.first);
else if(s[i.first]!=s[d]+i.second)
{
cout<<"?";
exit(0);
}
}
}
/*
4 1
1 2 0
*/
int main()
{
memset(s,-1,sizeof(s));
int n=read(),q=read();
while(q--)
{
int l=read(),r=read(),c=read();//sr-s[l-1]=c
a[l-1].push_back({r,c});
a[r].push_back({l-1,-c});
}
s[0]=s[n]=0,dfs(0),dfs(n);
int lst=0,i;
for(i=1;i<=n;i++)
if(s[i]!=-1)
{
// cout<<i<<':'<<lst<<endl;
if((s[lst]+s[i])%2!=(i-lst)%2||abs(s[lst]-s[i])>i-lst)
{
cout<<"?";
exit(0);
}
// puts("233");
for(lst++;lst<i;lst++)
if(s[lst-1]<=s[i])
s[lst]=s[lst-1]+1;
else
s[lst]=s[lst-1]-1;
}
// for(i=0;i<=n;i++)
// cout<<s[i]<<' ';
// puts("");
cout<<"! ";
for(i=1;i<=n;i++)
putchar(s[i]>s[i-1]?'(':')');
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
4 1 1 2 0
output:
! ()()
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
4 1 1 2 2
output:
! (())
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
2 2 1 1 1 2 2 -1
output:
! ()
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
2 1 1 1 2
output:
?
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
4 0
output:
! ()()
result:
ok ok
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3652kb
input:
8 2 1 5 1 3 7 1
output:
! (()())()
result:
wrong answer requirement not satisified