Submission #696603

# Submission time Handle Problem Language Result Execution time Memory
696603 2023-02-07T01:09:36 Z SanguineChameleon Autobus (COCI22_autobus) C++17
70 / 70
177 ms 10024 KB
// BEGIN BOILERPLATE CODE

#include <bits/stdc++.h>
using namespace std;

#ifdef KAMIRULEZ
	const bool kami_loc = true;
	const long long kami_seed = 69420;
#else
	const bool kami_loc = false;
	const long long kami_seed = chrono::steady_clock::now().time_since_epoch().count();
#endif

const string kami_fi = "kamirulez.inp";
const string kami_fo = "kamirulez.out";
mt19937_64 kami_gen(kami_seed);

long long rand_range(long long rmin, long long rmax) {
	uniform_int_distribution<long long> rdist(rmin, rmax);
	return rdist(kami_gen);
}

long double rand_real(long double rmin, long double rmax) {
	uniform_real_distribution<long double> rdist(rmin, rmax);
	return rdist(kami_gen);
}

void file_io(string fi, string fo) {
	if (fi != "" && (!kami_loc || fi == kami_fi)) {
		freopen(fi.c_str(), "r", stdin);
	}
	if (fo != "" && (!kami_loc || fo == kami_fo)) {
		freopen(fo.c_str(), "w", stdout);
	}
}

void set_up() {
	if (kami_loc) {
		file_io(kami_fi, kami_fo);
	}
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

void just_do_it();

void just_exec_it() {
	if (kami_loc) {
		auto pstart = chrono::steady_clock::now();
		just_do_it();
		auto pend = chrono::steady_clock::now();
		long long ptime = chrono::duration_cast<chrono::milliseconds>(pend - pstart).count();
		string bar(50, '=');
		cout << '\n' << bar << '\n';
		cout << "Time: " << ptime << " ms" << '\n';
	}
	else {
		just_do_it();
	}
}

int main() {
	set_up();
	just_exec_it();
	return 0;
}

// END BOILERPLATE CODE

// BEGIN MAIN CODE

const long long inf = 1e18L + 20;
const int ms = 75;
long long dp[ms][ms][ms];

void just_do_it() {
	fill_n(&dp[0][0][0], ms * ms * ms, inf);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		dp[i][i][0] = 0;
	}
	for (int i = 0; i < m; i++) {
		int u, v;
		long long w;
		cin >> u >> v >> w;
		dp[u][v][1] = min(dp[u][v][1], w);
	}
	for (int k = 1; k <= n; k++) {
		for (int u = 1; u <= n; u++) {
			for (int v = 1; v <= n; v++) {
				dp[u][v][k] = min(dp[u][v][k], dp[u][v][k - 1]);
				for (int x = 1; x <= n; x++) {
					dp[u][v][k] = min(dp[u][v][k], dp[u][x][k - 1] + dp[x][v][1]);
				}
			}
		}
	}
	int K, Q;
	cin >> K >> Q;
	K = min(K, n);
	for (int i = 0; i < Q; i++) {
		int u, v;
		cin >> u >> v;
		long long res = dp[u][v][K];
		if (res == inf) {
			cout << -1 << '\n';
		}
		else {
			cout << res << '\n';
		}
	}
}

// END MAIN CODE

Compilation message

Main.cpp: In function 'void file_io(std::string, std::string)':
Main.cpp:30:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   freopen(fi.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen(fo.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 3 ms 3624 KB Output is correct
3 Correct 2 ms 3628 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3540 KB Output is correct
6 Correct 2 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3652 KB Output is correct
2 Correct 41 ms 3644 KB Output is correct
3 Correct 39 ms 3656 KB Output is correct
4 Correct 41 ms 3640 KB Output is correct
5 Correct 61 ms 3664 KB Output is correct
6 Correct 41 ms 3688 KB Output is correct
7 Correct 59 ms 3688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 3 ms 3624 KB Output is correct
3 Correct 2 ms 3628 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3540 KB Output is correct
6 Correct 2 ms 3540 KB Output is correct
7 Correct 42 ms 3660 KB Output is correct
8 Correct 46 ms 3656 KB Output is correct
9 Correct 44 ms 3648 KB Output is correct
10 Correct 43 ms 3648 KB Output is correct
11 Correct 47 ms 3684 KB Output is correct
12 Correct 41 ms 3696 KB Output is correct
13 Correct 144 ms 9744 KB Output is correct
14 Correct 129 ms 9760 KB Output is correct
15 Correct 129 ms 9756 KB Output is correct
16 Correct 131 ms 9752 KB Output is correct
17 Correct 134 ms 9740 KB Output is correct
18 Correct 156 ms 9808 KB Output is correct
19 Correct 134 ms 9836 KB Output is correct
20 Correct 129 ms 9840 KB Output is correct
21 Correct 132 ms 9860 KB Output is correct
22 Correct 129 ms 9876 KB Output is correct
23 Correct 140 ms 9868 KB Output is correct
24 Correct 122 ms 9884 KB Output is correct
25 Correct 130 ms 9876 KB Output is correct
26 Correct 140 ms 9956 KB Output is correct
27 Correct 154 ms 10024 KB Output is correct
28 Correct 133 ms 9876 KB Output is correct
29 Correct 127 ms 9620 KB Output is correct
30 Correct 142 ms 9752 KB Output is correct
31 Correct 130 ms 9712 KB Output is correct
32 Correct 124 ms 9612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3540 KB Output is correct
2 Correct 3 ms 3624 KB Output is correct
3 Correct 2 ms 3628 KB Output is correct
4 Correct 2 ms 3540 KB Output is correct
5 Correct 2 ms 3540 KB Output is correct
6 Correct 2 ms 3540 KB Output is correct
7 Correct 44 ms 3652 KB Output is correct
8 Correct 41 ms 3644 KB Output is correct
9 Correct 39 ms 3656 KB Output is correct
10 Correct 41 ms 3640 KB Output is correct
11 Correct 61 ms 3664 KB Output is correct
12 Correct 41 ms 3688 KB Output is correct
13 Correct 59 ms 3688 KB Output is correct
14 Correct 42 ms 3660 KB Output is correct
15 Correct 46 ms 3656 KB Output is correct
16 Correct 44 ms 3648 KB Output is correct
17 Correct 43 ms 3648 KB Output is correct
18 Correct 47 ms 3684 KB Output is correct
19 Correct 41 ms 3696 KB Output is correct
20 Correct 144 ms 9744 KB Output is correct
21 Correct 129 ms 9760 KB Output is correct
22 Correct 129 ms 9756 KB Output is correct
23 Correct 131 ms 9752 KB Output is correct
24 Correct 134 ms 9740 KB Output is correct
25 Correct 156 ms 9808 KB Output is correct
26 Correct 134 ms 9836 KB Output is correct
27 Correct 129 ms 9840 KB Output is correct
28 Correct 132 ms 9860 KB Output is correct
29 Correct 129 ms 9876 KB Output is correct
30 Correct 140 ms 9868 KB Output is correct
31 Correct 122 ms 9884 KB Output is correct
32 Correct 130 ms 9876 KB Output is correct
33 Correct 140 ms 9956 KB Output is correct
34 Correct 154 ms 10024 KB Output is correct
35 Correct 133 ms 9876 KB Output is correct
36 Correct 127 ms 9620 KB Output is correct
37 Correct 142 ms 9752 KB Output is correct
38 Correct 130 ms 9712 KB Output is correct
39 Correct 124 ms 9612 KB Output is correct
40 Correct 36 ms 3648 KB Output is correct
41 Correct 39 ms 3660 KB Output is correct
42 Correct 45 ms 3668 KB Output is correct
43 Correct 44 ms 3648 KB Output is correct
44 Correct 42 ms 3688 KB Output is correct
45 Correct 41 ms 3692 KB Output is correct
46 Correct 127 ms 9748 KB Output is correct
47 Correct 134 ms 9748 KB Output is correct
48 Correct 128 ms 9676 KB Output is correct
49 Correct 125 ms 9752 KB Output is correct
50 Correct 125 ms 9832 KB Output is correct
51 Correct 131 ms 9748 KB Output is correct
52 Correct 133 ms 9748 KB Output is correct
53 Correct 128 ms 9752 KB Output is correct
54 Correct 132 ms 9876 KB Output is correct
55 Correct 130 ms 9868 KB Output is correct
56 Correct 134 ms 9804 KB Output is correct
57 Correct 146 ms 9876 KB Output is correct
58 Correct 131 ms 9960 KB Output is correct
59 Correct 142 ms 9960 KB Output is correct
60 Correct 138 ms 9996 KB Output is correct
61 Correct 177 ms 9932 KB Output is correct
62 Correct 121 ms 9752 KB Output is correct
63 Correct 131 ms 9628 KB Output is correct
64 Correct 135 ms 9756 KB Output is correct
65 Correct 126 ms 9616 KB Output is correct