Submission #1443437


Source Code Expand

#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
map<int ,long long>dp[100010];
int n;
long long ans=1e18;
int l[100010],r[100010];
int mabs(int x)
{
	if(x<0)return -x;return x;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",l+i,r+i);
	}
	for(int i=1;i<=n;i++)
	{
		int ln=r[i-1]-l[i-1];
		for(int j=-400;j<=400;j++)
		{
			dp[i][j]=1e18;
			int cst=mabs(l[i]-j);
			for(int k=j-ln;k<=j+r[i]-l[i];k++)
			{
				if(dp[i-1][k]==1e18)continue;
				dp[i][j]=min(dp[i][j],dp[i-1][k]+cst);
				if(i==n)ans=min(ans,dp[i][j]);
			}
		}
	}
	printf("%lld",ans);
	return 0;
}

Submission Info

Submission Time
Task E - NarrowRectangles
User ASSWECAN
Language C++14 (GCC 5.4.1)
Score 0
Code Size 648 Byte
Status WA
Exec Time 2123 ms
Memory 314240 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:15:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:18:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",l+i,r+i);
                        ^

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 0 / 300 0 / 700
Status
AC × 3
WA × 1
TLE × 1
WA × 2
TLE × 11
AC × 3
WA × 3
TLE × 31
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt
Subtask 0_000, 0_001, 0_004, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 2_018.txt, 2_019.txt, 2_020.txt, 2_021.txt, 2_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt
Case Name Status Exec Time Memory
0_000.txt AC 4 ms 5120 KB
0_001.txt AC 5 ms 5120 KB
0_002.txt WA 5 ms 5248 KB
0_003.txt TLE 2106 ms 46592 KB
0_004.txt AC 47 ms 5120 KB
1_005.txt WA 148 ms 25088 KB
1_006.txt WA 148 ms 25088 KB
1_007.txt TLE 2104 ms 7552 KB
1_008.txt TLE 2104 ms 12544 KB
1_009.txt TLE 2104 ms 13056 KB
1_010.txt TLE 2104 ms 13056 KB
1_011.txt TLE 2104 ms 13056 KB
1_012.txt TLE 2104 ms 12672 KB
1_013.txt TLE 2104 ms 12288 KB
1_014.txt TLE 2104 ms 11776 KB
1_015.txt TLE 2104 ms 12032 KB
1_016.txt TLE 2104 ms 12288 KB
1_017.txt TLE 2104 ms 11904 KB
2_018.txt TLE 2122 ms 314240 KB
2_019.txt TLE 2123 ms 313728 KB
2_020.txt TLE 2110 ms 118912 KB
2_021.txt TLE 2110 ms 120864 KB
2_022.txt TLE 2110 ms 119680 KB
2_023.txt TLE 2110 ms 118528 KB
2_024.txt TLE 2110 ms 118272 KB
2_025.txt TLE 2110 ms 120576 KB
2_026.txt TLE 2110 ms 114816 KB
2_027.txt TLE 2111 ms 119168 KB
2_028.txt TLE 2110 ms 117504 KB
2_029.txt TLE 2110 ms 118400 KB
2_030.txt TLE 2110 ms 119168 KB
2_031.txt TLE 2108 ms 75392 KB
2_032.txt TLE 2105 ms 33920 KB
2_033.txt TLE 2104 ms 12672 KB
2_034.txt TLE 2104 ms 7680 KB
2_035.txt TLE 2110 ms 120064 KB
2_036.txt TLE 2110 ms 116992 KB