답안 #531469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531469 2022-02-28T18:36:57 Z mat50013 Toll (BOI17_toll) C++11
39 / 100
3000 ms 6724 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const int NMAX(50005);
vector<pair<int, int> > G[NMAX];
ll dp[6], newDp[5];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int k, n, m, o;
    cin >> k >> n >> m >> o;

    for(int i = 1; i <= m; ++i){
        int a, b, t;
        cin >> a >> b >> t;
        G[b].push_back({a, t});
    }

    for(int i = 1; i <= o; ++i){
        int a, b;
        cin >> a >> b;

        int wh = b / k;
        for(int j = 0; j < k; ++j)
            dp[j] = LLONG_MAX / 2;
        dp[b % k] = 0;
        int fin = a / k;
        for(int segm = wh; segm > fin; --segm){
            for(int j = 0; j < k; ++j)
                newDp[j] = LLONG_MAX / 2;
            for(int j = 0; j < k; ++j)
            {
                int nod = segm * k + j;
                for(auto it: G[nod])
                    newDp[it.first % k] = min(newDp[it.first % k], dp[j] + it.second);
            }
            for(int j = 0; j < k; ++j)
                dp[j] = newDp[j];
        }

        cout << (dp[a % k] == LLONG_MAX / 2 ? - 1 : dp[a % k]) << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3036 ms 4000 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3056 ms 4652 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1488 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 3 ms 1484 KB Output is correct
8 Correct 6 ms 1628 KB Output is correct
9 Correct 3 ms 1504 KB Output is correct
10 Correct 81 ms 3792 KB Output is correct
11 Correct 94 ms 4504 KB Output is correct
12 Correct 110 ms 6120 KB Output is correct
13 Correct 135 ms 6576 KB Output is correct
14 Correct 116 ms 5356 KB Output is correct
15 Correct 76 ms 3908 KB Output is correct
16 Correct 55 ms 3928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1488 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 2 ms 1484 KB Output is correct
7 Correct 3 ms 1484 KB Output is correct
8 Correct 6 ms 1628 KB Output is correct
9 Correct 3 ms 1504 KB Output is correct
10 Correct 81 ms 3792 KB Output is correct
11 Correct 94 ms 4504 KB Output is correct
12 Correct 110 ms 6120 KB Output is correct
13 Correct 135 ms 6576 KB Output is correct
14 Correct 116 ms 5356 KB Output is correct
15 Correct 76 ms 3908 KB Output is correct
16 Correct 55 ms 3928 KB Output is correct
17 Correct 1753 ms 4592 KB Output is correct
18 Correct 1 ms 1484 KB Output is correct
19 Correct 1 ms 1496 KB Output is correct
20 Correct 1 ms 1484 KB Output is correct
21 Correct 1 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 22 ms 1560 KB Output is correct
24 Correct 27 ms 1572 KB Output is correct
25 Correct 41 ms 1624 KB Output is correct
26 Correct 34 ms 1568 KB Output is correct
27 Correct 1500 ms 3872 KB Output is correct
28 Correct 2009 ms 6264 KB Output is correct
29 Correct 2219 ms 6724 KB Output is correct
30 Correct 1821 ms 5404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3036 ms 4000 KB Time limit exceeded
2 Halted 0 ms 0 KB -