Submission #444544

# Submission time Handle Problem Language Result Execution time Memory
444544 2021-07-14T08:36:05 Z BeanZ Toll (BOI17_toll) C++14
7 / 100
190 ms 186308 KB
// I_Love_LPL 1y0m6d
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 5e4 + 5;
long long mod = 1e9 + 7;
const int lim = 4e5 + 5;
const int lg = 18;
const int base = 37;
const long double eps = 1e-6;
ll dp[N][lg + 1][5][5], temp[5], res[5];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("tests.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll k, n, m, q;
    cin >> k >> n >> m >> q;
    for (int i = 0; i < n; i++){
        for (int j = 0; j <= lg; j++){
            for (int g = 0; g < k; g++){
                for (int t = 0; t < k; t++){
                    dp[i][j][g][t] = 1e9;
                }
            }
        }
    }
    for (int i = 1; i <= m; i++){
        ll u, v, c;
        cin >> u >> v >> c;
        dp[u][0][u % k][v % k] = c;
    }
    for (int lo = 1; lo <= lg; lo++){
        for (int i = 0; (i + k * (1 << lo) - 1) < n; i++){
            for (int j = 0; j < k; j++){ // des
                for (int g = 0; g < k; g++){ // trans
                    dp[i][lo][i % k][j] = min(dp[i][lo][i % k][j], dp[i][lo - 1][i % k][g] + dp[i + k * (1 << (lo - 1)) - (i % k) + (g % k)][lo - 1][g % k][j]);
                }
            }
        }
    }
    while (q--){
        ll u, v;
        cin >> u >> v;
        ll dep = (v / k) - (u / k);
        for (int i = 0; i < k; i++) res[i] = 1e9;
        res[u % k] = 0;
        ll cur = u / k;
        for (int i = 0; i <= lg; i++){
            for (int g = 0; g < k; g++) temp[g] = 1e9;
            if (dep & (1 << i)){
                for (int g = 0; g < k; g++){ // des
                    for (int j = 0; j < k; j++){ // trans
                        temp[g] = min(temp[g], res[j] + dp[cur * k + j][i][j][g]);
                    }
                }
                cur = cur + (1 << i);
                for (int g = 0; g < k; g++) res[g] = temp[g];
            }
        }
        if (res[v % k] < 1e9) cout << res[v % k] << endl;
        else cout << -1 << endl;
    }
}
/*
Ans:

Out:
*/

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 143 ms 186308 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 4044 KB Output is correct
6 Correct 6 ms 4052 KB Output is correct
7 Correct 3 ms 4044 KB Output is correct
8 Correct 126 ms 186140 KB Output is correct
9 Correct 125 ms 186208 KB Output is correct
10 Correct 110 ms 186240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 186180 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 0 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 143 ms 186308 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 3 ms 4044 KB Output is correct
6 Correct 6 ms 4052 KB Output is correct
7 Correct 3 ms 4044 KB Output is correct
8 Correct 126 ms 186140 KB Output is correct
9 Correct 125 ms 186208 KB Output is correct
10 Correct 110 ms 186240 KB Output is correct
11 Correct 190 ms 186180 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Incorrect 1 ms 332 KB Output isn't correct
15 Halted 0 ms 0 KB -