Submission #340411

# Submission time Handle Problem Language Result Execution time Memory
340411 2020-12-27T14:43:28 Z 8e7 Toll (BOI17_toll) C++14
7 / 100
219 ms 80364 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define maxn 50005
using namespace std;
const int inf = (1<<30) - 1;
struct mat{
	int m[5][5];
	mat() {
		for (int i = 0;i < 5;i++) {
			for (int j = 0;j < 5;j++) m[i][j] = inf;
		}
	}
};
void print(mat a) {
	for (int i = 0;i < 5;i++) {
		for (int j = 0;j < 5;j++) cerr << a.m[i][j] << " ";
		cerr << endl;
	}
}
mat comb(mat a, mat b) {
	mat ret;
	for (int i = 0;i < 5;i++) {
		for (int j = 0;j < 5;j++) {
			ret.m[i][j] = inf;
			for (int k = 0;k < 5;k++) ret.m[i][j] = min(ret.m[i][j], a.m[i][k] + b.m[k][j]);
		}
	}
	//print(a);
	//cerr << endl;
	//print(b);
	//cerr << endl;
	//print(ret);
	//cerr << endl;
	return ret;
}
mat anc[16][maxn];


int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int k, n, m, o;
	cin >> k >> n >> m >> o;
	for (int i = 0;i < m;i++) {
		int a, b, t;
		cin >> a >> b >> t;
		anc[0][a / k].m[a % k][b % k] = t;
	}

	int len = (n + k - 1) / k;
	for (int i = 1;i < 16;i++) {
		for (int j = 0;j < len - (1<<i) + 1;j++) {
			anc[i][j] = comb(anc[i - 1][j], anc[i - 1][j + (1<<(i - 1))]);
		}
	}
	while (o--) {
		int a, b;
		cin >> a >> b;
		int ai = a / k, bi = b / k;
		mat cur;
		for (int i = 0;i < 5;i++) {
			for (int j = 0;j < 5;j++) cur.m[i][j] = 0;
		}
		for (int i = 15;i >= 0;i--) {
			if (ai + (1<<i) <= bi) {
				cur = comb(cur, anc[i][ai]);
				ai += 1<<i;
			}
		}
		int ans = cur.m[a % k][b % k];
		cout << (ans >= inf ? -1 : ans) << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 219 ms 79656 KB Output is correct
2 Correct 49 ms 78572 KB Output is correct
3 Correct 49 ms 78572 KB Output is correct
4 Correct 52 ms 78700 KB Output is correct
5 Correct 57 ms 78700 KB Output is correct
6 Correct 53 ms 78848 KB Output is correct
7 Correct 53 ms 78708 KB Output is correct
8 Correct 219 ms 79724 KB Output is correct
9 Correct 218 ms 79596 KB Output is correct
10 Correct 197 ms 78828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 80364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 78572 KB Output is correct
2 Incorrect 49 ms 78572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 78572 KB Output is correct
2 Incorrect 49 ms 78572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 219 ms 79656 KB Output is correct
2 Correct 49 ms 78572 KB Output is correct
3 Correct 49 ms 78572 KB Output is correct
4 Correct 52 ms 78700 KB Output is correct
5 Correct 57 ms 78700 KB Output is correct
6 Correct 53 ms 78848 KB Output is correct
7 Correct 53 ms 78708 KB Output is correct
8 Correct 219 ms 79724 KB Output is correct
9 Correct 218 ms 79596 KB Output is correct
10 Correct 197 ms 78828 KB Output is correct
11 Incorrect 160 ms 80364 KB Output isn't correct
12 Halted 0 ms 0 KB -