제출 #1128625

#제출 시각아이디문제언어결과실행 시간메모리
1128625pcheloveksToll (BOI17_toll)C++20
0 / 100
3094 ms4156 KiB
//#pragma GCC optimize("O3") #include <iostream> #include <vector> #include <map> #include <set> #include <fstream> #include <algorithm> #include <cstring> // Для memset #define endl '\n' using namespace std; typedef long long LL; typedef pair<LL, LL> pii; const LL DIM = 50007; const LL INF = 999999999999; LL n, k, o, m; class edge { public: LL to, w; }; vector < edge > v[DIM]; class tran { public: LL mat[6][6]; tran() { for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { mat[i][j] = -1; } } } }; tran solve(LL L, LL R) { tran ans; if (R - L == 1) { for (int i = 1; i <= k; i++) { LL val = (L - 1) * k + i - 1; for (auto to : v[val]) { ans.mat[i][to.to - ((R - 1) * k) + 1] = to.w; } } return ans; } LL m = (L + R) / 2; tran m1 = solve(L, m); tran m2 = solve(m, R); for (int l = 1; l <= k; l++) { for (int m = 1; m <= k; m++) { for (int r = 1; r <= k; r++) { if(m1.mat[l][m] != -1 && m2.mat[m][r] != -1) ans.mat[l][r] = m1.mat[l][m] + m2.mat[m][r]; } } } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> k >> n >> m >> o; for (int i = 1; i <= m; i++) { LL a, b, t; cin >> a >> b >> t; v[a].push_back({ b, t }); } for (int i = 1; i <= o; i++) { LL a, b; cin >> a >> b; LL b1 = a / k + 1; LL b2 = b / k + 1; if (b1 >= b2) cout << -1 << endl; else cout << solve(b1, b2).mat[a - ((b1 - 1) * k) + 1][b - ((b2 - 1) * k) + 1] << endl; } 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...