Submission #3557196
Source Code Expand
#include <iostream> #include <string.h> #include <stdio.h> #include <map> #include <vector> #include <math.h> #include <algorithm> #include <queue> #include <set> #include <tuple> using namespace std; #define rep(i,a) for(int i=0; i<a; i++) #define rrep(i,a) for(int i=a; i>=0; i--) #define rep1(i,a) for(int i=1; i<=a; i++) #define cout1(a) cout << a << endl; #define cout2(a,b) cout << a << " " << b << endl; #define cout3(a,b,c) cout << a << " " << b << " " << c << endl; #define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl; #define mem(a,n) memset( a, n, sizeof(a)) #define all(a) a.begin(),a.end() typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef vector<int> V; typedef vector<V> VV; typedef vector<VV> VVV; const int INF = 1e9; const int MOD = 1e9+7; const ll LLINF = 1e18; static const double pi = 3.141592653589793; int N, L[100009], R[100009]; ll dp[1009][1009]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin>>N; if(N>400) return 0; rep(i,N){ cin>>L[i]>>R[i]; if(L[i]>400||R[i]>400) return 0;} rep(i,401) dp[0][i] = abs(i-L[0]); rep1(i,N-1){ rep(j,401){ ll mn=LLINF; for(int k=max(0,j-(R[i-1]-L[i-1]));k<=min(400,j+(R[i]-L[i]));k++){ mn = min(mn,dp[i-1][k]); } dp[i][j] = abs(j-L[i]) + mn; } } ll ans=LLINF; rep(i,401){ ans = min(ans,dp[N-1][i]); } cout1(ans); }
Submission Info
Submission Time | |
---|---|
Task | E - NarrowRectangles |
User | mensan_fukuhara |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 1555 Byte |
Status | WA |
Exec Time | 67 ms |
Memory | 6144 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 0 / 700 | ||||||||||
Status |
|
|
|
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 | 2 ms | 2304 KB |
0_001.txt | AC | 2 ms | 2304 KB |
0_002.txt | WA | 2 ms | 2304 KB |
0_003.txt | WA | 2 ms | 2304 KB |
0_004.txt | AC | 2 ms | 2304 KB |
1_005.txt | AC | 4 ms | 6144 KB |
1_006.txt | AC | 4 ms | 6144 KB |
1_007.txt | AC | 67 ms | 6144 KB |
1_008.txt | AC | 28 ms | 6144 KB |
1_009.txt | AC | 27 ms | 6144 KB |
1_010.txt | AC | 29 ms | 6144 KB |
1_011.txt | AC | 28 ms | 6144 KB |
1_012.txt | AC | 28 ms | 6144 KB |
1_013.txt | AC | 29 ms | 6144 KB |
1_014.txt | AC | 30 ms | 6144 KB |
1_015.txt | AC | 28 ms | 6144 KB |
1_016.txt | AC | 29 ms | 6144 KB |
1_017.txt | AC | 30 ms | 6144 KB |
2_018.txt | WA | 1 ms | 256 KB |
2_019.txt | WA | 1 ms | 256 KB |
2_020.txt | WA | 1 ms | 256 KB |
2_021.txt | WA | 1 ms | 256 KB |
2_022.txt | WA | 1 ms | 256 KB |
2_023.txt | WA | 1 ms | 256 KB |
2_024.txt | WA | 1 ms | 256 KB |
2_025.txt | WA | 1 ms | 256 KB |
2_026.txt | WA | 1 ms | 256 KB |
2_027.txt | WA | 1 ms | 256 KB |
2_028.txt | WA | 1 ms | 256 KB |
2_029.txt | WA | 1 ms | 256 KB |
2_030.txt | WA | 1 ms | 256 KB |
2_031.txt | WA | 1 ms | 256 KB |
2_032.txt | WA | 1 ms | 256 KB |
2_033.txt | WA | 1 ms | 256 KB |
2_034.txt | WA | 1 ms | 256 KB |
2_035.txt | WA | 1 ms | 256 KB |
2_036.txt | WA | 1 ms | 256 KB |