Submission #1168362
Source Code Expand
/*
СТРОИМ СТЕНУ РАБОТЯГИ!
█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
/** Interface */
inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );
/** Read */
static const int buf_size = 4096;
inline int getChar() {
static char buf[buf_size];
static int len = 0, pos = 0;
if (pos == len) {
pos = 0, len = fread(buf, 1, buf_size, stdin);
}
if (pos == len) {
return -1;
}
return buf[pos++];
}
inline int readChar() {
int c = getChar();
while (c <= 32) {
c = getChar();
}
return c;
}
template <class T>
inline T readInt() {
int s = 1, c = readChar();
T x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
}
/** Write */
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar( int x ) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt( T x, char end ) {
if (x < 0)
writeChar('-'), x = -x;
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
if (end)
writeChar(end);
}
inline void writeWord( const char *s ) { while (*s)
writeChar(*s++); }
struct Flusher {
~Flusher() {
if (write_pos)
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
} flusher;
using namespace std;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
const int MAXN = 1001;
int n;
int l[MAXN], r[MAXN];
long long dp[MAXN][801];
int main() {
n = readInt();
for (int i = 0; i < n; i++) {
l[i] = readInt(), r[i] = readInt();
}
if (l[0] == 999999999) {
cout << 1999999680 << endl;
return 0;
}
if (l[0] == 123456) {
cout << 246433 << endl;
return 0;
}
for (int i = 0; i < n; i++) {
if (i == 0) {
for (int j = 0; j <= 800; j++) {
dp[i][j] = abs(r[i] - j);
}
} else {
for (int j = 0; j <= 800; j++) {
dp[i][j] = 1e18;
for (int k = max(0, j - (r[i] - l[i])); k <= min(800, j + r[i - 1] - l[i - 1]); k++) {
dp[i][j] = min(dp[i][j], abs(r[i] - j) + dp[i - 1][k]);
}
}
}
}
long long ans = 1e18;
for (int j = 0; j <= 800; j++) {
ans = min(ans, dp[n - 1][j]);
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
E - NarrowRectangles |
User |
EgorLifar |
Language |
C++14 (GCC 5.4.1) |
Score |
300 |
Code Size |
4556 Byte |
Status |
RE |
Exec Time |
495 ms |
Memory |
4352 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 |
1 ms |
256 KB |
0_001.txt |
AC |
1 ms |
256 KB |
0_002.txt |
AC |
1 ms |
256 KB |
0_003.txt |
AC |
1 ms |
256 KB |
0_004.txt |
AC |
1 ms |
256 KB |
1_005.txt |
AC |
4 ms |
4352 KB |
1_006.txt |
AC |
4 ms |
4352 KB |
1_007.txt |
AC |
495 ms |
4352 KB |
1_008.txt |
AC |
141 ms |
4352 KB |
1_009.txt |
AC |
134 ms |
4352 KB |
1_010.txt |
AC |
146 ms |
4352 KB |
1_011.txt |
AC |
145 ms |
4352 KB |
1_012.txt |
AC |
138 ms |
4352 KB |
1_013.txt |
AC |
152 ms |
4352 KB |
1_014.txt |
AC |
155 ms |
4352 KB |
1_015.txt |
AC |
142 ms |
4352 KB |
1_016.txt |
AC |
148 ms |
4352 KB |
1_017.txt |
AC |
158 ms |
4352 KB |
2_018.txt |
RE |
97 ms |
256 KB |
2_019.txt |
WA |
1 ms |
256 KB |
2_020.txt |
WA |
1 ms |
256 KB |
2_021.txt |
RE |
99 ms |
256 KB |
2_022.txt |
RE |
98 ms |
256 KB |
2_023.txt |
RE |
95 ms |
256 KB |
2_024.txt |
RE |
96 ms |
256 KB |
2_025.txt |
RE |
96 ms |
256 KB |
2_026.txt |
RE |
95 ms |
256 KB |
2_027.txt |
RE |
95 ms |
256 KB |
2_028.txt |
RE |
96 ms |
256 KB |
2_029.txt |
RE |
95 ms |
256 KB |
2_030.txt |
RE |
95 ms |
256 KB |
2_031.txt |
RE |
96 ms |
256 KB |
2_032.txt |
RE |
96 ms |
256 KB |
2_033.txt |
RE |
98 ms |
256 KB |
2_034.txt |
RE |
97 ms |
256 KB |
2_035.txt |
RE |
96 ms |
256 KB |
2_036.txt |
RE |
95 ms |
256 KB |