답안 #714589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714589 2023-03-25T06:11:01 Z Melika0gh Toll (BOI17_toll) C++17
56 / 100
3000 ms 5884 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define sync        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define fi          first
#define se          second

const int maxn = 5e4 + 10, inf = 1e9 + 7, maxsq = 400, maxlg = 21;
//const int mood2 = 97277821, mood3 = 34098487, base = 31;
vector<pair<int, int> > adj[maxn], q[maxn];
vector<int> vec;
int dp[maxn], id[maxn], res[maxn];
int k, n, m, o;

int main()
{
	cin >> k >> n >> m >> o;
	for(int i = 0; i < m; i++)
	{
		int v, u, w;
		cin >> v >> u >> w;
		adj[v].pb(mp(u, w));
	}
	for(int i = 0; i < o; i++)
	{
		int v, u;
		cin >> v >> u;
		q[u].pb(mp(v, i));
		vec.pb(u);
	}
	
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	
	for(int i = 0; i < vec.size(); i++)
		id[vec[i]] = i;
		
	for(auto x : vec)
	{
		fill(dp, dp+n, inf);
		int xx = id[x];
		dp[x] = 0;
		for(int i = x-1; i >= 0; i--)
		{
			for(auto e : adj[i])
			{
				int u = e.fi, w = e.se;
				if(dp[u] >= inf)
					continue;
				dp[i] = min(dp[i], dp[u] + w);
			}
		}
		for(auto y : q[x])
			res[y.se] = dp[y.fi];
	}
	
	for(int i = 0; i < o; i++)
	{
		if(res[i] >= inf)
			cout << -1 << '\n';
		else
			cout << res[i] << '\n';
	}
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0; i < vec.size(); i++)
      |                 ~~^~~~~~~~~~~~
toll.cpp:45:7: warning: unused variable 'xx' [-Wunused-variable]
   45 |   int xx = id[x];
      |       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1347 ms 4984 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 1074 ms 4948 KB Output is correct
9 Correct 1025 ms 4872 KB Output is correct
10 Correct 387 ms 3388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1714 ms 4956 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 8 ms 2944 KB Output is correct
8 Correct 11 ms 2956 KB Output is correct
9 Correct 755 ms 4956 KB Output is correct
10 Correct 2334 ms 5716 KB Output is correct
11 Correct 1619 ms 4956 KB Output is correct
12 Correct 1755 ms 4896 KB Output is correct
13 Correct 780 ms 5620 KB Output is correct
14 Correct 533 ms 4564 KB Output is correct
15 Correct 612 ms 4232 KB Output is correct
16 Correct 599 ms 4348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2712 KB Output is correct
8 Correct 5 ms 2772 KB Output is correct
9 Correct 5 ms 2712 KB Output is correct
10 Correct 68 ms 4452 KB Output is correct
11 Correct 134 ms 4548 KB Output is correct
12 Correct 154 ms 5328 KB Output is correct
13 Correct 173 ms 5688 KB Output is correct
14 Correct 167 ms 5068 KB Output is correct
15 Correct 84 ms 4192 KB Output is correct
16 Correct 82 ms 4172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2712 KB Output is correct
8 Correct 5 ms 2772 KB Output is correct
9 Correct 5 ms 2712 KB Output is correct
10 Correct 68 ms 4452 KB Output is correct
11 Correct 134 ms 4548 KB Output is correct
12 Correct 154 ms 5328 KB Output is correct
13 Correct 173 ms 5688 KB Output is correct
14 Correct 167 ms 5068 KB Output is correct
15 Correct 84 ms 4192 KB Output is correct
16 Correct 82 ms 4172 KB Output is correct
17 Correct 802 ms 4684 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2652 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 6 ms 2772 KB Output is correct
24 Correct 7 ms 2780 KB Output is correct
25 Correct 10 ms 2732 KB Output is correct
26 Correct 10 ms 2772 KB Output is correct
27 Correct 350 ms 4704 KB Output is correct
28 Correct 1158 ms 5512 KB Output is correct
29 Correct 1020 ms 5756 KB Output is correct
30 Correct 995 ms 5152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1347 ms 4984 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 4 ms 2644 KB Output is correct
7 Correct 3 ms 2644 KB Output is correct
8 Correct 1074 ms 4948 KB Output is correct
9 Correct 1025 ms 4872 KB Output is correct
10 Correct 387 ms 3388 KB Output is correct
11 Correct 1714 ms 4956 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 8 ms 2944 KB Output is correct
18 Correct 11 ms 2956 KB Output is correct
19 Correct 755 ms 4956 KB Output is correct
20 Correct 2334 ms 5716 KB Output is correct
21 Correct 1619 ms 4956 KB Output is correct
22 Correct 1755 ms 4896 KB Output is correct
23 Correct 780 ms 5620 KB Output is correct
24 Correct 533 ms 4564 KB Output is correct
25 Correct 612 ms 4232 KB Output is correct
26 Correct 599 ms 4348 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 1 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 3 ms 2712 KB Output is correct
34 Correct 5 ms 2772 KB Output is correct
35 Correct 5 ms 2712 KB Output is correct
36 Correct 68 ms 4452 KB Output is correct
37 Correct 134 ms 4548 KB Output is correct
38 Correct 154 ms 5328 KB Output is correct
39 Correct 173 ms 5688 KB Output is correct
40 Correct 167 ms 5068 KB Output is correct
41 Correct 84 ms 4192 KB Output is correct
42 Correct 82 ms 4172 KB Output is correct
43 Correct 802 ms 4684 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2652 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 6 ms 2772 KB Output is correct
50 Correct 7 ms 2780 KB Output is correct
51 Correct 10 ms 2732 KB Output is correct
52 Correct 10 ms 2772 KB Output is correct
53 Correct 350 ms 4704 KB Output is correct
54 Correct 1158 ms 5512 KB Output is correct
55 Correct 1020 ms 5756 KB Output is correct
56 Correct 995 ms 5152 KB Output is correct
57 Execution timed out 3039 ms 5884 KB Time limit exceeded
58 Halted 0 ms 0 KB -