用户输出
12
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#228 | #1025. 1-02F. JM的睡前故事 | Accepted | 100 | 215 ms | 3472 K | C++ 17 / 2.4 K | LittleFall | 2019-06-20 22:10:41 |
/* LittleFall : Hello! */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline ll read();
const int M = 200016, MOD = 1000000007;
/*
S点,F点,N点
每两个N点之间,要么
(1)3*把两个N点连起来, 减去最长的连续段
(2)2*把两个N点连起来
边界情况(最左边的N点左边还有S点):
(1)如果最左边的S点在N点的左边,就把它们连起来就行
(2)否则,不用考虑.
*/
pair<ll, char> save[M]; //坐标, 点的归属
int main(void) {
#ifdef _LITTLEFALL_
freopen("in.txt", "r", stdin);
#endif
int n = read();
ll cnt_s = 0, cnt_f = 0, cnt_n = 0;
ll min_s = INT_MIN, min_f = INT_MIN, min_n = INT_MIN;
ll max_s = INT_MIN, max_f = INT_MIN, max_n = INT_MIN;
for (int i = 0; i < n; ++i) {
save[i].first = read();
save[i].second = getchar();
if (save[i].second == 'N') {
cnt_n++;
max_n = max(max_n, save[i].first);
if (cnt_n == 1)
min_n = save[i].first;
}
if (save[i].second == 'S') {
cnt_s++;
max_s = max(max_s, save[i].first);
if (cnt_s == 1)
min_s = save[i].first;
}
if (save[i].second == 'F') {
cnt_f++;
max_f = max(max_f, save[i].first);
if (cnt_f == 1)
min_f = save[i].first;
}
}
ll ans = 0;
if (cnt_n == 0) {
ans = max_f - min_f + max_s - min_s;
cout << ans << endl;
return 0;
}
if (cnt_s) {
ans += max(0ll, min_n - min_s);
ans += max(0ll, max_s - max_n);
}
if (cnt_f) {
ans += max(0ll, min_n - min_f);
ans += max(0ll, max_f - max_n);
}
ll lst_n = INT_MIN, lst_s = INT_MIN, lst_f = INT_MIN;
ll mx_sub_s = 0, mx_sub_f = 0;
for (int i = 0; i < n; ++i) {
if (save[i].second == 'N') {
if (lst_n != INT_MIN) {
ll len = save[i].first - lst_n;
mx_sub_s = max(mx_sub_s, save[i].first - lst_s);
mx_sub_f = max(mx_sub_f, save[i].first - lst_f);
ans += min(len * 2, len * 3 - mx_sub_s - mx_sub_f);
}
lst_n = lst_s = lst_f = save[i].first;
mx_sub_s = mx_sub_f = 0;
}
if (save[i].second == 'S') {
mx_sub_s = max(mx_sub_s, save[i].first - lst_s);
lst_s = save[i].first;
}
if (save[i].second == 'F') {
mx_sub_f = max(mx_sub_f, save[i].first - lst_f);
lst_f = save[i].first;
}
}
cout << ans << endl;
return 0;
}
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
用户输出
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