Submission #696718

# Submission time Handle Problem Language Result Execution time Memory
696718 2023-02-07T06:00:58 Z baojiaopisu Autobus (COCI22_autobus) C++14
70 / 70
158 ms 6564 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;

#define fi first
#define se second
#define left BAO
#define right ANH
#define pb push_back
#define pf push_front
#define mp make_pair
#define ins insert
#define btpc __builtin_popcount
#define btclz __builtin_clz

#define sz(x) (int)(x.size());
#define all(x) x.begin(), x.end()
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y)
        {
            x = y;
            return true;
        }
        return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y)
        {
            x = y;
            return true;
        }
        return false;
    }

const int MOD = 1e9 + 7; //998244353

template<class X, class Y>
	void add(X &x, const Y &y) {
		x = (x + y);
		if(x >= MOD) x -= MOD;
	}

template<class X, class Y> 
	void sub(X &x, const Y &y) {
		x = (x - y);
		if(x < 0) x += MOD;
	}

/* Author : Le Ngoc Bao Anh, 12A5, LQD High School for Gifted Student*/

const ll INF = 1e9;
const int N = 73;

int d[N][N], dp[N][N][N];

void BaoJiaoPisu() {
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) d[i][j] = INF;
		d[i][i] = 0;
	}
	for(int i = 1; i <= m; i++) {
		int u, v, w; cin >> u >> v >> w;
		minimize(d[u][v], w);
	}

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			for(int x = 0; x <= n; x++) {
				dp[i][j][x] = INF;
			}
		}

		dp[i][i][0] = 0;
		for(int x = 0; x < n; x++) {
			for(int j = 1; j <= n; j++) {
				for(int t = 1; t <= n; t++) minimize(dp[i][t][x + 1], dp[i][j][x] + d[j][t]);
			}
		}
	}

	int k, q; cin >> k >> q;
	minimize(k, n);

	while(q--) {
		int u, v; cin >> u >> v;
		int ans = INF;
		for(int i = k; i >= 0; i--) {
			minimize(ans, dp[u][v][i]);
		}

		if(ans == INF) ans = -1;
		cout << ans << '\n';
	}
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int tc = 1, ddd = 0;
    // cin >> tc;
    while(tc--) {
        //ddd++;
        //cout << "Case #" << ddd << ": ";
        BaoJiaoPisu();
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:119:17: warning: unused variable 'ddd' [-Wunused-variable]
  119 |     int tc = 1, ddd = 0;
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1820 KB Output is correct
2 Correct 38 ms 1740 KB Output is correct
3 Correct 46 ms 1876 KB Output is correct
4 Correct 38 ms 1868 KB Output is correct
5 Correct 37 ms 1824 KB Output is correct
6 Correct 38 ms 1812 KB Output is correct
7 Correct 37 ms 1828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 36 ms 1764 KB Output is correct
8 Correct 37 ms 1868 KB Output is correct
9 Correct 37 ms 1832 KB Output is correct
10 Correct 43 ms 1800 KB Output is correct
11 Correct 39 ms 1860 KB Output is correct
12 Correct 53 ms 1888 KB Output is correct
13 Correct 139 ms 4932 KB Output is correct
14 Correct 127 ms 5008 KB Output is correct
15 Correct 126 ms 5008 KB Output is correct
16 Correct 127 ms 4840 KB Output is correct
17 Correct 131 ms 4836 KB Output is correct
18 Correct 124 ms 4936 KB Output is correct
19 Correct 153 ms 4868 KB Output is correct
20 Correct 133 ms 4840 KB Output is correct
21 Correct 129 ms 4900 KB Output is correct
22 Correct 125 ms 4876 KB Output is correct
23 Correct 131 ms 5004 KB Output is correct
24 Correct 127 ms 4972 KB Output is correct
25 Correct 125 ms 5144 KB Output is correct
26 Correct 138 ms 5052 KB Output is correct
27 Correct 122 ms 4984 KB Output is correct
28 Correct 125 ms 5036 KB Output is correct
29 Correct 124 ms 4864 KB Output is correct
30 Correct 131 ms 4908 KB Output is correct
31 Correct 123 ms 4920 KB Output is correct
32 Correct 131 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 37 ms 1820 KB Output is correct
8 Correct 38 ms 1740 KB Output is correct
9 Correct 46 ms 1876 KB Output is correct
10 Correct 38 ms 1868 KB Output is correct
11 Correct 37 ms 1824 KB Output is correct
12 Correct 38 ms 1812 KB Output is correct
13 Correct 37 ms 1828 KB Output is correct
14 Correct 36 ms 1764 KB Output is correct
15 Correct 37 ms 1868 KB Output is correct
16 Correct 37 ms 1832 KB Output is correct
17 Correct 43 ms 1800 KB Output is correct
18 Correct 39 ms 1860 KB Output is correct
19 Correct 53 ms 1888 KB Output is correct
20 Correct 139 ms 4932 KB Output is correct
21 Correct 127 ms 5008 KB Output is correct
22 Correct 126 ms 5008 KB Output is correct
23 Correct 127 ms 4840 KB Output is correct
24 Correct 131 ms 4836 KB Output is correct
25 Correct 124 ms 4936 KB Output is correct
26 Correct 153 ms 4868 KB Output is correct
27 Correct 133 ms 4840 KB Output is correct
28 Correct 129 ms 4900 KB Output is correct
29 Correct 125 ms 4876 KB Output is correct
30 Correct 131 ms 5004 KB Output is correct
31 Correct 127 ms 4972 KB Output is correct
32 Correct 125 ms 5144 KB Output is correct
33 Correct 138 ms 5052 KB Output is correct
34 Correct 122 ms 4984 KB Output is correct
35 Correct 125 ms 5036 KB Output is correct
36 Correct 124 ms 4864 KB Output is correct
37 Correct 131 ms 4908 KB Output is correct
38 Correct 123 ms 4920 KB Output is correct
39 Correct 131 ms 4812 KB Output is correct
40 Correct 50 ms 1824 KB Output is correct
41 Correct 37 ms 1800 KB Output is correct
42 Correct 39 ms 1844 KB Output is correct
43 Correct 38 ms 1824 KB Output is correct
44 Correct 42 ms 1868 KB Output is correct
45 Correct 42 ms 1884 KB Output is correct
46 Correct 133 ms 4796 KB Output is correct
47 Correct 126 ms 4788 KB Output is correct
48 Correct 131 ms 4984 KB Output is correct
49 Correct 123 ms 4916 KB Output is correct
50 Correct 124 ms 4980 KB Output is correct
51 Correct 132 ms 5132 KB Output is correct
52 Correct 131 ms 5140 KB Output is correct
53 Correct 118 ms 5068 KB Output is correct
54 Correct 145 ms 5036 KB Output is correct
55 Correct 126 ms 5676 KB Output is correct
56 Correct 132 ms 6116 KB Output is correct
57 Correct 125 ms 6220 KB Output is correct
58 Correct 158 ms 6340 KB Output is correct
59 Correct 131 ms 6416 KB Output is correct
60 Correct 133 ms 6424 KB Output is correct
61 Correct 131 ms 6564 KB Output is correct
62 Correct 124 ms 6464 KB Output is correct
63 Correct 125 ms 6552 KB Output is correct
64 Correct 153 ms 6408 KB Output is correct
65 Correct 138 ms 6528 KB Output is correct