QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#814084#9879. ReTravelucup-team3510#WA 52ms8028kbC++201.1kb2024-12-14 15:07:222024-12-14 15:07:22

Judging History

This is the latest submission verdict.

  • [2024-12-14 15:07:22]
  • Judged
  • Verdict: WA
  • Time: 52ms
  • Memory: 8028kb
  • [2024-12-14 15:07:22]
  • Submitted

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define s1 first
#define s2 second
using namespace std;
ll dp[511][511];int mnx[511][511],mny[511][511];int n;
pii a[511];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d%d",&a[i].s1,&a[i].s2);
	sort(a+1,a+1+n);
	memset(dp,0x3f,sizeof(dp));
	for(int i=1;i<=n;++i)dp[i][i]=0;
	for(int l=1;l<=n;++l)
	{
		mnx[l][l]=a[l].s1;
		mny[l][l]=a[l].s2;
		for(int r=l+1;r<=n;++r)mnx[l][r]=min(mnx[l][r-1],a[r].s1),mny[l][r]=min(mny[l][r-1],a[r].s2);
	}
	// printf("mnx:\n");
	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=i;j<=n;++j)printf("%d ",mnx[i][j]);putchar(10);
	// }
	// printf("mny:\n");
	// for(int i=1;i<=n;++i)
	// {
	// 	for(int j=i;j<=n;++j)printf("%d ",mny[i][j]);putchar(10);
	// }
	for(int i=2;i<=n;++i)
	{
		for(int l=1;l+i-1<=n;++l)
		{
			int r=l+i-1;
			for(int k=l;k<r;++k)
			{
				dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]
					+mny[l][k]+mnx[k+1][r]+mnx[l][k]+mny[k+1][r]-2*(mny[l][r]+mnx[l][r]));
			}
			// printf("dp[%d,%d]:%lld\n",l,r,dp[l][r]);
		}
	}
	printf("%lld\n",dp[1][n]+mnx[1][n]+mny[1][n]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 3
1 2

output:

6

result:

ok "6"

Test #2:

score: 0
Accepted
time: 1ms
memory: 6040kb

input:

3
2 2
3 3
1 3

output:

7

result:

ok "7"

Test #3:

score: -100
Wrong Answer
time: 52ms
memory: 8028kb

input:

500
906691059 413653999
813847339 955892128
451585301 43469773
278009742 548977048
521760889 434794718
985946604 841597326
891047768 325679554
511742081 384452587
626401695 957413342
975078788 234551094
541903389 149544006
302621084 150050891
811538590 101823753
663968655 858351976
268979133 9768326...

output:

135417973721

result:

wrong answer 1st words differ - expected: '202616034783', found: '135417973721'