Submission #847700

# Submission time Handle Problem Language Result Execution time Memory
847700 2023-09-10T08:11:20 Z hariaakas646 Toll (BOI17_toll) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define scld(t) scanf("%ld", &t)
#define sclld(t) scanf("%lld", &t)
#define scc(t) scanf("%c", &t)
#define scs(t) scanf("%s", t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &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 int li;
typedef unsigned long int uli;
typedef long long int lli;
typedef unsigned long long int ulli;
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("input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int k, n, m, o;
vvi graph;

vector<vvi> lift;

vi binlift(int x, int c) {
    vi out(k, 1e9);
    out[x%k] = 0;
    frange(i, 20) {
        if(c & (1<<i)) {
            
            vi nex(k, 1e9);
            frange(l, k) {
                frange(r, k) {
                    if(i == 0) {
                        nex[l] = min(nex[l], out[r] + lift[i][(x/k) * k + r][l]);
                    }
                    else {
                        if((x/k + (1<<(i-1)))*k+r<= n)
                            nex[l] = min(nex[l], out[r] + lift[i][(x/k)*k+r][l]);
                    }
                }
            }
            x = (x/k + (i<<i)) * k;
            out = nex;
        }
    }
    return out;
}

int main() {
    usaco();
    scd(k);
    scd(n);
    scd(m);
    scd(o);
    graph = vvi(n+1, vi(k, 1e9));

    frange(i, m) {
        int a, b;
        scd(a);
        scd(b);
        int t;
        scd(t);
        graph[a][b%k] = t;
    }

    lift = vector<vvi>(20, vvi(n+1, vi(k, 1e9)));

    forr(i, 0, n+1) {
        lift[0][i] = graph[i];
    }

    forr(i, 1, 20) {
        forr(j, 0, n+1) {
            frange(l, k) {
                frange(r, k) {
                    if((j/k + (1<<(i-1)))*k + r<= n)
                        lift[i][j][l] = min(lift[i][j][l], lift[i-1][j][r] + lift[i-1][(j/k + (1<<(i-1)))*k + r][l]);
                }
            }
        }
    }

    frange(i, o) {
        int a, b;
        scd(a);
        scd(b);
        vi out = binlift(a, b/k - a/k);
        int mi = out[b%k];
        if(mi < 1e9) printf("%d\n", mi);
        else printf("-1\n");
    }

}

Compilation message

toll.cpp: In function 'void usaco()':
toll.cpp:37:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     freopen("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:73:5: note: in expansion of macro 'scd'
   73 |     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:74:5: note: in expansion of macro 'scd'
   74 |     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:75:5: note: in expansion of macro 'scd'
   75 |     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:76:5: note: in expansion of macro 'scd'
   76 |     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:81:9: note: in expansion of macro 'scd'
   81 |         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:82:9: note: in expansion of macro 'scd'
   82 |         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:84:9: note: in expansion of macro 'scd'
   84 |         scd(t);
      |         ^~~
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:107:9: note: in expansion of macro 'scd'
  107 |         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:108:9: note: in expansion of macro 'scd'
  108 |         scd(b);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -