Submission #50584144
Source Code Expand
// Author: XZC(L_Wave)
// Language: Cpp/G++14
// Problem: E - Last Train
// Contest: AtCoder - HUAWEI Programming Contest 2024(AtCoder Beginner Contest 342)
// URL: https://atcoder.jp/contests/abc342/tasks/abc342_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Create Time: not 2024-02-24 20:00:24, but 1926-08-17 11:45:14
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i <= i##ABRACADABRA; i++)
#define drep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i >= i##ABRACADABRA; i--)
using namespace std;
using ll = long long;
int n,m;
ll dis[200010];
struct Node {
ll l,r,d,k,c,u,v;
void read(){
scanf("%lld%lld%lld%lld%lld%lld",&l,&d,&k,&c,&v,&u);
l+=c;
r=l+(k-1)*d;
// cout<<l<<' '<<r<<'\n';
}
} p[200010];
vector<pair<int,int> >G[200010];
ll calc(ll d,int id){
// 模 p[id].d 与 p[id].l 同余
ll now=d-d%p[id].d+p[id].l%p[id].d;
// cout<<now<<' '<<p[id].l<<' '<<p[id].r<<'\n';
if (now>d)now-=p[id].d;
now=min(now,p[id].r);
if (now<p[id].l)return dis[0];
return now-p[id].c;
}
int main() {
scanf("%d%d",&n,&m);
rep(i,1,m)p[i].read();
rep(i,1,m)G[p[i].u].push_back({p[i].v,i});
memset(dis,0xcf,sizeof(dis));
dis[n]=4e18;
priority_queue<pair<ll,int>>Q;
Q.push({dis[n],n});
while (Q.size()){
auto [d,u]=Q.top();
Q.pop();
if (dis[u]!=d)continue;
for (auto [v,id]:G[u]){
if (dis[v]<calc(dis[u],id)){
dis[v]=calc(dis[u],id);
// cout<<u<<" --> "<<v<<','<<id<<':'<<dis[v]<<'\n';
Q.push({dis[v],v});
}
}
}
rep(i,1,n-1){
if (dis[i]<-1e18)puts("Unreachable");
else printf("%lld\n",dis[i]);
}
return 0;
}
Submission Info
Submission Time
2024-02-24 21:31:34+0900
Task
E - Last Train
User
fft_ntt
Language
C++ 20 (gcc 12.2)
Score
450
Code Size
1791 Byte
Status
AC
Exec Time
198 ms
Memory
26480 KiB
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:43:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp: In member function ‘void Node::read()’:
Main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%lld%lld%lld%lld%lld%lld",&l,&d,&k,&c,&v,&u);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
450 / 450
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
3 ms
5312 KiB
00_sample_01.txt
AC
3 ms
5432 KiB
00_sample_02.txt
AC
2 ms
5284 KiB
01_random_03.txt
AC
185 ms
26480 KiB
01_random_04.txt
AC
198 ms
26440 KiB
01_random_05.txt
AC
193 ms
26444 KiB
01_random_06.txt
AC
193 ms
26408 KiB
01_random_07.txt
AC
190 ms
26464 KiB
01_random_08.txt
AC
163 ms
25548 KiB
01_random_09.txt
AC
163 ms
25512 KiB
01_random_10.txt
AC
128 ms
25108 KiB
01_random_11.txt
AC
109 ms
17976 KiB
01_random_12.txt
AC
168 ms
23076 KiB
01_random_13.txt
AC
75 ms
13624 KiB
01_random_14.txt
AC
34 ms
9684 KiB
01_random_15.txt
AC
34 ms
9668 KiB
01_random_16.txt
AC
58 ms
15092 KiB
01_random_17.txt
AC
132 ms
25088 KiB
01_random_18.txt
AC
133 ms
24980 KiB
01_random_19.txt
AC
126 ms
25088 KiB
01_random_20.txt
AC
127 ms
25128 KiB
01_random_21.txt
AC
127 ms
25152 KiB
01_random_22.txt
AC
115 ms
18536 KiB
01_random_23.txt
AC
81 ms
17772 KiB
01_random_24.txt
AC
69 ms
17036 KiB
01_random_25.txt
AC
158 ms
26404 KiB
01_random_26.txt
AC
162 ms
26456 KiB
01_random_27.txt
AC
163 ms
26404 KiB
01_random_28.txt
AC
163 ms
26416 KiB
01_random_29.txt
AC
8 ms
5376 KiB
01_random_30.txt
AC
15 ms
6792 KiB
01_random_31.txt
AC
54 ms
12020 KiB
01_random_32.txt
AC
93 ms
17540 KiB