Submission #1348159


Source Code Expand

#include<cstdio>
#include<cstdlib>
#include<vector>


using namespace std;
using ll=long long;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vi>;


void min_u(int&m, int v)
{
	if(m>v) m=v;
}


void max_u(int&m, int v)
{
	if(m<v) m=v;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi l(n), r(n);
		vvi dp(n);

		int l_max=0;
		for(int i=0;i<n;i++)
		{
			scanf("%d%d", &l[i], &r[i]);
			max_u(l_max, l[i]);
		}

		if(l_max>1000) return 1;

		for(auto&dpe:dp) dpe.assign(l_max+1, l_max*n);


		for(int x=0;x<=l_max;x++)
		{
			dp[0][x]=abs(l[0]-x);
		}
		for(int i=1;i<n;i++)
		{
//printf("i=%d  l_max=%d\n", i, l_max);
			for(int x=0;x<=l_max;x++)
			{
				int j_min=max(    0, x-(r[i-1]-l[i-1]));
				int j_max=min(l_max, x+r[i]-l[i]);
				for(int j=j_min;j<=j_max;j++)
				{
					min_u(dp[i][x], abs(l[i]-x)+dp[i-1][j]);
				}
			}
		}

		int ans=dp[n-1][0];
		for(auto dpe:dp[n-1]) min_u(ans, dpe);
		printf("%d\n", ans);
	}


	return 0;
}

Submission Info

Submission Time
Task E - NarrowRectangles
User myanta
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1044 Byte
Status RE
Exec Time 32 ms
Memory 6528 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:37:31: 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 300 / 300 0 / 700
Status
AC × 3
RE × 2
AC × 13
AC × 17
RE × 20
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 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt RE 1 ms 256 KB
0_003.txt RE 1 ms 256 KB
0_004.txt AC 1 ms 256 KB
1_005.txt AC 2 ms 896 KB
1_006.txt AC 2 ms 896 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 30 ms 896 KB
1_009.txt AC 28 ms 896 KB
1_010.txt AC 30 ms 896 KB
1_011.txt AC 30 ms 896 KB
1_012.txt AC 29 ms 896 KB
1_013.txt AC 31 ms 896 KB
1_014.txt AC 32 ms 896 KB
1_015.txt AC 30 ms 896 KB
1_016.txt AC 31 ms 896 KB
1_017.txt AC 32 ms 896 KB
2_018.txt RE 19 ms 3328 KB
2_019.txt RE 19 ms 3328 KB
2_020.txt AC 25 ms 6528 KB
2_021.txt RE 23 ms 3328 KB
2_022.txt RE 22 ms 3328 KB
2_023.txt RE 22 ms 3328 KB
2_024.txt RE 22 ms 3328 KB
2_025.txt RE 22 ms 3328 KB
2_026.txt RE 23 ms 3328 KB
2_027.txt RE 22 ms 3328 KB
2_028.txt RE 22 ms 3328 KB
2_029.txt RE 22 ms 3328 KB
2_030.txt RE 22 ms 3328 KB
2_031.txt RE 22 ms 3328 KB
2_032.txt RE 22 ms 3328 KB
2_033.txt RE 22 ms 3328 KB
2_034.txt RE 22 ms 3328 KB
2_035.txt RE 22 ms 3328 KB
2_036.txt RE 23 ms 3328 KB