Submission #887371

#TimeUsernameProblemLanguageResultExecution timeMemory
887371dubabubaRailway Trip 2 (JOI22_ho_t4)C++14
8 / 100
37 ms1372 KiB
#include <bits/stdc++.h> using namespace std; const int inf = 1e8 + 10; const int mxn = 330; int a[mxn], n, m; int b[mxn], k, q; int dp[mxn][mxn]; int main() { cin >> n >> k; for(int i = 0; i < mxn; i++) for(int j = 0; j < mxn; j++) dp[i][j] = 1e8 + 10; cin >> m; for(int i = 0; i < m; i++) { cin >> a[i] >> b[i]; if(a[i] < b[i]) for(int t = 0; t < k; t++) { int st = a[i] + t; if(st > b[i]) break; for(int en = st; en <= b[i]; en++) dp[st][en] = 1; } else for(int t = 0; t < k; t++) { int st = a[i] - t; if(st < b[i]) break; for(int en = st; en >= b[i]; en--) dp[st][en] = 1; } } for(int mid = 0; mid < mxn; mid++) for(int st = 0; st < mxn; st++) for(int en = 0; en < mxn; en++) dp[st][en] = min(dp[st][en], dp[st][mid] + dp[mid][en]); int q; cin >> q; while(q--) { int st, en; cin >> st >> en; if(dp[st][en] >= inf) cout << -1 << '\n'; else cout << dp[st][en] << '\n'; } return 0; }
#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...