QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#670856 | #7905. Ticket to Ride | Lynkcat | WA | 2ms | 3664kb | C++20 | 1.5kb | 2024-10-24 05:23:06 | 2024-10-24 05:23:07 |
Judging History
answer
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) (int)((x).size())
#define int ll
//#define N
using namespace std;
const int N=10005;
int n,m,g[N],fa[N],h[N],dp[N],R[N];
int ans[N];
vector<pa>G[N];
inline int gf(int k)
{
while (k!=fa[k]) k=fa[k]=fa[fa[k]];
return k;
}
void BellaKira()
{
cin>>n>>m;
for (int i=1;i<=m;i++)
{
int l,r,v;
cin>>l>>r>>v;
G[r].push_back(mp(l,v));
}
for (int i=0;i<=n;i++)
{
for (auto [l,v]:G[i]) g[i]+=v;
g[i+1]=g[i];
}
ans[n]=g[n];
for (int t=1;t<n;t++)
{
g[n]=inf;
for (int i=t;i<=n;i++) fa[i]=i,R[i]=i;
for (int i=t+1;i<=n;i++) h[i]=g[i-1];
for (int i=t;i<=n;i++) h[i]=g[i]-g[i-1];
for (int i=t+1;i<=n;i++)
{
for (auto [l,v]:G[i])
{
if (l<t) continue;
l=gf(l);
while (1)
{
if (v<=h[l])
{
h[l]-=v;
break;
}
v-=h[l];
int r=R[l]+1;
fa[r]=l;
R[l]=R[r];
h[l]=h[r];
}
}
int p=gf(i);
dp[i]=g[R[p]]-h[p];
}
ans[n-t]=dp[n];
for (int i=0;i<=n;i++) g[i]=dp[i];
}
for (int i=1;i<=n;i++) cout<<ans[i]<<' ';
cout<<'\n';
for (int i=1;i<=n;i++) vector<pa>().swap(G[i]);
}
signed main()
{
IOS;
cin.tie(0);
int T=1;
cin>>T;
while (T--)
{
BellaKira();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3664kb
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: 2ms
memory: 3648kb
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 1594205360 1671371256 2103791342 2721639122 3241574409 3936588085 41...
result:
wrong answer 5th lines differ - expected: '976357580 1594205360 210379134...241574409 3936588085 4180705418', found: '1594205360 1671371256 21037913...41574409 3936588085 4180705418 '