Submission #1007445

# Submission time Handle Problem Language Result Execution time Memory
1007445 2024-06-25T01:32:11 Z Br3ad Toll (BOI17_toll) C++17
0 / 100
1 ms 1116 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define PF push_front
#define PB push_back
#define MP make_pair
#define max(a, b) ((a > b)? a : b)
#define min(a, b) ((a < b)? a : b)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)

const int N = 5e2 + 5;
const int M = 1e9 + 7; 
const int inf = 0x3f3f3f3f;
const ll int INF = 1e18;

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    // ifstream cin();
    // ofstream cout();

    int k, n, m, q;
    cin >> k >> n >> m >> q;
    
    ll par[N][5][16];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < k; j++){
            for(int step = 0; step < 16; step++){
                par[i][j][step] = INF;
            }
        }
    }

    for(int i = 0; i < m; i++){
        int a, b, w;
        cin >> a >> b >> w;
        par[a][b%k][0] = w;
    }

    for(int i = 1; i < 16; i++){
        for(int j = 0; j < n; j++){
            for(int pos = 0; pos < k; pos++){
                for(int temp = 0; temp < k; temp++){
                    int jump = j + (1 << (i-1))*k - j%k + temp;
                    if(jump >= n) continue;
                    par[j][pos][i] = min(par[j][pos][i], par[j][temp][i-1] + par[jump][pos][i-1]);
                }
            }
        }
    }

    while(q--){
        int a, b;
        cin >> a >> b;

        int pa = a/k, pb = b/k;

        if(pb <= pa){
            cout << "-1" << endl;
            continue;
        }

        vector<ll> dp(k, INF);
        dp[a%k] = 0;
        for(int i = 15; i >= 0; i--){
            if(((pb - pa) >> i) & 1){
                vector<ll> cur(k, INF);
                for(int j = 0; j < k; j++){
                    for(int from = 0; from < k; from++){
                        cur[j] = min(cur[j], dp[from] + par[pa*k + from][j][i]);
                    }
                }
                dp = cur;
                pa += (1 << i);
            }
        }

        cout << ((dp[b%k] == INF)? -1 : dp[b%k]) << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 856 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 612 KB Output is correct
6 Runtime error 1 ms 1116 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 856 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 612 KB Output is correct
6 Runtime error 1 ms 1116 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -