# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
696947 |
2023-02-07T16:41:22 Z |
browntoad |
Robot (JOI21_ho_t4) |
C++14 |
|
1080 ms |
99328 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define pii pair<int, int>
#define ppi pair<int, pii>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
// #define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll maxn = 1e5+5;
const ll maxm = 2e5+5;
map<pii, bool> occ; // the special dp[i][j] state (if it is alr determined or not)
vector<int> dpv(maxn);
priority_queue<ppi, vector<ppi>, greater<ppi> > pq;
map<pii, int> vord;
map<pii, int> colcnt;
struct edge{
int to, c, p;
int idc; // for that node, the rank of the color
bool operator <(edge b){
return c<b.c;
}
};
vector<edge> e[maxn];
vector<vector<int> > ec;
int n, m;
signed main(){
IOS();
cin>>n>>m;
REP(i, m){
int u, v, c, p; cin>>u>>v>>c>>p;
e[u].pb({v, c, p, 0});
e[v].pb({u, c, p, 0});
}
REP1(i, n){
sort(ALL(e[i]));
vector<int> tmp;
REP(j, SZ(e[i])){
tmp.pb(j);
if (j==SZ(e[i])-1 ||e[i][j+1].c!=e[i][j].c){
vord[{i, e[i][j].c}]=SZ(ec);
ec.pb(tmp);
tmp.clear();
}
colcnt[{i, e[i][j].c}]+=e[i][j].p;
}
}
// compute dp
pq.push({0, {1, 0}});
int ans = -1;
while(pq.size()){
ppi tmp = pq.top(); pq.pop();
if (occ.count(tmp.s)) continue;
// cout<<tmp.f<<' '<<tmp.s.f<<' '<<tmp.s.s<<endl;
occ[tmp.s]=1;
if (tmp.s.f == n && tmp.s.s == 0){
ans=tmp.f;
break;
}
if (tmp.s.s == 0){
REP(i, SZ(e[tmp.s.f])){
edge tx = e[tmp.s.f][i];
if (!occ.count({tx.to, tx.c})){
pq.push({tmp.f, {tx.to, tx.c}});
}
if (!occ.count({tx.to, 0})){
// cout<<tmp.s.f<<' '<<tx.c<<' '<<colcnt[{tmp.s.f, tx.c}]<<endl;
pq.push({min(tx.p+tmp.f, colcnt[{tmp.s.f, tx.c}]-tx.p+tmp.f), {tx.to, 0}});
}
}
}
else{
int poop = vord[tmp.s];
REP(i, SZ(ec[poop])){
int tid = ec[poop][i];
edge tx = e[tmp.s.f][tid];
if (!occ.count({tx.to, 0})){
pq.push({colcnt[{tmp.s.f, tx.c}]-tx.p+tmp.f, {tx.to, 0}});
}
}
}
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3472 KB |
Output is correct |
3 |
Correct |
2 ms |
3468 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3468 KB |
Output is correct |
7 |
Correct |
3 ms |
3668 KB |
Output is correct |
8 |
Correct |
2 ms |
3540 KB |
Output is correct |
9 |
Correct |
6 ms |
4308 KB |
Output is correct |
10 |
Correct |
6 ms |
4244 KB |
Output is correct |
11 |
Correct |
4 ms |
4052 KB |
Output is correct |
12 |
Correct |
5 ms |
3992 KB |
Output is correct |
13 |
Correct |
7 ms |
3996 KB |
Output is correct |
14 |
Correct |
5 ms |
4052 KB |
Output is correct |
15 |
Correct |
4 ms |
3796 KB |
Output is correct |
16 |
Correct |
6 ms |
3924 KB |
Output is correct |
17 |
Correct |
5 ms |
3924 KB |
Output is correct |
18 |
Correct |
2 ms |
3668 KB |
Output is correct |
19 |
Correct |
5 ms |
4052 KB |
Output is correct |
20 |
Correct |
5 ms |
3916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
380 ms |
31672 KB |
Output is correct |
2 |
Correct |
153 ms |
17916 KB |
Output is correct |
3 |
Correct |
180 ms |
33304 KB |
Output is correct |
4 |
Correct |
162 ms |
22260 KB |
Output is correct |
5 |
Correct |
992 ms |
99328 KB |
Output is correct |
6 |
Correct |
989 ms |
81020 KB |
Output is correct |
7 |
Correct |
636 ms |
62488 KB |
Output is correct |
8 |
Correct |
811 ms |
56772 KB |
Output is correct |
9 |
Correct |
922 ms |
56772 KB |
Output is correct |
10 |
Correct |
487 ms |
50152 KB |
Output is correct |
11 |
Correct |
118 ms |
27648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3472 KB |
Output is correct |
3 |
Correct |
2 ms |
3468 KB |
Output is correct |
4 |
Correct |
2 ms |
3412 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3468 KB |
Output is correct |
7 |
Correct |
3 ms |
3668 KB |
Output is correct |
8 |
Correct |
2 ms |
3540 KB |
Output is correct |
9 |
Correct |
6 ms |
4308 KB |
Output is correct |
10 |
Correct |
6 ms |
4244 KB |
Output is correct |
11 |
Correct |
4 ms |
4052 KB |
Output is correct |
12 |
Correct |
5 ms |
3992 KB |
Output is correct |
13 |
Correct |
7 ms |
3996 KB |
Output is correct |
14 |
Correct |
5 ms |
4052 KB |
Output is correct |
15 |
Correct |
4 ms |
3796 KB |
Output is correct |
16 |
Correct |
6 ms |
3924 KB |
Output is correct |
17 |
Correct |
5 ms |
3924 KB |
Output is correct |
18 |
Correct |
2 ms |
3668 KB |
Output is correct |
19 |
Correct |
5 ms |
4052 KB |
Output is correct |
20 |
Correct |
5 ms |
3916 KB |
Output is correct |
21 |
Correct |
380 ms |
31672 KB |
Output is correct |
22 |
Correct |
153 ms |
17916 KB |
Output is correct |
23 |
Correct |
180 ms |
33304 KB |
Output is correct |
24 |
Correct |
162 ms |
22260 KB |
Output is correct |
25 |
Correct |
992 ms |
99328 KB |
Output is correct |
26 |
Correct |
989 ms |
81020 KB |
Output is correct |
27 |
Correct |
636 ms |
62488 KB |
Output is correct |
28 |
Correct |
811 ms |
56772 KB |
Output is correct |
29 |
Correct |
922 ms |
56772 KB |
Output is correct |
30 |
Correct |
487 ms |
50152 KB |
Output is correct |
31 |
Correct |
118 ms |
27648 KB |
Output is correct |
32 |
Correct |
229 ms |
35704 KB |
Output is correct |
33 |
Correct |
249 ms |
35652 KB |
Output is correct |
34 |
Correct |
531 ms |
52628 KB |
Output is correct |
35 |
Correct |
405 ms |
40832 KB |
Output is correct |
36 |
Correct |
592 ms |
50656 KB |
Output is correct |
37 |
Correct |
613 ms |
58792 KB |
Output is correct |
38 |
Correct |
497 ms |
62984 KB |
Output is correct |
39 |
Correct |
321 ms |
42216 KB |
Output is correct |
40 |
Correct |
830 ms |
58168 KB |
Output is correct |
41 |
Correct |
929 ms |
58380 KB |
Output is correct |
42 |
Correct |
1008 ms |
69268 KB |
Output is correct |
43 |
Correct |
317 ms |
35512 KB |
Output is correct |
44 |
Correct |
293 ms |
47760 KB |
Output is correct |
45 |
Correct |
748 ms |
51788 KB |
Output is correct |
46 |
Correct |
556 ms |
49864 KB |
Output is correct |
47 |
Correct |
763 ms |
55032 KB |
Output is correct |
48 |
Correct |
1080 ms |
97088 KB |
Output is correct |