ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214440 | #2767. 摆烂 | nodgd | 0 | 965ms | 33436kb | C++11 | 1.6kb | 2024-11-18 21:55:32 | 2024-11-19 08:35:34 |
answer
#include <bits/stdc++.h>
using namespace std;
const int BUFFER_SIZE = 1 << 20;
char rb[BUFFER_SIZE], *rp = rb, *rt = rb;
inline char read_char() {
return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp ++) : *rp ++;
}
inline int read_int() {
int x = 0;
char ch = read_char(), flag = 0;
while (ch != '-' && (ch < '0' || ch > '9')) {
ch = read_char();
}
if (ch == '-') {
flag = 1;
ch = read_char();
}
for (x = 0; ch >= '0' && ch <= '9'; ch = read_char()) {
x = x * 10 + (ch - '0');
}
return flag ? -x : x;
}
const int MAX_N = 2000000 + 5;
typedef long long i64;
const i64 INF64 = 1e18;
int N;
int b[MAX_N], a[MAX_N], q[MAX_N], qh, qt;
i64 f[MAX_N], g[MAX_N][22];
int main() {
N = read_int();
for (int i = 1; i <= N; i ++) {
b[i] = read_int();
a[i] = read_int();
}
q[qh = 0] = 0, qt = 1, a[0] = 1e9 + 1;
for (int i = 1; i <= N; i ++) {
f[i] = INF64;
for (; qh < qt && a[q[qt - 1]] < a[i]; qt --);
q[qt ++] = i;
for (; qh < qt && f[q[qh]] < b[i]; ) qh ++;
f[i] = b[i] + 2ll * a[q[qh]];
if (qh + 1 < qt) {
int p = qt - 1, j;
g[p][0] = f[q[p - 1]] + 2ll * a[q[p]];
for (j = 1; p - (1 << j) + 1 > qh; j ++) {
g[p][j] = min(g[p][j - 1], g[p - (1 << j - 1)][j - 1]);
}
j --;
i64 tf = min(g[p][j], g[qh + (1 << j)][j]);
f[i] = min(f[i], tf);
}
printf("f[%d]=%lld\n", i, f[i]);
}
printf("%lld\n", f[N]);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1168kb
input:
20 12513359 382258501 49946422 294259408 61782741 259996549 128874560 457675284 152578248 511428369 ...
output:
f[1]=777030361 f[2]=814463424 f[3]=826299743 f[4]=1044225128 f[5]=1175434986 f[6]=1185609488 f[7]=12...
result:
wrong output format Expected integer, but "f[1]=777030361" found
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 0ms
memory: 1208kb
input:
1000 132699 718470029 234343 395421925 1290414 393017296 1399642 607415822 1402810 515471990 2008288...
output:
f[1]=1437072757 f[2]=1437174401 f[3]=1438230472 f[4]=1438339700 f[5]=1438342868 f[6]=1438948346 f[7]...
result:
wrong output format Expected integer, but "f[1]=1437072757" found
Subtask #3:
score: 0
Wrong Answer
Test #20:
score: 0
Wrong Answer
time: 22ms
memory: 3756kb
input:
100000 9326 430414358 13368 156324232 15149 550951304 22296 345034579 22578 397947033 37137 49312905...
output:
f[1]=860838042 f[2]=860842084 f[3]=1101917757 f[4]=1101924904 f[5]=1101925186 f[6]=1101939745 f[7]=1...
result:
wrong output format Expected integer, but "f[1]=860838042" found
Subtask #4:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 395ms
memory: 33436kb
input:
2000000 181 24185667 293 532288461 1433 921996635 1694 629544979 2540 173534643 2662 963172401 3159 ...
output:
f[1]=48371515 f[2]=1064577215 f[3]=1843994703 f[4]=1843994964 f[5]=1843995810 f[6]=1926347464 f[7]=1...
result:
wrong output format Expected integer, but "f[1]=48371515" found
Subtask #5:
score: 0
Wrong Answer
Test #42:
score: 0
Wrong Answer
time: 548ms
memory: 33436kb
input:
2000000 684 624071334 1181 709831992 1397 43325781 1938 430417709 4157 60566309 4568 912818933 5265 ...
output:
f[1]=1248143352 f[2]=1419665165 f[3]=1419665381 f[4]=1419665922 f[5]=1419668141 f[6]=1825642434 f[7]...
result:
wrong output format Expected integer, but "f[1]=1248143352" found