Submission #960525

# Submission time Handle Problem Language Result Execution time Memory
960525 2024-04-10T15:16:50 Z hariaakas646 Toll (BOI17_toll) C++14
100 / 100
132 ms 18768 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int k, n, m, o;
vector<vii> graph, revg;
vvi lef, righ;
vi out;

void rec(int l, int r, vector<pair<pii, int>> quer) {
    if(l >= r) return;
    int mid = (l+r)/2;

    forr(i, l, mid+1) {
        frange(j, 2*k) lef[i][j] = 1e9 + 5;
    }
    forr(i, mid+1, r+1) {
        frange(j, 2*k) righ[i][j] = 1e9 + 5;
    }

    for(int i=mid; i>=l; i--) {
        frange(j, 2*k) {
            if(i == mid-j) lef[i][j] = 0;
            else {
                for(auto e : graph[i]) {
                    if(e.f <= mid) lef[i][j] = min(lef[i][j], lef[e.f][j] + e.s);
                }
            }
        }
    }

    forr(i, mid+1, r+1) {
        frange(j, 2*k) {
            if(i == mid+1+j) righ[i][j] = 0;
            else {
                for(auto e : revg[i]) {
                    if(e.f >= mid+1) righ[i][j] = min(righ[i][j], righ[e.f][j] + e.s);
                }
            }
        }
    }

    vector<pair<pii, int>> lv, rv;
    for(auto p1 : quer) {
        auto p = p1.f;
        if(p.f <= mid && p.s > mid) {
            int mi = 1e9;
            for(int i=max(l, mid-2*k+1); i<=mid; i++) {
                for(auto e : graph[i]) {
                    if(e.f > mid) {
                        mi = min(mi, lef[p.f][mid-i] + e.s + righ[p.s][e.f-(mid+1)]);
                    }
                }
            }
            if(mi == 1e9) mi = -1;
            out[p1.s] = mi;
        }
        else if(p.f <= mid) lv.pb(p1);
        else rv.pb(p1);
    }

    rec(l, mid, lv);
    rec(mid+1, r, rv);


}

int main() {
    // usaco();
    scd(k);
    scd(n);
    scd(m);
    scd(o);

    revg = graph = vector<vii>(n+1);

    frange(i, m) {
        int a, b, v;
        scd(a);
        scd(b);
        scd(v);
        a++;
        b++;
        graph[a].pb(mp(b, v));
        revg[b].pb(mp(a, v));
    }

    lef = righ = vvi(n+1, vi(2*k));
    vector<pair<pii, int>> query(o);

    frange(i, o) {
        scd(query[i].f.f);
        scd(query[i].f.s);
        query[i].f.f++;
        query[i].f.s++;
        query[i].s = i;
    }
    out = vi(o);
    rec(1, n, query);

    for(auto e : out) printf("%d\n", e);


}

Compilation message

toll.cpp: In function 'void usaco()':
toll.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp: In function 'int main()':
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:99:5: note: in expansion of macro 'scd'
   99 |     scd(k);
      |     ^~~
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:100:5: note: in expansion of macro 'scd'
  100 |     scd(n);
      |     ^~~
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:101:5: note: in expansion of macro 'scd'
  101 |     scd(m);
      |     ^~~
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:102:5: note: in expansion of macro 'scd'
  102 |     scd(o);
      |     ^~~
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:108:9: note: in expansion of macro 'scd'
  108 |         scd(a);
      |         ^~~
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:109:9: note: in expansion of macro 'scd'
  109 |         scd(b);
      |         ^~~
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:110:9: note: in expansion of macro 'scd'
  110 |         scd(v);
      |         ^~~
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:121:9: note: in expansion of macro 'scd'
  121 |         scd(query[i].f.f);
      |         ^~~
toll.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
toll.cpp:122:9: note: in expansion of macro 'scd'
  122 |         scd(query[i].f.s);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 12636 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 704 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 36 ms 12712 KB Output is correct
9 Correct 33 ms 12380 KB Output is correct
10 Correct 13 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 13396 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 436 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 4 ms 1112 KB Output is correct
9 Correct 36 ms 12628 KB Output is correct
10 Correct 113 ms 15492 KB Output is correct
11 Correct 70 ms 13676 KB Output is correct
12 Correct 61 ms 12884 KB Output is correct
13 Correct 114 ms 13644 KB Output is correct
14 Correct 59 ms 9764 KB Output is correct
15 Correct 62 ms 9808 KB Output is correct
16 Correct 60 ms 10060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 34 ms 11948 KB Output is correct
11 Correct 77 ms 12836 KB Output is correct
12 Correct 95 ms 14732 KB Output is correct
13 Correct 96 ms 15696 KB Output is correct
14 Correct 83 ms 13652 KB Output is correct
15 Correct 58 ms 9808 KB Output is correct
16 Correct 58 ms 9808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 34 ms 11948 KB Output is correct
11 Correct 77 ms 12836 KB Output is correct
12 Correct 95 ms 14732 KB Output is correct
13 Correct 96 ms 15696 KB Output is correct
14 Correct 83 ms 13652 KB Output is correct
15 Correct 58 ms 9808 KB Output is correct
16 Correct 58 ms 9808 KB Output is correct
17 Correct 57 ms 12888 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 3 ms 600 KB Output is correct
25 Correct 4 ms 860 KB Output is correct
26 Correct 3 ms 860 KB Output is correct
27 Correct 31 ms 12124 KB Output is correct
28 Correct 89 ms 14864 KB Output is correct
29 Correct 103 ms 15696 KB Output is correct
30 Correct 98 ms 14224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 12636 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 704 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 36 ms 12712 KB Output is correct
9 Correct 33 ms 12380 KB Output is correct
10 Correct 13 ms 8796 KB Output is correct
11 Correct 61 ms 13396 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 436 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 4 ms 1112 KB Output is correct
19 Correct 36 ms 12628 KB Output is correct
20 Correct 113 ms 15492 KB Output is correct
21 Correct 70 ms 13676 KB Output is correct
22 Correct 61 ms 12884 KB Output is correct
23 Correct 114 ms 13644 KB Output is correct
24 Correct 59 ms 9764 KB Output is correct
25 Correct 62 ms 9808 KB Output is correct
26 Correct 60 ms 10060 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 600 KB Output is correct
36 Correct 34 ms 11948 KB Output is correct
37 Correct 77 ms 12836 KB Output is correct
38 Correct 95 ms 14732 KB Output is correct
39 Correct 96 ms 15696 KB Output is correct
40 Correct 83 ms 13652 KB Output is correct
41 Correct 58 ms 9808 KB Output is correct
42 Correct 58 ms 9808 KB Output is correct
43 Correct 57 ms 12888 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 2 ms 600 KB Output is correct
50 Correct 3 ms 600 KB Output is correct
51 Correct 4 ms 860 KB Output is correct
52 Correct 3 ms 860 KB Output is correct
53 Correct 31 ms 12124 KB Output is correct
54 Correct 89 ms 14864 KB Output is correct
55 Correct 103 ms 15696 KB Output is correct
56 Correct 98 ms 14224 KB Output is correct
57 Correct 132 ms 18768 KB Output is correct
58 Correct 34 ms 12632 KB Output is correct
59 Correct 65 ms 13440 KB Output is correct