用户输出
12
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#187 | #1025. 1-02F. JM的睡前故事 | Accepted | 100 | 369 ms | 3480 K | C++ 11 / 1.6 K | JM233333 | 2019-06-16 14:10:35 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 2e9 + 1;
class Point {
public:
ll pos;
char type;
Point(ll x, char c) : pos(x), type(c) {}
Point() {}
};
class Status {
public:
ll prev;
ll maxdelta;
Status() { reset(-INF); }
void reset(ll x) {
prev = x;
maxdelta = 0;
}
void refresh(ll x, ll &sum) {
if (prev > -INF) {
maxdelta = max(maxdelta, x - prev);
sum += (x - prev);
}
prev = x;
}
};
ll solve(int n);
const int MAX = 2e5 + 5;
Point cities[MAX];
int main() {
// freopen("test.txt", "r", stdin);
int n;
while (scanf("%d", &n) != EOF) {
// 输入
for (int i = 1; i <= n; i++) {
scanf("%lld %c", &cities[i].pos, &cities[i].type);
}
// 求解
ll res = solve(n);
// 输出
printf("%lld\n", res);
}
return 0;
}
// 解决
ll solve(int n) {
// 初始化
Status R, B;
ll prevP = -INF;
ll sum = 0;
ll res = 0;
// 遍历
for (int i = 1; i <= n; i++) {
// 获取当前坐标
ll x = cities[i].pos;
// R或B的情况
if (cities[i].type == 'S') {
R.refresh(x, sum);
}
if (cities[i].type == 'F') {
B.refresh(x, sum);
}
// P的情况
if (cities[i].type == 'N') {
R.refresh(x, sum);
B.refresh(x, sum);
if (prevP > -INF) {
res += min(sum, sum + (x - prevP) - R.maxdelta - B.maxdelta);
sum = 0;
}
R.reset(x);
B.reset(x);
prevP = x;
}
}
// 处理后缀部分
res += sum;
// 返回
return res;
}
用户输出
26
系统信息
Exited with return code 0
用户输出
29
系统信息
Exited with return code 0
15
-9518 S
-6858 N
-6726 F
-6486 S
-4496 N
-4191 N
-772 F
-258 S
-194 N
1035 S
2297 N
48
<30 bytes omitted>
用户输出
25088
系统信息
Exited with return code 0
用户输出
17637
系统信息
Exited with return code 0
用户输出
2000000000
系统信息
Exited with return code 0
用户输出
2000000000
系统信息
Exited with return code 0
用户输出
272
系统信息
Exited with return code 0
用户输出
2935
系统信息
Exited with return code 0
用户输出
54
系统信息
Exited with return code 0
200000
-999993330 S
-999988735 S
-999984678 S
-999977849 S
-999951666 S
-999943701 S
-9999425
<2685579 bytes omitted>
用户输出
1999992428
系统信息
Exited with return code 0
200000
-999996027 N
-999987416 N
-999967709 N
-999963541 N
-999955415 N
-999952044 N
-9999474
<2686720 bytes omitted>
用户输出
3320054196
系统信息
Exited with return code 0
200000
-999990213 F
-999982840 S
-999968801 F
-999967841 F
-999962299 S
-999959418 F
-9999393
<2686251 bytes omitted>
用户输出
3999956454
系统信息
Exited with return code 0
200000
-999993029 N
-999991469 N
-999986935 F
-999985436 F
-999972536 N
-999942131 F
-9999228
<2686073 bytes omitted>
用户输出
2610648739
系统信息
Exited with return code 0
200000
-999995755 S
-999990441 N
-999985911 S
-999985634 N
-999985320 S
-999983113 S
-9999819
<2686104 bytes omitted>
用户输出
2615049664
系统信息
Exited with return code 0
200000
-999991777 S
-999983793 S
-999981785 N
-999977644 F
-999975825 F
-999972503 F
-9999695
<2685682 bytes omitted>
用户输出
3559440156
系统信息
Exited with return code 0
200000
-999995726 S
-999995703 F
-999979384 S
-999973371 S
-999964577 F
-999964134 F
-9999486
<2685782 bytes omitted>
用户输出
3557779308
系统信息
Exited with return code 0
200000
-999995137 S
-999994133 N
-999977895 N
-999966642 F
-999962968 N
-999953746 N
-9999116
<2686247 bytes omitted>
用户输出
2546503759
系统信息
Exited with return code 0
200000
-999994908 N
-999981350 N
-999980985 N
-999967224 N
-999960985 N
-999957419 N
-9999549
<2685946 bytes omitted>
用户输出
2062081408
系统信息
Exited with return code 0