답안 #1040674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1040674 2024-08-01T08:24:12 Z n3rm1n Toll (BOI17_toll) C++17
0 / 100
3000 ms 19088 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;
        g[from].push_back(make_pair(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/k, last = n;
    while(last / 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/k;
       // cout << "start at " << i << " " << curr_bucket << endl;
        ll cut_later = dq.size();
        while(i >= 1 && i/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;
               // cout << i << " " << nb << endl;
               // cout << "newcost " << newcost << endl;
                for (ll to = 1; to <= n; ++ to)
                {
                    newinfo.u[to] = min(newinfo.u[to], dq[j].u[to] + newcost);
                }
            }
           /* cout << "for curr i = " << i << endl;
            for (ll ii = 1; ii <= n; ++ ii)
                cout << newinfo.u[ii] << " ";
            cout << endl;*/
            dq.push_back(newinfo);
            i --;
        }
        while(cut_later --)
            dq.pop_front();
        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:109: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]
  109 |         for (ll j = 0; j < dq.size(); ++ j)
      |                        ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3050 ms 10476 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3040 ms 19088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4548 KB Output is correct
2 Incorrect 2 ms 5556 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4548 KB Output is correct
2 Incorrect 2 ms 5556 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3050 ms 10476 KB Time limit exceeded
2 Halted 0 ms 0 KB -