# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
584287 |
2022-06-27T07:20:20 Z |
반딧불(#8375) |
Wild Boar (JOI18_wild_boar) |
C++17 |
|
18000 ms |
215592 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Edge{
int s, e, i; ll v;
Edge(){}
Edge(int s, int e, int i, ll v): s(s), e(e), i(i), v(v){}
};
struct dat{
int x; ll y;
dat(){}
dat(int x, ll y): x(x), y(y){}
bool operator<(const dat &r)const{
return y>r.y;
}
};
int n, m, k, l;
vector<int> link[2002];
vector<int> revLink[2002];
Edge edge[4002];
int arr[100002];
ll dist[4002][4002];
vector<pair<ll, int> > distVec[2002][4002];
void init(){
for(int i=0; i<m*2; i++){
for(int j=0; j<m*2; j++) dist[i][j] = 1e18;
priority_queue<dat> pq;
pq.push(dat(i, 0));
while(!pq.empty()){
dat tmp = pq.top(); pq.pop();
if(dist[i][tmp.x] < 1e18) continue;
int xe = tmp.x, x = edge[xe].e;
dist[i][xe] = tmp.y;
for(auto ye: link[x]){
if((xe^ye) == 1) continue;
pq.push(dat(ye, tmp.y + edge[ye].v));
}
}
}
/// ����
for(int i=1; i<=n; i++){
for(int j=0; j<m*2; j++){
for(auto c: link[i]){ /// c: i���� ������ ����
distVec[i][j].push_back(make_pair(dist[c][j]+edge[c].v, c));
for(int pnt=(int)distVec[i][j].size()-1; pnt>0; pnt--){
if(distVec[i][j][pnt-1] > distVec[i][j][pnt]){
swap(distVec[i][j][pnt-1], distVec[i][j][pnt]);
}
else break;
}
if((int)distVec[i][j].size() >= 3) distVec[i][j].pop_back();
}
}
}
}
ll DP[2][4002];
void solve(){
for(int i=0; i<m*2; i++) DP[0][i] = DP[1][i] = 1e18;
for(int i=0; i<m*2; i++){
if(edge[i].e != arr[2]) continue;
for(auto s: link[arr[1]]){
DP[0][i] = min(DP[0][i], dist[s][i]+edge[s].v);
}
}
for(int d=3; d<=l; d++){
int b = d%2;
for(int i=0; i<m*2; i++) DP[b][i] = 1e18;
vector<pair<ll, int> > vec;
for(int c=0; c<m*2; c++){
if(edge[c].e == arr[d-1]){
vec.push_back(make_pair(DP[!b][c], c));
for(int pnt=(int)vec.size()-1; pnt>0; pnt--){
if(vec[pnt-1] > vec[pnt]){
swap(vec[pnt-1], vec[pnt]);
}
else break;
}
if((int)vec.size() >= 3) vec.pop_back();
}
}
for(int c=0; c<m*2; c++){ /// d�� ���ϴ� ���� ���� ��ȣ
if(edge[c].e != arr[d]) continue;
for(pair<ll, int> p1: vec){ /// ��� ������ ���� �����
for(pair<ll, int> p2: distVec[arr[d-1]][c]){ /// d�� ���ϴ� �����
if((p1.second ^ p2.second) == 1) continue;
DP[b][c] = min(DP[b][c], p1.first + p2.first);
}
}
}
}
ll ans = 1e18;
for(int i=0; i<m*2; i++) if(edge[i].e == arr[l]) ans = min(ans, DP[l%2][i]);
printf("%lld\n", ans == 1e18 ? -1 : ans);
}
int main(){
scanf("%d %d %d %d", &n, &m, &k, &l);
for(int i=0; i<m; i++){
scanf("%d %d %lld", &edge[i*2].s, &edge[i*2].e, &edge[i*2].v);
edge[i*2+1] = edge[i*2];
swap(edge[i*2+1].s, edge[i*2+1].e);
edge[i*2].i = i*2, edge[i*2+1].i = i*2+1;
link[edge[i*2].s].push_back(i*2);
link[edge[i*2+1].s].push_back(i*2+1);
revLink[edge[i*2].e].push_back(i*2);
revLink[edge[i*2+1].e].push_back(i*2+1);
}
init();
for(int i=1; i<=l; i++) scanf("%d", &arr[i]);
for(int i=1; i<=k; i++){
int x, y;
scanf("%d %d", &x, &y);
arr[x] = y;
solve();
}
}
Compilation message
wild_boar.cpp: In function 'int main()':
wild_boar.cpp:106:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | scanf("%d %d %d %d", &n, &m, &k, &l);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:108:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
108 | scanf("%d %d %lld", &edge[i*2].s, &edge[i*2].e, &edge[i*2].v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:120:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
120 | for(int i=1; i<=l; i++) scanf("%d", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~
wild_boar.cpp:123:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
123 | scanf("%d %d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
188492 KB |
Output is correct |
2 |
Correct |
85 ms |
188620 KB |
Output is correct |
3 |
Correct |
88 ms |
188648 KB |
Output is correct |
4 |
Correct |
93 ms |
188616 KB |
Output is correct |
5 |
Correct |
89 ms |
188580 KB |
Output is correct |
6 |
Correct |
90 ms |
188588 KB |
Output is correct |
7 |
Correct |
88 ms |
188620 KB |
Output is correct |
8 |
Correct |
88 ms |
188636 KB |
Output is correct |
9 |
Correct |
87 ms |
188596 KB |
Output is correct |
10 |
Correct |
92 ms |
188692 KB |
Output is correct |
11 |
Correct |
90 ms |
188604 KB |
Output is correct |
12 |
Correct |
87 ms |
188596 KB |
Output is correct |
13 |
Correct |
90 ms |
188536 KB |
Output is correct |
14 |
Correct |
89 ms |
188564 KB |
Output is correct |
15 |
Correct |
90 ms |
188544 KB |
Output is correct |
16 |
Correct |
88 ms |
188620 KB |
Output is correct |
17 |
Correct |
88 ms |
188636 KB |
Output is correct |
18 |
Correct |
91 ms |
188648 KB |
Output is correct |
19 |
Correct |
90 ms |
188568 KB |
Output is correct |
20 |
Correct |
87 ms |
188652 KB |
Output is correct |
21 |
Correct |
88 ms |
188612 KB |
Output is correct |
22 |
Correct |
92 ms |
188640 KB |
Output is correct |
23 |
Correct |
90 ms |
188516 KB |
Output is correct |
24 |
Correct |
91 ms |
188640 KB |
Output is correct |
25 |
Correct |
86 ms |
188568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
188492 KB |
Output is correct |
2 |
Correct |
85 ms |
188620 KB |
Output is correct |
3 |
Correct |
88 ms |
188648 KB |
Output is correct |
4 |
Correct |
93 ms |
188616 KB |
Output is correct |
5 |
Correct |
89 ms |
188580 KB |
Output is correct |
6 |
Correct |
90 ms |
188588 KB |
Output is correct |
7 |
Correct |
88 ms |
188620 KB |
Output is correct |
8 |
Correct |
88 ms |
188636 KB |
Output is correct |
9 |
Correct |
87 ms |
188596 KB |
Output is correct |
10 |
Correct |
92 ms |
188692 KB |
Output is correct |
11 |
Correct |
90 ms |
188604 KB |
Output is correct |
12 |
Correct |
87 ms |
188596 KB |
Output is correct |
13 |
Correct |
90 ms |
188536 KB |
Output is correct |
14 |
Correct |
89 ms |
188564 KB |
Output is correct |
15 |
Correct |
90 ms |
188544 KB |
Output is correct |
16 |
Correct |
88 ms |
188620 KB |
Output is correct |
17 |
Correct |
88 ms |
188636 KB |
Output is correct |
18 |
Correct |
91 ms |
188648 KB |
Output is correct |
19 |
Correct |
90 ms |
188568 KB |
Output is correct |
20 |
Correct |
87 ms |
188652 KB |
Output is correct |
21 |
Correct |
88 ms |
188612 KB |
Output is correct |
22 |
Correct |
92 ms |
188640 KB |
Output is correct |
23 |
Correct |
90 ms |
188516 KB |
Output is correct |
24 |
Correct |
91 ms |
188640 KB |
Output is correct |
25 |
Correct |
86 ms |
188568 KB |
Output is correct |
26 |
Correct |
89 ms |
189072 KB |
Output is correct |
27 |
Correct |
147 ms |
191052 KB |
Output is correct |
28 |
Correct |
167 ms |
191056 KB |
Output is correct |
29 |
Correct |
423 ms |
198876 KB |
Output is correct |
30 |
Correct |
680 ms |
198792 KB |
Output is correct |
31 |
Correct |
1209 ms |
198984 KB |
Output is correct |
32 |
Correct |
1227 ms |
199036 KB |
Output is correct |
33 |
Correct |
357 ms |
200896 KB |
Output is correct |
34 |
Correct |
360 ms |
200848 KB |
Output is correct |
35 |
Correct |
1004 ms |
200460 KB |
Output is correct |
36 |
Correct |
770 ms |
200348 KB |
Output is correct |
37 |
Correct |
366 ms |
200984 KB |
Output is correct |
38 |
Correct |
325 ms |
202064 KB |
Output is correct |
39 |
Correct |
494 ms |
201456 KB |
Output is correct |
40 |
Correct |
308 ms |
202136 KB |
Output is correct |
41 |
Correct |
335 ms |
202108 KB |
Output is correct |
42 |
Correct |
431 ms |
202008 KB |
Output is correct |
43 |
Correct |
291 ms |
202808 KB |
Output is correct |
44 |
Correct |
292 ms |
202776 KB |
Output is correct |
45 |
Correct |
247 ms |
202664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
188492 KB |
Output is correct |
2 |
Correct |
85 ms |
188620 KB |
Output is correct |
3 |
Correct |
88 ms |
188648 KB |
Output is correct |
4 |
Correct |
93 ms |
188616 KB |
Output is correct |
5 |
Correct |
89 ms |
188580 KB |
Output is correct |
6 |
Correct |
90 ms |
188588 KB |
Output is correct |
7 |
Correct |
88 ms |
188620 KB |
Output is correct |
8 |
Correct |
88 ms |
188636 KB |
Output is correct |
9 |
Correct |
87 ms |
188596 KB |
Output is correct |
10 |
Correct |
92 ms |
188692 KB |
Output is correct |
11 |
Correct |
90 ms |
188604 KB |
Output is correct |
12 |
Correct |
87 ms |
188596 KB |
Output is correct |
13 |
Correct |
90 ms |
188536 KB |
Output is correct |
14 |
Correct |
89 ms |
188564 KB |
Output is correct |
15 |
Correct |
90 ms |
188544 KB |
Output is correct |
16 |
Correct |
88 ms |
188620 KB |
Output is correct |
17 |
Correct |
88 ms |
188636 KB |
Output is correct |
18 |
Correct |
91 ms |
188648 KB |
Output is correct |
19 |
Correct |
90 ms |
188568 KB |
Output is correct |
20 |
Correct |
87 ms |
188652 KB |
Output is correct |
21 |
Correct |
88 ms |
188612 KB |
Output is correct |
22 |
Correct |
92 ms |
188640 KB |
Output is correct |
23 |
Correct |
90 ms |
188516 KB |
Output is correct |
24 |
Correct |
91 ms |
188640 KB |
Output is correct |
25 |
Correct |
86 ms |
188568 KB |
Output is correct |
26 |
Correct |
89 ms |
189072 KB |
Output is correct |
27 |
Correct |
147 ms |
191052 KB |
Output is correct |
28 |
Correct |
167 ms |
191056 KB |
Output is correct |
29 |
Correct |
423 ms |
198876 KB |
Output is correct |
30 |
Correct |
680 ms |
198792 KB |
Output is correct |
31 |
Correct |
1209 ms |
198984 KB |
Output is correct |
32 |
Correct |
1227 ms |
199036 KB |
Output is correct |
33 |
Correct |
357 ms |
200896 KB |
Output is correct |
34 |
Correct |
360 ms |
200848 KB |
Output is correct |
35 |
Correct |
1004 ms |
200460 KB |
Output is correct |
36 |
Correct |
770 ms |
200348 KB |
Output is correct |
37 |
Correct |
366 ms |
200984 KB |
Output is correct |
38 |
Correct |
325 ms |
202064 KB |
Output is correct |
39 |
Correct |
494 ms |
201456 KB |
Output is correct |
40 |
Correct |
308 ms |
202136 KB |
Output is correct |
41 |
Correct |
335 ms |
202108 KB |
Output is correct |
42 |
Correct |
431 ms |
202008 KB |
Output is correct |
43 |
Correct |
291 ms |
202808 KB |
Output is correct |
44 |
Correct |
292 ms |
202776 KB |
Output is correct |
45 |
Correct |
247 ms |
202664 KB |
Output is correct |
46 |
Correct |
516 ms |
215592 KB |
Output is correct |
47 |
Execution timed out |
18088 ms |
202724 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
188492 KB |
Output is correct |
2 |
Correct |
85 ms |
188620 KB |
Output is correct |
3 |
Correct |
88 ms |
188648 KB |
Output is correct |
4 |
Correct |
93 ms |
188616 KB |
Output is correct |
5 |
Correct |
89 ms |
188580 KB |
Output is correct |
6 |
Correct |
90 ms |
188588 KB |
Output is correct |
7 |
Correct |
88 ms |
188620 KB |
Output is correct |
8 |
Correct |
88 ms |
188636 KB |
Output is correct |
9 |
Correct |
87 ms |
188596 KB |
Output is correct |
10 |
Correct |
92 ms |
188692 KB |
Output is correct |
11 |
Correct |
90 ms |
188604 KB |
Output is correct |
12 |
Correct |
87 ms |
188596 KB |
Output is correct |
13 |
Correct |
90 ms |
188536 KB |
Output is correct |
14 |
Correct |
89 ms |
188564 KB |
Output is correct |
15 |
Correct |
90 ms |
188544 KB |
Output is correct |
16 |
Correct |
88 ms |
188620 KB |
Output is correct |
17 |
Correct |
88 ms |
188636 KB |
Output is correct |
18 |
Correct |
91 ms |
188648 KB |
Output is correct |
19 |
Correct |
90 ms |
188568 KB |
Output is correct |
20 |
Correct |
87 ms |
188652 KB |
Output is correct |
21 |
Correct |
88 ms |
188612 KB |
Output is correct |
22 |
Correct |
92 ms |
188640 KB |
Output is correct |
23 |
Correct |
90 ms |
188516 KB |
Output is correct |
24 |
Correct |
91 ms |
188640 KB |
Output is correct |
25 |
Correct |
86 ms |
188568 KB |
Output is correct |
26 |
Correct |
89 ms |
189072 KB |
Output is correct |
27 |
Correct |
147 ms |
191052 KB |
Output is correct |
28 |
Correct |
167 ms |
191056 KB |
Output is correct |
29 |
Correct |
423 ms |
198876 KB |
Output is correct |
30 |
Correct |
680 ms |
198792 KB |
Output is correct |
31 |
Correct |
1209 ms |
198984 KB |
Output is correct |
32 |
Correct |
1227 ms |
199036 KB |
Output is correct |
33 |
Correct |
357 ms |
200896 KB |
Output is correct |
34 |
Correct |
360 ms |
200848 KB |
Output is correct |
35 |
Correct |
1004 ms |
200460 KB |
Output is correct |
36 |
Correct |
770 ms |
200348 KB |
Output is correct |
37 |
Correct |
366 ms |
200984 KB |
Output is correct |
38 |
Correct |
325 ms |
202064 KB |
Output is correct |
39 |
Correct |
494 ms |
201456 KB |
Output is correct |
40 |
Correct |
308 ms |
202136 KB |
Output is correct |
41 |
Correct |
335 ms |
202108 KB |
Output is correct |
42 |
Correct |
431 ms |
202008 KB |
Output is correct |
43 |
Correct |
291 ms |
202808 KB |
Output is correct |
44 |
Correct |
292 ms |
202776 KB |
Output is correct |
45 |
Correct |
247 ms |
202664 KB |
Output is correct |
46 |
Correct |
516 ms |
215592 KB |
Output is correct |
47 |
Execution timed out |
18088 ms |
202724 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |