Submission #629971

# Submission time Handle Problem Language Result Execution time Memory
629971 2022-08-15T12:59:40 Z urosk Toll (BOI17_toll) C++14
0 / 100
255 ms 196060 KB
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
*/
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}
#define maxn 50005
#define lg 20
ll n,k,m,q;
struct mat{
    ll a[5][5];
    mat(){
        for(ll i = 0;i<5;i++) for(ll j = 0;j<5;j++) a[i][j] = llinf;
    }
    mat operator + (mat b){
        mat c;
        for(ll i = 0;i<5;i++){
            for(ll j = 0;j<5;j++){
                for(ll k = 0;k<5;k++){
                    c.a[i][j] = min(c.a[i][j],a[i][k] + b.a[k][j]);
                }
            }
        }
        return c;
    }
};
mat dp[maxn][lg];

int main(){
	daj_mi_malo_vremena
    cin >> k >> n >> m >> q;
    for(ll i = 1;i<=m;i++){
        ll x,y,w; cin >> x >> y >> w;
        dp[x/k][0].a[x%k][y%k] = w;
    }
    for(ll j = 1;j<lg;j++){
        for(ll i = 0;i<n;i++){
            if(i+(1<<j)+1>n) break;
            dp[i][j] = dp[i][j-1] + dp[i+(1<<(j-1))][j-1];
        }
    }
    while(q--){
        ll x,y; cin >> x >> y;
        ll xd = x/k,yd = y/k;
        mat ans = dp[xd][0];
        xd++;
        for(ll j = lg-1;j>=0;j--){
            if(xd+(1<<j)<=yd){
                ans = ans + dp[xd][j];
                xd+=(1<<j)+1;
            }
        }
        ll val = ans.a[x%k][y%k];
        if(val==llinf) val = -1;
        cout<<val<<endl;
    }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 241 ms 196056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 255 ms 196060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 195892 KB Output is correct
2 Incorrect 76 ms 195920 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 195892 KB Output is correct
2 Incorrect 76 ms 195920 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 241 ms 196056 KB Output isn't correct
2 Halted 0 ms 0 KB -