제출 #412266

#제출 시각아이디문제언어결과실행 시간메모리
412266Killer2501Toll (BOI17_toll)C++14
100 / 100
147 ms160088 KiB
#include<bits/stdc++.h>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "SKILEVEL"
#define pii pair<ll, pll>
using namespace std;
using ll = long long;
const int  N = 1e5+5;
const ll mod = 1e12;
const ll base = 350;
const ll cs = 331;
ll m, n, t, k, a[N], tong, b[N], dp[N][16][5][5], q, ans;
vector<ll>  adj[N];
ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}


void sol()
{
    cin >> k >> n >> m >> q;
    for(int i = 0; i <= n/k; i ++)
    {
        for(int j = 0; j < 16; j ++)
        {
            for(int l = 0; l < k; l ++)
            {
                for(int r = 0; r < k; r ++)dp[i][j][l][r] = mod;
            }
        }
    }
    while(m -- > 0)
    {
        ll x, y, w;
        cin >> x >> y >> w;
        dp[x/k][0][x%k][y%k] = w;
    }
    for(int j = 1; j < 16; j ++)
    {
        for(int i = 0; i + (1<<j)-1<= n/k; i ++)
        {
            for(int l = 0; l < k; l ++)
            {
                for(int r = 0; r < k; r ++)
                {
                    for(int p = 0; p < k; p ++)
                    {
                        dp[i][j][l][r] = min(dp[i][j][l][r], dp[i][j-1][l][p] + dp[i+(1<<(j-1))][j-1][p][r]);
                    }
                }
            }
        }
    }
    while(q -- > 0)
    {
        ll x, y;
        cin >> x >> y;
        ll u = x / k, v = y / k;
        vector<ll> kq;
        kq.resize(k, mod);
        kq[x%k] = 0;
        for(int j = 15; j >= 0; j --)
        {
            if(u + (1<<j) <= v)
            {
                vector<ll> pre;
                pre.resize(k, mod);
                for(int l = 0; l < k; l ++)
                {
                    for(int r = 0; r < k; r ++)pre[r] = min(pre[r], kq[l] + dp[u][j][l][r]);
                }
                swap(kq, pre);
                u += (1<<j);
            }
        }
        ans = kq[y%k];
        if(ans == mod)ans = -1;
        cout << ans << '\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
2

1 6 6 4
1 2 3
2 3 6
0 1 6
1 2 3
1 2 6
3 4 3
0 4
2 3
1 3
0 2
*/

컴파일 시 표준 에러 (stderr) 메시지

toll.cpp: In function 'int main()':
toll.cpp:97:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...