Submission #1443380
Source Code Expand
/*
% D a l a o
--InterestingLSY
*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define INF 9999999
#define LINF 9999999999999999
#define SINF "%"
#define uint unsigned int
#define msn(a,v) memset(a,v,sizeof(a))
#define ms(a) msn(a,0)
#define NONE -1
#define ll long long
#define uchar unsigned char
#define sint short int
#define usint unsigned sint
using namespace std;
#define MAXN 5000
int n;
int l[MAXN],r[MAXN];
int len[MAXN];
int maxpos=-1 , minpos=LINF;
ll mem[MAXN][MAXN];
ll dp(int pos,int lastl){
if(pos == n+1) return 0;
if(mem[pos][lastl] != -1) return mem[pos][lastl];
ll ans = LINF;
for(int nowl = lastl-len[pos];nowl <= lastl+len[pos-1];nowl++)
ans = min( ans , dp(pos+1,nowl) + abs(l[pos]-nowl) );
mem[pos][lastl] = ans;
return ans;
}
int main(){
//freopen("E.txt","r",stdin);
msn(mem,-1);
scanf("%d",&n);
for(int i = 1;i <= n;i++){
scanf("%d %d",&l[i],&r[i]);
len[i] = r[i] - l[i];
minpos = min( minpos , l[i] );
maxpos = max( maxpos , l[i] );
}
ll ans = LINF;
for(int i = minpos;i <= maxpos;i++)
ans = min( ans , dp(1,i) );
printf("%lld\n",ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
E - NarrowRectangles |
User |
interestingLSY |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1373 Byte |
Status |
RE |
Exec Time |
2104 ms |
Memory |
195712 KB |
Compile Error
./Main.cpp:18:14: warning: overflow in implicit constant conversion [-Woverflow]
#define LINF 9999999999999999
^
./Main.cpp:34:24: note: in expansion of macro ‘LINF’
int maxpos=-1 , minpos=LINF;
^
./Main.cpp: In function ‘int main()’:
./Main.cpp:51:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:53:29: 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 |
× 5 |
WA |
× 11 |
TLE |
× 2 |
RE |
× 19 |
|
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 |
49 ms |
195584 KB |
0_001.txt |
AC |
48 ms |
195584 KB |
0_002.txt |
RE |
465 ms |
195584 KB |
0_003.txt |
RE |
142 ms |
195584 KB |
0_004.txt |
AC |
48 ms |
195584 KB |
1_005.txt |
AC |
53 ms |
195584 KB |
1_006.txt |
AC |
53 ms |
195584 KB |
1_007.txt |
TLE |
2104 ms |
195584 KB |
1_008.txt |
WA |
1127 ms |
195584 KB |
1_009.txt |
WA |
1079 ms |
195584 KB |
1_010.txt |
WA |
1175 ms |
195712 KB |
1_011.txt |
WA |
1169 ms |
195584 KB |
1_012.txt |
WA |
1107 ms |
195584 KB |
1_013.txt |
WA |
1232 ms |
195584 KB |
1_014.txt |
WA |
1239 ms |
195584 KB |
1_015.txt |
WA |
1140 ms |
195584 KB |
1_016.txt |
WA |
1193 ms |
195584 KB |
1_017.txt |
WA |
1264 ms |
195584 KB |
2_018.txt |
RE |
143 ms |
195584 KB |
2_019.txt |
WA |
49 ms |
195584 KB |
2_020.txt |
TLE |
2104 ms |
195584 KB |
2_021.txt |
RE |
143 ms |
195584 KB |
2_022.txt |
RE |
143 ms |
195584 KB |
2_023.txt |
RE |
143 ms |
195584 KB |
2_024.txt |
RE |
144 ms |
195584 KB |
2_025.txt |
RE |
144 ms |
195584 KB |
2_026.txt |
RE |
143 ms |
195584 KB |
2_027.txt |
RE |
143 ms |
195584 KB |
2_028.txt |
RE |
144 ms |
195584 KB |
2_029.txt |
RE |
144 ms |
195584 KB |
2_030.txt |
RE |
143 ms |
195584 KB |
2_031.txt |
RE |
144 ms |
195584 KB |
2_032.txt |
RE |
143 ms |
195584 KB |
2_033.txt |
RE |
144 ms |
195584 KB |
2_034.txt |
RE |
145 ms |
195584 KB |
2_035.txt |
RE |
144 ms |
195584 KB |
2_036.txt |
RE |
143 ms |
195584 KB |