답안 #158120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158120 2019-10-15T03:17:17 Z PeppaPig Toll (BOI17_toll) C++14
0 / 100
44 ms 32248 KB
#include <bits/stdc++.h>

using namespace std;

int k, n, m, q;
int bl[10005][5][5][16];

int main() {
    fill_n(bl[0][0][0], 10005 * 5 * 5 * 16, 1e9);
    scanf("%d %d %d %d", &k, &n, &m, &q);
    for(int i = 1, a, b, c; i <= m; i++) {
        scanf("%d %d %d", &a, &b, &c);
        bl[a / k][a % k][b % k][0] = c;
    }
    for(int i = 1; i <= 15; i++) for(int a = 0; a <= n / k + 1; a++) 
        for(int b = 0; b < k; b++) for(int c = 0; c < k; c++) for(int t = 0; t < k; t++)
            if(a + (1 << (i - 1)) <= n / k + 1)
                bl[a][b][c][i] = min(bl[a][b][c][i], bl[a][b][t][i-1] + bl[a + (1 << (i - 1))][t][c][i-1]);
    while(q--) {
        int a, b;
        scanf("%d %d", &a, &b);
        if(a / k >= b / k) {
            printf("-1\n");
            continue;
        }
        int ans = b % k, dp[5];
        for(int i = 0; i < k; i++) dp[i] = bl[a / k][a % k][i][0];
        a = (a / k) + 1, b = b / k;
        for(int i = 15; ~i; i--) if(a + (1 << i) <= b) {
            int ndp[5];
            fill_n(ndp, 5, 1e9);
            for(int x = 0; x < k; x++) for(int y = 0; y < k; y++)
                ndp[x] = min(ndp[x], dp[y] + bl[a][y][x][i]);
            for(int j = 0; j < k; j++) dp[j] = ndp[j];
            a += (1 << i);
        }
        if(dp[ans] == 1e9) printf("-1\n");
        else printf("%d\n", dp[ans]);
    }

    return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d", &k, &n, &m, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 44 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 32220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 15976 KB Output is correct
2 Correct 18 ms 15992 KB Output is correct
3 Correct 17 ms 16024 KB Output is correct
4 Correct 16 ms 15992 KB Output is correct
5 Correct 18 ms 15992 KB Output is correct
6 Correct 17 ms 16032 KB Output is correct
7 Correct 17 ms 15992 KB Output is correct
8 Correct 19 ms 16120 KB Output is correct
9 Correct 18 ms 15992 KB Output is correct
10 Runtime error 38 ms 32220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 15976 KB Output is correct
2 Correct 18 ms 15992 KB Output is correct
3 Correct 17 ms 16024 KB Output is correct
4 Correct 16 ms 15992 KB Output is correct
5 Correct 18 ms 15992 KB Output is correct
6 Correct 17 ms 16032 KB Output is correct
7 Correct 17 ms 15992 KB Output is correct
8 Correct 19 ms 16120 KB Output is correct
9 Correct 18 ms 15992 KB Output is correct
10 Runtime error 38 ms 32220 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 44 ms 32248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -