답안 #131953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131953 2019-07-18T05:59:00 Z 임유진(#3191) Wild Boar (JOI18_wild_boar) C++14
47 / 100
18000 ms 4716 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 2005
#define MAXL 100005
#define fi first
#define se second

typedef long long lint;
typedef pair<lint, int> pli;

const lint LINF = 1ll << 60;
int A[MAXN], B[MAXN], C[MAXN], X[MAXL];
vector<int> ed[2 * MAXN];
vector<lint> dp;
vector<int> in[MAXN], out[MAXN];

int main() {
	int N, M, T, L;
	int P, Q;

	scanf("%d%d%d%d", &N, &M, &T, &L);
	for(int i = 0; i < M; i++) scanf("%d%d%d", A + i, B + i, C + i);
	for(int i = 0; i < L; i++) scanf("%d", X + i);
	scanf("%d%d", &P, &Q);

	X[P - 1] = Q;
	for(int i = 1; i <= N; i++) {
		for(int j = 0; j < M; j++) {
			if(A[j] == i) {
				out[i].push_back(j);
				in[i].push_back(j + M);
			}
			else if(B[j] == i) {
				in[i].push_back(j);
				out[i].push_back(j + M);
			}
		}
		for(auto a : in[i]) for(auto b : out[i]) if(a % M != b % M) ed[a].push_back(b);
	}

	dp.resize(2 * M, 0ll);
	for(auto a : out[X[0]]) dp[a] = C[a % M];
	for(int i = 0; i < L - 1; i++) {
		priority_queue<pli, vector<pli>, greater<pli> > pq;
		vector<lint> v(2 * M, LINF);
		for(auto a : out[X[i]]) {
			v[a] = dp[a];
			pq.push(make_pair(dp[a], a));
		}
		swap(dp, v);
		while(!pq.empty()) {
			pli t = pq.top();
			pq.pop();
			if(dp[t.se] != t.fi) continue;
			for(auto a : ed[t.se]) if(t.fi + C[a % M] < dp[a]) {
				dp[a] = t.fi + C[a % M];
				pq.push(make_pair(dp[a], a));
			}
		}
	}

	lint ans = LINF;
	for(auto a : in[X[L - 1]]) ans = min(ans, dp[a]);
	printf("%lld", ans == LINF ? -1 : ans);
	return 0;
}

Compilation message

wild_boar.cpp: In function 'int main()':
wild_boar.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &N, &M, &T, &L);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:24:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < M; i++) scanf("%d%d%d", A + i, B + i, C + i);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:25:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < L; i++) scanf("%d", X + i);
                             ~~~~~^~~~~~~~~~~~~
wild_boar.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &P, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 476 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 476 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 53 ms 888 KB Output is correct
28 Correct 55 ms 888 KB Output is correct
29 Correct 8876 ms 1016 KB Output is correct
30 Correct 10426 ms 1036 KB Output is correct
31 Correct 14425 ms 1088 KB Output is correct
32 Correct 14392 ms 1144 KB Output is correct
33 Correct 8132 ms 1008 KB Output is correct
34 Correct 8240 ms 1012 KB Output is correct
35 Correct 12634 ms 1076 KB Output is correct
36 Correct 11323 ms 1044 KB Output is correct
37 Correct 8140 ms 1016 KB Output is correct
38 Correct 7493 ms 888 KB Output is correct
39 Correct 8683 ms 1016 KB Output is correct
40 Correct 7534 ms 1000 KB Output is correct
41 Correct 7463 ms 992 KB Output is correct
42 Correct 6899 ms 1016 KB Output is correct
43 Correct 6235 ms 1016 KB Output is correct
44 Correct 6360 ms 1116 KB Output is correct
45 Correct 2330 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 476 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 53 ms 888 KB Output is correct
28 Correct 55 ms 888 KB Output is correct
29 Correct 8876 ms 1016 KB Output is correct
30 Correct 10426 ms 1036 KB Output is correct
31 Correct 14425 ms 1088 KB Output is correct
32 Correct 14392 ms 1144 KB Output is correct
33 Correct 8132 ms 1008 KB Output is correct
34 Correct 8240 ms 1012 KB Output is correct
35 Correct 12634 ms 1076 KB Output is correct
36 Correct 11323 ms 1044 KB Output is correct
37 Correct 8140 ms 1016 KB Output is correct
38 Correct 7493 ms 888 KB Output is correct
39 Correct 8683 ms 1016 KB Output is correct
40 Correct 7534 ms 1000 KB Output is correct
41 Correct 7463 ms 992 KB Output is correct
42 Correct 6899 ms 1016 KB Output is correct
43 Correct 6235 ms 1016 KB Output is correct
44 Correct 6360 ms 1116 KB Output is correct
45 Correct 2330 ms 1016 KB Output is correct
46 Correct 11 ms 632 KB Output is correct
47 Execution timed out 18041 ms 4716 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 508 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 476 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 504 KB Output is correct
25 Correct 2 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 53 ms 888 KB Output is correct
28 Correct 55 ms 888 KB Output is correct
29 Correct 8876 ms 1016 KB Output is correct
30 Correct 10426 ms 1036 KB Output is correct
31 Correct 14425 ms 1088 KB Output is correct
32 Correct 14392 ms 1144 KB Output is correct
33 Correct 8132 ms 1008 KB Output is correct
34 Correct 8240 ms 1012 KB Output is correct
35 Correct 12634 ms 1076 KB Output is correct
36 Correct 11323 ms 1044 KB Output is correct
37 Correct 8140 ms 1016 KB Output is correct
38 Correct 7493 ms 888 KB Output is correct
39 Correct 8683 ms 1016 KB Output is correct
40 Correct 7534 ms 1000 KB Output is correct
41 Correct 7463 ms 992 KB Output is correct
42 Correct 6899 ms 1016 KB Output is correct
43 Correct 6235 ms 1016 KB Output is correct
44 Correct 6360 ms 1116 KB Output is correct
45 Correct 2330 ms 1016 KB Output is correct
46 Correct 11 ms 632 KB Output is correct
47 Execution timed out 18041 ms 4716 KB Time limit exceeded
48 Halted 0 ms 0 KB -