Submission #430576

#TimeUsernameProblemLanguageResultExecution timeMemory
430576CodePlatinaBrackets (CPSPC17_brackets)C++17
74 / 100
1089 ms25412 KiB
#include <iostream> #include <vector> #include <queue> #define pii pair<int, int> #define piii pair<int, pii> #define ff first #define ss second #define ee ss.ff #define rr ss.ss using namespace std; const int INF = (int)1e9 + 7; vector<int> gph[202][8]; vector<int> rgph[202][8]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("in.txt", "r", stdin); int n, m, s, e; cin >> n >> m >> s >> e; --s; --e; for(int i = 0; i < m; ++i) { int x, y; char c; cin >> x >> y >> c; --x; --y; int z; if(c == '<') z = 0; if(c == '>') z = 1; if(c == '{') z = 2; if(c == '}') z = 3; if(c == '[') z = 4; if(c == ']') z = 5; if(c == '(') z = 6; if(c == ')') z = 7; gph[x][z].push_back(y); rgph[y][z].push_back(x); } int C[n][n]; for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j) C[i][j] = INF; priority_queue<piii, vector<piii>, greater<piii>> Q; for(int i = 0; i < n; ++i) Q.push({0, {i, i}}); while(Q.size()) { auto x = Q.top(); Q.pop(); if(C[x.ee][x.rr] != INF) continue; C[x.ee][x.rr] = x.ff; for(int i = 0; i < 8; i += 2) for(auto j : rgph[x.ee][i]) for(auto k : gph[x.rr][i + 1]) Q.push({x.ff + 2, {j, k}}); for(int i = 0; i < n; ++i) { if(C[i][x.rr] > C[x.ee][x.rr] + C[i][x.ee]) Q.push({C[x.ee][x.rr] + C[i][x.ee], {i, x.rr}}); if(C[x.ee][i] > C[x.ee][x.rr] + C[x.rr][i]) Q.push({C[x.ee][x.rr] + C[x.rr][i], {x.ee, i}}); } } cout << (C[s][e] == INF ? -1 : C[s][e]); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:28:13: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   28 |         int z;
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...