Submission #697118

# Submission time Handle Problem Language Result Execution time Memory
697118 2023-02-08T13:02:40 Z AmirElarbi Toll (BOI17_toll) C++14
0 / 100
65 ms 20068 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e9+7;
const int nax = 5e4+5;
const int nax2 =  20;
typedef complex<int> Point;
using cd = complex<double>;
int k,n,m,o, dat[5][5][32][nax];
int ans[5][5],cnt[5][5];
void combine(int l, int lev){
    for(int i = 0; i < k; i++)
        for(int j = 0; j < k; j++){
            for (int z = 0; z < k; ++z)
            {
                dat[i][j][lev][l] = min(dat[i][j][lev][l], dat[i][z][lev-1][l] + dat[z][j][lev-1][l+(1 << (lev-1))]);        
            }
        }
}
int main()
{
    optimise;
    cin >> k >> n >> m >> o;
    for (int i = 0; i < k; ++i)
        for (int j = 0; j < k; ++j)
            for (int a = 0; a < 25; ++a)
                for(int b = 0; b < n; b++)
                    dat[i][j][a][b] = INF;

    for (int i = 0; i < m; ++i)
    {
        int a,b,c;
        cin >> a >> b >> c;
        dat[a % k][b % k][0][a / k] = c;
    }
    for (int i = 1; i < 25; ++i)
    {
        for (int j = 0; j + (1 << i) < (n+k-1)/k; ++j)
        {
            combine(j, i);
        }
    }
    while(o--){
        int a,b;
        cin >> a >> b;
        if(a == b) cout << 0 << endl;
        else if(a/k >= b/k) cout << -1 << endl;
        else {
            int cur = a/k;
            for(int i = 0; i < k; i++)
                for(int j = 0; j < k; j++)
                    if(i == j) ans[i][j] = 0; 
                    else ans[i][j] = INF; 
            for (int lvl = 20; lvl >= 0; --lvl)
            {
                if(cur + (1 << lvl) <= b/k){
                    for(int i = 0; i < k; i++)
                        for(int j = 0; j < k; j++)
                            cnt[i][j] = INF; 
                    for(int i = 0; i < k; i++)
                        for(int j = 0; j < k; j++){
                            for (int z = 0; z < k; ++z)
                            {
                                cnt[i][j] = min(cnt[i][j], ans[i][z] + dat[z][j][lvl][cur]);        
                            }
                        }
                    memcpy(ans, cnt, sizeof ans);
                    cur += (1 << lvl);
                }
            }
            if(ans[a%k][b%k] >= INF) cout << -1 << endl;
            else cout << ans[a%k][b%k]  << endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 50 ms 5368 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 20068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 2 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 2 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 5368 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -