QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#734370 | #9569. Subway | BreakPlus | WA | 4ms | 31080kb | C++14 | 2.3kb | 2024-11-11 09:29:59 | 2024-11-11 09:30:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
ll x=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
return x*f;
}
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
ll ans=1, base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod; b>>=1;
}
return ans;
}
void init(){ }
const int B = 550;
int n,k,a[200005],b[200005],id[400005],bel[400005],nxt[400005],w[400005];
struct cmp{
bool operator()(const int &x, const int &y){
return a[bel[x]]!=a[bel[y]]?a[bel[x]]<a[bel[y]]:x<y;
}
};
vector<int>t[200005];
set<int,cmp>v[200005];
int stk[200005], hd, tp, cnt; bool vis[200005];
ll dis[400005], ans[200005];
priority_queue<pair<int,ll>, vector<pair<int,ll>>, greater<pair<int,ll>>>q;
void procedure(){
n=read(), k=read();
for(int i=1;i<=k;i++) a[i]=read();
for(int i=1;i<=k;i++) b[i]=read();
for(int i=1;i<=k;i++){
int q=read();
for(int j=1;j<=q;j++){
id[++cnt]=read(); bel[cnt]=i; v[id[cnt]].insert(cnt);
if(j<q) nxt[cnt]=cnt+1, w[cnt]=read();
}
}
memset(dis, 0x3f, sizeof(dis));
memset(ans, 0x3f, sizeof(ans));
for(auto x: v[1]){
dis[x] = 0; q.push(mkp(0, x));
}
v[1].clear();
while(!q.empty()){
int x=q.top().se; q.pop();
if(vis[x]) continue; vis[x]=1;
if(nxt[x] && dis[nxt[x]] > dis[x] + w[x]){
dis[nxt[x]] = dis[x] + w[x];
q.push(mkp(dis[nxt[x]], nxt[x]));
}
if(id[x]==1) continue;
v[id[x]].erase(x);
t[id[x]].pb(x);
if(!v[id[x]].size()) continue;
int y = *v[id[x]].begin();
for(auto i: t[id[x]]){
dis[y] = min(dis[y], dis[i] + 1ll * b[bel[i]] * a[bel[y]]);
}
q.push(mkp(dis[y], y));
}
for(int i=1;i<=cnt;i++) ans[id[i]] = min(ans[id[i]], dis[i]);
for(int i=2;i<=n;i++) printf("%lld ", ans[i]);
}
int main(){
#ifdef LOCAL
assert(freopen("input.txt","r",stdin));
assert(freopen("output.txt","w",stdout));
#endif
ll T=1;
init();
while(T--) procedure();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 31080kb
input:
6 3 1 5 1 5 5 1 3 1 2 2 3 3 3 5 1 2 1 4 3 3 4 5 4 6
output:
2 5 21 14 18
result:
ok 5 number(s): "2 5 21 14 18"
Test #2:
score: 0
Accepted
time: 0ms
memory: 30388kb
input:
6 3 1 5 1 5 5 1 5 1 2 2 100 3 100 6 1 4 5 1 100 2 4 3 100 5 1 4 2 3 1 5
output:
2 31 43 37 136
result:
ok 5 number(s): "2 31 43 37 136"
Test #3:
score: 0
Accepted
time: 4ms
memory: 28952kb
input:
5 9 278281 70119 511791 834898 25300 63487 609134 236836 394497 835557 287345 579404 879128 636344 306393 569430 152565 47119 2 3 823004250 4 2 1 25427550 3 2 1 15849621 3 2 1 701911826 5 3 5 679672631 3 907176714 2 2 1 817370554 2 2 3 697987914 2 2 4 873900795 2 2 1 814305954 5
output:
817370554 15849621 80811085745 701911826
result:
ok 4 number(s): "817370554 15849621 80811085745 701911826"
Test #4:
score: 0
Accepted
time: 0ms
memory: 28908kb
input:
5 10 436148 103565 528276 212202 680282 92724 609031 560815 80390 406327 546832 581372 731920 348686 791433 98906 112247 118131 361076 724950 4 1 213029090 4 415633732 5 581145231 3 2 4 306227294 2 2 1 713116112 4 2 3 99672714 5 2 3 975143846 1 5 4 249118026 5 689334413 1 597093740 2 553624319 3 3 4...
output:
597093740 765908995 213029090 628662822
result:
ok 4 number(s): "597093740 765908995 213029090 628662822"
Test #5:
score: 0
Accepted
time: 0ms
memory: 30692kb
input:
3 5 696710 837216 390019 431068 960618 589388 829806 692481 154511 282620 2 1 711629163 3 2 1 781784306 3 2 1 686636041 3 2 3 794790206 2 2 1 844212542 2
output:
844212542 686636041
result:
ok 2 number(s): "844212542 686636041"
Test #6:
score: 0
Accepted
time: 0ms
memory: 30648kb
input:
3 8 344877 101098 328614 735002 476606 635558 573861 261083 964379 333960 25186 276560 258996 683650 765559 582374 2 3 838262394 1 2 2 863940316 3 2 2 476918371 3 3 3 320092619 1 400754003 2 3 3 150885055 2 90507792 1 2 3 190275693 2 2 2 600234969 3 2 2 679446528 3
output:
400754003 29224357199
result:
ok 2 number(s): "400754003 29224357199"
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 30988kb
input:
50 52 895514 29433 851800 887860 340384 95967 506578 666268 850660 602220 717255 242039 34055 752012 248567 170469 505996 823344 143369 390858 112988 892365 15368 617804 351619 557340 788960 990487 283825 272924 24678 130649 341049 980236 558990 254726 682005 963825 953074 603477 706464 340694 23541...
output:
632126151 479346918 492618840 3695787776 22624579200 174047740 416387993526 21429733469 29010353943 203893499 522142321620 977566721 279122223 98659158855 804573598 250379455515 22466373513 224856032596 416404080694 75356833904 69909552850 4504114918 13173874327 1104455938 278587376156 136977429637 ...
result:
wrong answer 9th numbers differ - expected: '15831777447', found: '29010353943'