Submission #1035718

#TimeUsernameProblemLanguageResultExecution timeMemory
1035718c2zi6Wombats (IOI13_wombats)C++14
55 / 100
20093 ms108372 KiB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "wombats.h"
 
const int MAXC = 200;
 
int n, m;
struct PART {
    int d[MAXC][MAXC];
    PART() {
        rep(i, m) rep(j, m) d[i][j] = 2e9;
    }
    void add(const PART& b) {
        PART c;
        rep(u, m) rep(v, m) rep(mid, m) {
            setmin(c.d[u][v], d[u][mid] + b.d[mid][v]);
        }
        rep(u, m) rep(v, m) d[u][v] = c.d[u][v];
    }
};
void combine(const PART& a, const PART& b) {
    PART c;
    rep(u, m) rep(v, m) rep(mid, m) {
        setmin(c.d[u][v], a.d[u][mid] + b.d[mid][v]);
    }
}
vector<PART> a;
PART answer;
VVI H, V;
 
void recalc() {
    a = vector<PART>(n);
    rep(u, n) {
        replr(i, 0, m-1) {
            int sum = 0;
            replr(j, i, m-1) {
                a[u].d[i][j] = sum + V[u][j];
                a[u].d[j][i] = sum + V[u][i];
                sum += H[u][j];
            }
        }
    }
    answer = a[0];
    replr(i, 1, n-1) answer.add(a[i]);
}
 
bool lucum1;

void init(int R, int C, int H_arg[5000][200], int V_arg[5000][200]) {
    lucum1 = (C <= 20);
    n = R;
    m = C;
 
    H = V = VVI(n, VI(m));
    rep(i, n) rep(j, m-1) H[i][j] = H_arg[i][j];
    rep(i, n-1) rep(j, m) V[i][j] = V_arg[i][j];
 
    if (lucum1) recalc();
}
 
void changeH(int P, int Q, int W) {
    H[P][Q] = W;
    if (lucum1) recalc();
    /* ... */
}
 
void changeV(int P, int Q, int W) {
    V[P][Q] = W;
    if (lucum1) recalc();
    /* ... */
}
 
int escape(int U1, int U2) {
    if (lucum1) return answer.d[U1][U2];

    int sz = (n+1) * (m+1);
    VVPI gp(sz);
    rep(i, n) rep(j, m) {
        if (j+1 < m) {
            gp[i*m+j].pb({i*m+(j+1), H[i][j]});
            gp[i*m+(j+1)].pb({i*m+j, H[i][j]});
        }
        gp[i*m+j].pb({(i+1)*m+j, V[i][j]});
    }

    VI dist(sz, 1e9);
    VI vis(sz);
    priority_queue<PII> pq;
    pq.push({0, 0*m+U1});
    dist[0*m+U1] = 0;
    while (pq.size()) {
        int u = pq.top().ss;
        pq.pop();
        if (vis[u]) continue;
        vis[u] = true;
        for (auto[v, w] : gp[u]) {
            if (dist[u] + w < dist[v]) {
                dist[v] = dist[u] + w;
                pq.push({-dist[v], v});
            }
        }
    }
    return dist[n*m+U2];
}
 

Compilation message (stderr)

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
wombats.cpp: In function 'int escape(int, int)':
wombats.cpp:125:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  125 |         for (auto[v, w] : gp[u]) {
      |                  ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...