QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#767745 | #7905. Ticket to Ride | eastcloud | WA | 1ms | 3968kb | C++17 | 2.3kb | 2024-11-20 22:00:08 | 2024-11-20 22:00:08 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pi pair<ll,ll>
#define vi vector<ll>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define eb emplace_back
#define IL inline
using namespace std;
#define N 10005
ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
void write(ll x){
if(x<0)x=-x,putchar('-');
if(x/10)write(x/10);
putchar(x%10+'0');
}
vector<pi> c[N];
ll pre[N],nex[N],f[N],add[N],g[N],res[N],fa[N];
ll find(ll x){return (x==fa[x]?x:fa[x]=find(fa[x]));}
void del(ll x){
fa[x]=pre[x];add[pre[x]]+=add[x];
pre[nex[x]]=pre[x];nex[pre[x]]=nex[x];
}
void solve(){
ll n=read()+1,m=read();
for(ll i=1;i<=n;i++)c[i].clear();
for(ll i=1;i<=m;i++){
ll l=read()+1,r=read()+1,w=read();
c[r].eb(l,w);
}
for(ll i=1;i<=n;i++){
f[i]=f[i-1];
for(auto [l,w]:c[i])f[i]+=w;
}
res[1]=f[n];
for(ll k=2;k<=n-1;k++){
for(ll i=k-1;i<=n;i++)fa[i]=i,add[i]=0,pre[i]=nex[i]=0,g[i]=f[i];
ll tp=0;
for(ll i=k;i<=n;i++){
for(auto [l,w]:c[i]){
if(l-1<k-1)continue;
ll pos=find(l-1);add[pos]+=w;
//cerr<<i<<' '<<l-1<<' '<<pos<<' '<<add[pos]<<' '<<w<<"**"<<endl;
//cerr<<pos<<' '<<nex[pos]<<endl;
if(nex[pos] && add[pos]+g[pos]>=g[nex[pos]]){
del(nex[pos]);
}
}
ll pos=find(i-1);
f[i]=g[pos]+add[pos];
//cerr<<i<<' '<<pos<<' '<<g[4]<<' '<<k<<endl;
pos=find(i-1);
if(g[pos]+add[pos]<g[i]){
nex[pos]=i;pre[i]=pos;
}
else fa[i]=pos;
}
res[k]=f[n];
}
for(ll i=n-1;i>=1;i--)write(res[i]),putchar(' ');
putchar('\n');
}
int main(){
#ifdef EAST_CLOUD
freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
#endif
ll T=read();while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3968kb
input:
2 4 3 0 2 3 3 4 2 0 3 1 3 1 1 3 100
output:
2 3 5 6 0 100 100
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3900kb
input:
1000 2 9 0 2 396628655 1 2 268792718 0 2 16843338 1 2 717268783 0 1 693319712 0 1 856168102 1 2 407246545 1 2 527268921 0 1 536134606 6 2 2 5 451394766 0 5 695984050 9 7 0 6 73936815 2 9 505041862 4 5 223718927 5 7 179262261 3 5 449258178 0 5 493128 0 3 994723920 6 6 3 5 433389755 2 4 773727734 4 5 ...
output:
2085622420 4419671380 0 0 451394766 451394766 1147378816 1147378816 223718927 672977105 994723920 1218442847 1668194153 1742130968 1921393229 1921393229 2426435091 127680943 773727734 1334798432 2227456393 2675644351 2675644351 976357580 1594205360 2103791342 2721639122 3241574409 3936588085 418...
result:
wrong answer 41st lines differ - expected: '21544207 420680500 442224707 8...063578931 1063578931 1063578931', found: '21544207 166190990 442224707 5...63578931 1063578931 1063578931 '