QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#846382 | #23. Brackets | mnbvcxz123 | 0 | 7ms | 4080kb | C++14 | 1.2kb | 2025-01-07 07:49:31 | 2025-01-07 07:49:32 |
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=210,M=2010,Lim=2e18+1;
int n,m,s,t;
int f[N][N];
vector<pair<int,char>>eg[N],ge[N];
struct Item{
int w,u,v;
bool operator>(const Item&t)const{
return w>t.w;
}
};
bool match(char u,char v){
if(u=='(')return v==')';
if(u=='[')return v==']';
if(u=='{')return v=='}';
if(u=='<')return v=='>';
return false;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>s>>t;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i!=j)f[i][j]=Lim;
while(m--){
int u,v;char ch;
cin>>u>>v>>ch;
eg[u].push_back({v,ch});
ge[v].push_back({u,ch});
}
priority_queue<Item,vector<Item>,greater<Item>>q;
for(int i=1;i<=n;i++)q.push({0,i,i});
while(q.size()){
int w=q.top().w,u=q.top().u,v=q.top().v;q.pop();
if(w!=f[u][v])continue;
// cerr<<"F "<<u<<' '<<v<<' '<<w<<'\n';
for(auto pu:ge[u])
for(auto pv:eg[v])
if(match(pu.second,pv.second)){
if(w+2<f[pu.first][pv.first]){
f[pu.first][pv.first]=w+2;
q.push({w+2,pu.first,pv.first});
}
}
}
if(f[s][t]==Lim){
cout<<-1;
}
else{
cout<<f[s][t];
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
10 50 6 8 1 6 { 5 10 < 7 10 [ 9 6 [ 8 1 ( 4 8 < 1 1 < 10 3 [ 5 7 [ 2 1 ( 8 2 < 1 4 [ 10 6 < 8 9 > 3 5 < 2 8 < 10 4 { 9 6 ( 3 2 [ 7 2 [ 9 10 ] 3 9 { 6 5 { 8 9 [ 9 9 ( 3 1 [ 8 2 ( 1 6 < 5 8 { 1 7 { 9 9 ) 7 6 { 3 1 [ 7 3 < 5 10 { 2 5 { 7 8 { 10 8 ( 2 10 < 2 10 [ 4 4 < 1 7 { 8 6 { 10 8 { 1 10 { 3 10 < 9...
output:
-1
result:
wrong answer 1st lines differ - expected: '28', found: '-1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #50:
score: 0
Wrong Answer
time: 7ms
memory: 4080kb
input:
200 2000 1 200 135 138 { 126 129 [ 167 169 > 195 198 ] 187 188 ( 66 70 ) 61 65 < 13 14 { 193 196 [ 188 190 ) 4 5 < 137 140 ] 32 34 ] 87 91 ( 103 107 ) 182 186 > 168 169 < 101 104 ( 193 196 < 36 37 } 109 110 ( 141 145 [ 33 34 < 192 194 ] 34 38 < 176 178 ] 145 146 < 90 94 [ 152 156 ] 81 84 } 9 13 > 83...
output:
56
result:
wrong answer 1st lines differ - expected: '52', found: '56'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%