Submission #1165841

#TimeUsernameProblemLanguageResultExecution timeMemory
1165841sanoWombats (IOI13_wombats)C++20
9 / 100
164 ms12172 KiB
#include "wombats.h"
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<fstream>
#include<algorithm>
#include <iomanip>
#include<map>
#include <set>
#include <unordered_map>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <cstdint>
#define shit short int
#define ll long long
#define For(i, n) for(ll i = 0; i < (ll)n; i++)
#define ffor(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rfor(i, n) for(ll i = (ll)n; i >= (ll)0; i--)
#define rffor(i, a, n) for(ll i = (ll)n; i >= (ll)a; i--)
#define vec vector
#define ff first
#define ss second
#define pb push_back
#define pii pair<ll, ll>
#define NEK 2000000000
#define mod 998244353
#define mod2 1000000009
#define rsz resize 
#define prv1 43
#define prv2 47
#define D 8
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define sig 0.0000001

using namespace std;

class intervalac {
	int n;
	vec<int> l, r;
	vec<vec<vec<int>>> in;
	int c;
	vec<vec<int>> h, v;
public:
	void postav(int x, vec<int>& h1, vec<int>& h2, vec<int>& v) {
		For(i, c) {
			priority_queue<pii> q;
			vec<bool> bol(2 * c, 0);
			q.push({ 0, i });
			while (!q.empty()) {
				int som = q.top().ss, d = q.top().ff; q.pop();
				if (bol[som]) continue;
				d *= (-1);
				bol[som] = 1;
				int nd = 0;
				int pos = 0;
				if (som >= c) {
					pos = c;
					swap(h1, h2);
				}
				int nsom = 0;
				if (som + 1 - pos != c) {
					nsom = som + 1;
					nd = d + h1[nsom - pos - 1];
					q.push({ (-1) * nd, nsom });
				}
				if (som - 1 - pos >= 0) {
					nsom = som - 1;
					nd = d + h1[nsom - pos];
					q.push({ (-1) * nd, nsom });
				}
				if (som < c) {
					nsom = som + c;
					nd = d + v[som];
					q.push({ (-1) * nd, nsom });
				}
				else {
					in[x][i][som - c] = d;
				}
				if (som >= c) swap(h1, h2);
			}
		}
	}
	void update(int x) {
		For(i, in[2 * x].size()) {
			For(j, in[2 * x + 1].size()) {
				in[x][i][j] = NEK;
				For(r, in[2 * x].size()) {
					in[x][i][j] = min(in[x][i][j], in[2 * x][i][r] + in[2 * x + 1][r][j]);
				}
			}
		}
		return;
	}
	void zaciatok(int r1, int c1, vec<vec<int>>& h1, vec<vec<int>>& v1) {
		c = c1;
		n = 1;
		h = h1;
		v = v1;
		while (n < (r1-1)) n *= 2;
		l.resize(2 * n); r.resize(2 * n); 
		if(h.size() < n) h.resize(n, vec<int>(c1 - 1, 0));
		if(v.size() < n) v.resize(n, vec<int>(c1, 0));
		in.resize(2 * n, vec<vec<int>>(c1, vec<int>(c1, NEK)));
		For(i, n) {
			l[i + n] = i;
			r[i + n] = i;
			postav(i+n, h[i], h[i + 1], v[i]);
		}
		rffor(i, 1, (n - 1)) {
			l[i] = l[i * 2];
			r[i] = r[i * 2 + 1];
			update(i);
		}
	}
	int daj(int a, int b) {
		return in[1][a][b];
	}
	void zmenh(int p, int q, int w) {
		h[p][q] = w;
		if(p != (h.size() - 1)) postav(p+n, h[p], h[p + 1], v[p]);
		if (p != 0) postav(p + n - 1, h[p - 1], h[p], v[p - 1]);
		int som = p + n;
		som /= 2;
		while (som) {
			update(som);
			som /= 2;
		}
		return;
	}
	void zmenv(int p, int q, int w) {
		v[p][q] = w;
		postav(p + n, h[p], h[p + 1], v[p]);
		int som = p + n;
		som /= 2;
		while (som) {
			update(som);
			som /= 2;
		}
		return;
	}

};

intervalac seg;

int escape(int v1, int v2) {
	return seg.daj(v1, v2);
}

void changeH(int p, int q, int w) {
	seg.zmenh(p, q, w);
	return;
}

void changeV(int p, int q, int w) {
	seg.zmenv(p, q, w);
	return;
}

void init(int R, int C, int H[5000][200], int V[5000][200]) {
	int r = R, c = C;
	vec<vec<int>> h(r, vec<int>(c-1));
	vec<vec<int>> v(r-1, vec<int>(c));
	For(i, r) {
		For(j, c-1) {
			h[i][j] = H[i][j];
		}
	}
	For(i, r-1) {
		For(j, c) {
			v[i][j] = V[i][j];
		}
	}
	seg.zaciatok(r, c, h, v);
	return;
}


/*
signed main() {
	ll t;
	//cin >> t;
	t = 1;
	For(w, t) {
		int r, c;
		cin >> r >> c;
		int h[50][20];
		int v[50][20];
		For(i, r) {
			For(j, (c-1)) {
				cin >> h[i][j];
			}
		}
		For(i, (r-1)) {
			For(j, c) {
				cin >> v[i][j];
			}
		}
		init(r, c, h, v);
		int e; cin >> e;
		For(i, e) {
			int a, b, c; cin >> a >> b >> c;
			if (a == 1) {
				int w; cin >> w;
				changeH(b, c, w);
			}
			if (a == 2) {
				int w; cin >> w;
				changeV(b, c, w);
			}
			if (a == 3) {
				cout << escape(b, c) << '\n';
			}
		}
	}
	return 0;
}*/
#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...