QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#562680#7905. Ticket to RideHuTaoWA 1ms4188kbC++141.5kb2024-09-13 20:00:562024-09-13 20:00:56

Judging History

你现在查看的是最新测评结果

  • [2024-09-13 20:00:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4188kb
  • [2024-09-13 20:00:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 10005;
const LL INF = -0x3f3f3f3f3f3f3f3f;

int n, m;
vector<pair<int, int> > v[N];
LL f[N], g[N], ans[N];
int fa[N];
LL d[N], s[N];

inline int Gfa(int i)
{
	return i == fa[i] ? i : fa[i] = Gfa(fa[i]);
}

int main()
{
	int T;
	scanf("%d", &T);
	while(T -- )
	{
		scanf("%d%d", &n, &m);
		for(int i = 1; i <= n; i ++ ) v[i].clear();
		for(int i = 1; i <= m; i ++ )
		{
			int l, r, x;
			scanf("%d%d%d", &l, &r, &x);
			v[r].emplace_back(l, x);
		}
		
		f[0] = 0;
		for(int i = 1; i <= n; i ++ )
		{
			f[i] = f[i - 1];
			for(auto &j : v[i]) f[i] += j.second;
		}
		ans[n] = f[n];
		for(int i = n - 1; i >= 1; i -- )
		{
			d[0] = s[0] = 0, g[0] = INF;
			for(int j = 1; j <= n; j ++ )
			{
				g[j] = f[j - 1];
				fa[j] = g[j - 1] >= g[j] ? j - 1 : j;
				d[j] = s[j] = 0;
			}
			f[0] = INF;
			for(int j = 1; j <= n; j ++ )
			{
				for(auto &k : v[j])
				{
					d[k.first] += k.second;
					s[Gfa(k.first)] += k.second;
					if(d[k.first] + g[k.first] >= g[k.first + 1])
					{
						int p = Gfa(k.first), q = Gfa(k.first + 1);
						if(p != q)
						{
							s[p] += s[q];
							fa[q] = p;
						}
					}
				}
				// printf("!%d %d %lld %lld\n", j, Gfa(j), g[Gfa(j)], s[Gfa(j)]);
				f[j] = g[Gfa(j)] + s[Gfa(j)];
			}
			// for(int j = 1; j <= n; j ++ ) printf("%lld ", f[j]);
			// puts("");
			ans[i] = f[n];
		}

		for(int i = 1; i <= n; i ++ ) printf("%lld ", ans[i]);
		puts("");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4188kb

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: 4096kb

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 561070698 773727734 816762545 2675644351 2675644351 
976357580 1594205360 1671371256 2347908675 2965756455 3485691742 41807...

result:

wrong answer 4th lines differ - expected: '127680943 773727734 1334798432 2227456393 2675644351 2675644351', found: '127680943 561070698 773727734 816762545 2675644351 2675644351 '