답안 #793498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
793498 2023-07-25T22:59:41 Z asdfgrace Toll (BOI17_toll) C++17
100 / 100
2151 ms 7792 KB
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) //x
#define A(x) DEBUG(assert(x))
#define PRINT(x) DEBUG(cerr << x)
#define PV(x) DEBUG(cerr << #x << " = " << x << '\n')
#define PV2(x) DEBUG(cerr << #x << " = " << x.first << ',' << x.second << '\n')
#define PAR(x) DEBUG(PRINT(#x << " = { "); for (auto y : x) PRINT(y << ' '); PRINT("}\n");)
#define PAR2(x) DEBUG(PRINT(#x << " = { "); for (auto [y, z] : x) PRINT(y << ',' << z << "  "); PRINT("}\n");)
#define PAR2D(x) DEBUG(PRINT(#x << ":\n"); for (auto arr : x) {PAR(arr);} PRINT('\n'));
using i64 = long long;
constexpr int INF = 1000000007; //998244353;

int k, n, m, q;
vector<vector<pair<int, int>>> edges;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  cin >> k >> n >> m >> q;
  edges.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b, w;
    cin >> a >> b >> w;
    edges[a].push_back({b, w});
  }
  vector<int> best(n, INF);
  while (q--) {
    int a, b;
    cin >> a >> b;
    fill(best.begin() + a, best.begin() + b + 1, INF);
    best[a] = 0;
    for (int i = a; i < b; ++i) {
      for (auto [next, wt] : edges[i]) {
        best[next] = min(best[next], best[i] + wt);
      }
    }
    if (best[b] == INF) cout << -1 << '\n';
    else cout << best[b] << '\n';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 722 ms 4388 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 691 ms 4196 KB Output is correct
9 Correct 692 ms 4080 KB Output is correct
10 Correct 164 ms 1808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1438 ms 4912 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 20 ms 468 KB Output is correct
8 Correct 20 ms 508 KB Output is correct
9 Correct 1100 ms 4156 KB Output is correct
10 Correct 2151 ms 6476 KB Output is correct
11 Correct 1464 ms 4976 KB Output is correct
12 Correct 1801 ms 4468 KB Output is correct
13 Correct 544 ms 6272 KB Output is correct
14 Correct 390 ms 4272 KB Output is correct
15 Correct 408 ms 3660 KB Output is correct
16 Correct 470 ms 3664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 24 ms 4052 KB Output is correct
11 Correct 31 ms 4684 KB Output is correct
12 Correct 46 ms 6232 KB Output is correct
13 Correct 50 ms 6844 KB Output is correct
14 Correct 43 ms 5572 KB Output is correct
15 Correct 32 ms 3532 KB Output is correct
16 Correct 25 ms 3612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 24 ms 4052 KB Output is correct
11 Correct 31 ms 4684 KB Output is correct
12 Correct 46 ms 6232 KB Output is correct
13 Correct 50 ms 6844 KB Output is correct
14 Correct 43 ms 5572 KB Output is correct
15 Correct 32 ms 3532 KB Output is correct
16 Correct 25 ms 3612 KB Output is correct
17 Correct 363 ms 4848 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 5 ms 340 KB Output is correct
24 Correct 5 ms 340 KB Output is correct
25 Correct 8 ms 436 KB Output is correct
26 Correct 7 ms 484 KB Output is correct
27 Correct 221 ms 4104 KB Output is correct
28 Correct 443 ms 6396 KB Output is correct
29 Correct 522 ms 6896 KB Output is correct
30 Correct 442 ms 5616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 722 ms 4388 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 691 ms 4196 KB Output is correct
9 Correct 692 ms 4080 KB Output is correct
10 Correct 164 ms 1808 KB Output is correct
11 Correct 1438 ms 4912 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 20 ms 468 KB Output is correct
18 Correct 20 ms 508 KB Output is correct
19 Correct 1100 ms 4156 KB Output is correct
20 Correct 2151 ms 6476 KB Output is correct
21 Correct 1464 ms 4976 KB Output is correct
22 Correct 1801 ms 4468 KB Output is correct
23 Correct 544 ms 6272 KB Output is correct
24 Correct 390 ms 4272 KB Output is correct
25 Correct 408 ms 3660 KB Output is correct
26 Correct 470 ms 3664 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 324 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 24 ms 4052 KB Output is correct
37 Correct 31 ms 4684 KB Output is correct
38 Correct 46 ms 6232 KB Output is correct
39 Correct 50 ms 6844 KB Output is correct
40 Correct 43 ms 5572 KB Output is correct
41 Correct 32 ms 3532 KB Output is correct
42 Correct 25 ms 3612 KB Output is correct
43 Correct 363 ms 4848 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 5 ms 340 KB Output is correct
50 Correct 5 ms 340 KB Output is correct
51 Correct 8 ms 436 KB Output is correct
52 Correct 7 ms 484 KB Output is correct
53 Correct 221 ms 4104 KB Output is correct
54 Correct 443 ms 6396 KB Output is correct
55 Correct 522 ms 6896 KB Output is correct
56 Correct 442 ms 5616 KB Output is correct
57 Correct 1705 ms 7792 KB Output is correct
58 Correct 746 ms 4200 KB Output is correct
59 Correct 1116 ms 5044 KB Output is correct