답안 #340413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340413 2020-12-27T14:47:08 Z 8e7 Toll (BOI17_toll) C++14
7 / 100
257 ms 157164 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#define maxn 50005
#define int long long
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]);
		}
	}
	return ret;
}
mat anc[16][maxn];


signed 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";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 156964 KB Output is correct
2 Correct 89 ms 156908 KB Output is correct
3 Correct 88 ms 156908 KB Output is correct
4 Correct 90 ms 156892 KB Output is correct
5 Correct 91 ms 156908 KB Output is correct
6 Correct 93 ms 156908 KB Output is correct
7 Correct 92 ms 156908 KB Output is correct
8 Correct 251 ms 157164 KB Output is correct
9 Correct 251 ms 156908 KB Output is correct
10 Correct 235 ms 157036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 200 ms 156968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 156956 KB Output is correct
2 Incorrect 88 ms 156908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 156956 KB Output is correct
2 Incorrect 88 ms 156908 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 156964 KB Output is correct
2 Correct 89 ms 156908 KB Output is correct
3 Correct 88 ms 156908 KB Output is correct
4 Correct 90 ms 156892 KB Output is correct
5 Correct 91 ms 156908 KB Output is correct
6 Correct 93 ms 156908 KB Output is correct
7 Correct 92 ms 156908 KB Output is correct
8 Correct 251 ms 157164 KB Output is correct
9 Correct 251 ms 156908 KB Output is correct
10 Correct 235 ms 157036 KB Output is correct
11 Incorrect 200 ms 156968 KB Output isn't correct
12 Halted 0 ms 0 KB -