답안 #1040687

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040687 2024-08-01T08:29:24 Z n3rm1n Toll (BOI17_toll) C++17
0 / 100
3000 ms 12072 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const ll MAXN = 5e4 + 10;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

struct querie
{
    ll ql, qr, index;
    querie(){};
    querie(ll _ql, ll _qr, ll _index)
    {
        ql = _ql;
        qr = _qr;
        index = _index;
    }
};
ll k, n, m, q;
vector < pair < ll, ll > > g[MAXN];
map < pair < ll, ll >, ll > mp;
void read()
{
    cin >> k >> n >> m >> q;
    ll from, to, cost;
    for (ll i = 1; i <= m; ++ i)
    {
        cin >> from >> to >> cost;
        from ++;
        to ++;
        mp[{from, to}] = cost;
    }
}

vector < pair < ll, ll >  > ques[MAXN];
ll inf = 1e17; /// fix
struct info
{
    ll ver;
    ll u[MAXN];
    info()
    {
        ver = 0;
        for (ll i = 1; i <= n; ++ i)
            u[i] = inf;
    };
};
deque < info > dq;
ll ans[MAXN];
void queries()
{
    ll ql, qr;
    for (ll i = 1; i <= q; ++ i)
    {
        cin >> ql >> qr;
        ql ++;
        qr ++;
        ques[ql].push_back(make_pair(qr, i));
    }

    ll last_bucket = (n-1)/k, last = n;
    while((last-1) / k == last_bucket)
    {
        info newinfo;
        newinfo.ver = last;
        newinfo.u[last] = 0;
        dq.push_back(newinfo);
        last --;
    }
    ll i = last;
    while(i >= 1)
    {
        ll curr_bucket = (i-1)/k;
       // cout << "start at " << i << " " << curr_bucket << endl;
        ll cut_later = dq.size();
        while(i >= 1 && (i-1)/k == curr_bucket)
        {
            info newinfo;
            newinfo.ver = i;
            newinfo.u[i] = 0;

            for (ll j = 0; j < cut_later; ++ j)
            {
                ll nb = dq[j].ver;
                ll newcost = mp[make_pair(i, nb)];
                if(!newcost)continue;

                for (ll to = 1; to <= n; ++ to)
                {
                    newinfo.u[to] = min(newinfo.u[to], dq[j].u[to] + newcost);
                }
            }

            dq.push_back(newinfo);
            i --;
        }
        while(cut_later --)
            dq.pop_front();

      //  cout << "* " << dq.size() << endl;
        for (ll j = 0; j < dq.size(); ++ j)
        {
            ll v = dq[j].ver;
            for (auto query: ques[v])
            {
                ans[query.second] = dq[j].u[query.first];
                //cout << "here act" << endl;
            }
        }
    }
    for (ll i = 1; i <= q; ++ i)
    {
        if(ans[i] == inf)cout << -1 << endl;
        else cout << ans[i] << endl;
    }
}
int main()
{
    speed();

    read();
    queries();
    return 0;
}

Compilation message

toll.cpp: In function 'void queries()':
toll.cpp:106:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::deque<info>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for (ll j = 0; j < dq.size(); ++ j)
      |                        ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3027 ms 8268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3051 ms 12072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4544 KB Output is correct
2 Correct 3 ms 5300 KB Output is correct
3 Correct 2 ms 5692 KB Output is correct
4 Incorrect 3 ms 6472 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4544 KB Output is correct
2 Correct 3 ms 5300 KB Output is correct
3 Correct 2 ms 5692 KB Output is correct
4 Incorrect 3 ms 6472 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3027 ms 8268 KB Time limit exceeded
2 Halted 0 ms 0 KB -