답안 #209165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
209165 2020-03-13T09:57:45 Z songc Wild Boar (JOI18_wild_boar) C++14
47 / 100
18000 ms 134104 KB
#include <bits/stdc++.h>
#define pb push_back
#define all(v) v.begin(),v.end()
#define lb lower_bound
#define fi first
#define se second
#define INF (1ll<<60)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M, Q, L;
int P[101010];
int num[2020][2020], nm;
LL D[4040][4040];
bool chk[4040];
vector<pii> adj[2020];

struct Path{
	int u, v;
	LL w;
	bool operator<(const Path &r)const{
		return w > r.w;
	}
};
priority_queue<Path> PQ;

struct Node{
	Path p[4];
}C[2020][2020], T[404040];

void dijk(int a, int b){
	PQ.push((Path){a, b, 0});
	while (!PQ.empty()){
		Path T = PQ.top();
		PQ.pop();
		if (D[num[a][b]][num[T.u][T.v]] != INF) continue;
		D[num[a][b]][num[T.u][T.v]] = T.w;
		for (pii x : adj[T.u]) if (x.fi != T.v) PQ.push((Path){x.fi, T.u, T.w+x.se});
	}
}

Path add(Path a, Path b){
	return (Path){a.u, b.v, (a.v==b.u)?INF:min(INF,a.w+b.w)};
}

Node add(Node a, Node b){
	Node ret;
	for (int i=0; i<4; i++) ret.p[i].w=INF;
	vector<Path> v;
	for (int i=0; i<4; i++) for (int j=0; j<4; j++) v.pb(add(a.p[i], b.p[j]));
	for (Path x : v) ret.p[0] = max(ret.p[0], x);
	for (Path x : v) if (ret.p[0].u != x.u && ret.p[0].v != x.v) ret.p[1] = max(ret.p[1], x);
	for (Path x : v) if (ret.p[1].u != x.u && ret.p[0].v != x.v) ret.p[2] = max(ret.p[2], x);
	for (Path x : v) if (ret.p[0].u != x.u && ret.p[1].v != x.v) ret.p[3] = max(ret.p[3], x);
	return ret;
}

void init(int id, int s, int e){
	if (s+1 == e){
		T[id] = C[P[s]][P[e]];
		return;
	}
	int mid=(s+e)/2;
	init(id*2, s, mid), init(id*2+1, mid, e);
	T[id] = add(T[id*2], T[id*2+1]);
}

void upd(int id, int s, int e, int t){
	if (e < t || t < s) return;
	if (s+1 == e){
		T[id] = C[P[s]][P[e]];
		return;
	}
	int mid=(s+e)/2;
	upd(id*2, s, mid, t), upd(id*2+1, mid, e, t);
	T[id] = add(T[id*2], T[id*2+1]);
}

int main(){
	scanf("%d %d %d %d", &N, &M, &Q, &L);
	for (int i=1; i<=M; i++){
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		adj[u].pb(pii(v, w)), adj[v].pb(pii(u, w));
	}
	for (int u=1; u<=N; u++) for (pii v : adj[u]) num[u][v.fi]=++nm;
	for (int i=1; i<=nm; i++) for (int j=1; j<=nm; j++) D[i][j] = INF;
	for (int u=1; u<=N; u++) for (pii v : adj[u]) dijk(u, v.fi);
	for (int i=1; i<=N; i++) for (int j=1; j<=N; j++){
		if (i == j) continue;
		for (int k=0; k<4; k++) C[i][j].p[k].w = INF;
		vector<Path> V;
		for (pii u : adj[i]) for (pii v : adj[j]) V.pb((Path){u.fi, v.fi, D[num[u.fi][i]][num[j][v.fi]]+u.se});
		for (Path x : V) C[i][j].p[0] = max(C[i][j].p[0], x);
		for (Path x : V) if (C[i][j].p[0].u != x.u && C[i][j].p[0].v != x.v) C[i][j].p[1] = max(C[i][j].p[1], x);
		for (Path x : V) if (C[i][j].p[1].u != x.u && C[i][j].p[0].v != x.v) C[i][j].p[2] = max(C[i][j].p[2], x);
		for (Path x : V) if (C[i][j].p[0].u != x.u && C[i][j].p[1].v != x.v) C[i][j].p[3] = max(C[i][j].p[3], x);
	}
	for (int i=1; i<=L; i++) scanf("%d", &P[i]);
	init(1, 1, L);
	while(Q--){
		int a, b;
		scanf("%d %d", &a, &b);
		P[a]=b;
		upd(1, 1, L, a);
		if (T[1].p[0].w >= INF) puts("-1");
		else printf("%lld\n", T[1].p[0].w);
	}
	return 0;
}

Compilation message

wild_boar.cpp: In function 'int main()':
wild_boar.cpp:81: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, &Q, &L);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &u, &v, &w);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:100:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=1; i<=L; i++) scanf("%d", &P[i]);
                           ~~~~~^~~~~~~~~~~~~
wild_boar.cpp:104:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 5 ms 508 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 6 ms 632 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 508 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 504 KB Output is correct
22 Correct 5 ms 504 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 5 ms 508 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 6 ms 632 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 508 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 504 KB Output is correct
22 Correct 5 ms 504 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 8 ms 1016 KB Output is correct
27 Correct 95 ms 20088 KB Output is correct
28 Correct 95 ms 20092 KB Output is correct
29 Correct 333 ms 24312 KB Output is correct
30 Correct 587 ms 24440 KB Output is correct
31 Correct 1301 ms 24492 KB Output is correct
32 Correct 1303 ms 24360 KB Output is correct
33 Correct 249 ms 25592 KB Output is correct
34 Correct 250 ms 25464 KB Output is correct
35 Correct 1065 ms 25620 KB Output is correct
36 Correct 796 ms 25592 KB Output is correct
37 Correct 255 ms 25492 KB Output is correct
38 Correct 212 ms 27052 KB Output is correct
39 Correct 428 ms 27020 KB Output is correct
40 Correct 207 ms 27128 KB Output is correct
41 Correct 225 ms 27004 KB Output is correct
42 Correct 337 ms 28088 KB Output is correct
43 Correct 167 ms 28856 KB Output is correct
44 Correct 166 ms 28792 KB Output is correct
45 Correct 120 ms 31164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 5 ms 508 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 6 ms 632 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 508 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 504 KB Output is correct
22 Correct 5 ms 504 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 8 ms 1016 KB Output is correct
27 Correct 95 ms 20088 KB Output is correct
28 Correct 95 ms 20092 KB Output is correct
29 Correct 333 ms 24312 KB Output is correct
30 Correct 587 ms 24440 KB Output is correct
31 Correct 1301 ms 24492 KB Output is correct
32 Correct 1303 ms 24360 KB Output is correct
33 Correct 249 ms 25592 KB Output is correct
34 Correct 250 ms 25464 KB Output is correct
35 Correct 1065 ms 25620 KB Output is correct
36 Correct 796 ms 25592 KB Output is correct
37 Correct 255 ms 25492 KB Output is correct
38 Correct 212 ms 27052 KB Output is correct
39 Correct 428 ms 27020 KB Output is correct
40 Correct 207 ms 27128 KB Output is correct
41 Correct 225 ms 27004 KB Output is correct
42 Correct 337 ms 28088 KB Output is correct
43 Correct 167 ms 28856 KB Output is correct
44 Correct 166 ms 28792 KB Output is correct
45 Correct 120 ms 31164 KB Output is correct
46 Correct 613 ms 16700 KB Output is correct
47 Execution timed out 18080 ms 134104 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 504 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 5 ms 508 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 5 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 508 KB Output is correct
10 Correct 6 ms 632 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 5 ms 508 KB Output is correct
17 Correct 5 ms 504 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 504 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 504 KB Output is correct
22 Correct 5 ms 504 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 5 ms 504 KB Output is correct
25 Correct 5 ms 504 KB Output is correct
26 Correct 8 ms 1016 KB Output is correct
27 Correct 95 ms 20088 KB Output is correct
28 Correct 95 ms 20092 KB Output is correct
29 Correct 333 ms 24312 KB Output is correct
30 Correct 587 ms 24440 KB Output is correct
31 Correct 1301 ms 24492 KB Output is correct
32 Correct 1303 ms 24360 KB Output is correct
33 Correct 249 ms 25592 KB Output is correct
34 Correct 250 ms 25464 KB Output is correct
35 Correct 1065 ms 25620 KB Output is correct
36 Correct 796 ms 25592 KB Output is correct
37 Correct 255 ms 25492 KB Output is correct
38 Correct 212 ms 27052 KB Output is correct
39 Correct 428 ms 27020 KB Output is correct
40 Correct 207 ms 27128 KB Output is correct
41 Correct 225 ms 27004 KB Output is correct
42 Correct 337 ms 28088 KB Output is correct
43 Correct 167 ms 28856 KB Output is correct
44 Correct 166 ms 28792 KB Output is correct
45 Correct 120 ms 31164 KB Output is correct
46 Correct 613 ms 16700 KB Output is correct
47 Execution timed out 18080 ms 134104 KB Time limit exceeded
48 Halted 0 ms 0 KB -