用户输出
12
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#227 | #1025. 1-02F. JM的睡前故事 | Accepted | 100 | 370 ms | 3400 K | C / 1.2 K | Komeiji Koishi | 2019-06-20 21:49:30 |
#include <stdio.h>
#include <string.h>
typedef long long ll;
ll n, i, ans = 0, x[200005], c[200005], cnt = 0, st[4], mx[3], fr;
const ll inf = 1e9 + 7;
char s[5];
ll obt(ll a, ll b) {
if (b == -inf)
return 0;
return a - b;
}
ll max(ll a, ll b) {
if (a >= b)
return a;
return b;
}
ll min(ll a, ll b) {
if (a <= b)
return a;
return b;
}
int main() {
scanf("%lld", &n);
for (i = 1; i <= n; i++) {
scanf("%lld", &x[i]);
scanf("%s", s);
if (s[0] == 'S')
c[i] = 1;
if (s[0] == 'F')
c[i] = 2;
if (s[0] == 'N')
c[i] = 3, cnt++;
}
st[1] = st[2] = inf;
if (cnt == 0) {
for (i = 1; i <= n; i++) {
if (st[c[i]] != inf)
ans += x[i] - st[c[i]];
st[c[i]] = x[i];
}
} else {
st[1] = st[2] = mx[1] = mx[2] = fr = -inf;
for (i = 1; i <= n; i++) {
if (c[i] == 3) {
if (fr == -inf)
ans += obt(x[i], st[1]) + obt(x[i], st[2]);
else {
mx[1] = max(mx[1], x[i] - st[1]);
mx[2] = max(mx[2], x[i] - st[2]);
ans += min(3LL * (x[i] - fr) - mx[1] - mx[2], 2LL * (x[i] - fr));
}
fr = x[i];
mx[1] = mx[2] = -inf;
st[1] = st[2] = x[i];
} else {
if (fr == -inf)
ans += obt(x[i], st[c[i]]);
else
mx[c[i]] = max(mx[c[i]], x[i] - st[c[i]]);
st[c[i]] = x[i];
}
}
ans += st[1] - fr + st[2] - fr;
}
printf("%lld\n", ans);
return 0;
}
用户输出
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