Submission #1443408


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 999999999999999999
#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 500

int n;
int l[MAXN],r[MAXN];
int len[MAXN];

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];
	}
	
	ll ans = LINF;
	for(int i = 0;i <= MAXN;i++)
		ans = min(  ans  ,  dp(2,i) + abs(i-l[1])  );
		
	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 1282 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:47:2: error: expected primary-expression before ‘/’ token
  /freopen("E.txt","r",stdin);
  ^
./Main.cpp:50:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:52: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]);
                             ^