编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#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;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:4 ms
内存:300 KiB

输入文件(1.in

4
0 S
5 N
8 N
12 F

答案文件(1.out

12

用户输出

12

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:4 ms
内存:268 KiB

输入文件(2.in

5
7 S
24 F
26 F
41 S
53 S

答案文件(2.out

48

用户输出

48

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:4 ms
内存:300 KiB

输入文件(3.in

10
66 S
67 S
72 S
73 S
76 S
78 F
79 F
83 F
84 F
85 N

答案文件(3.out

26

用户输出

26

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:4 ms
内存:344 KiB

输入文件(4.in

10
61 S
64 S
68 S
71 S
72 S
73 S
74 N
86 N
87 F
90 F

答案文件(4.out

29

用户输出

29

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:3 ms
内存:268 KiB

输入文件(5.in

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>

答案文件(5.out

25088

用户输出

25088

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:4 ms
内存:296 KiB

输入文件(6.in

6
-8401 S
-5558 N
-3457 N
-2361 S
6966 N
8140 F

答案文件(6.out

17637

用户输出

17637

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:4 ms
内存:376 KiB

输入文件(7.in

2
1 S
2 S

答案文件(7.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:3 ms
内存:348 KiB

输入文件(8.in

2
-1000000000 F
1000000000 S

答案文件(8.out

0

用户输出

0

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:3 ms
内存:276 KiB

输入文件(9.in

2
-1000000000 N
1000000000 N

答案文件(9.out

2000000000

用户输出

2000000000

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:4 ms
内存:348 KiB

输入文件(10.in

2
-1000000000 F
1000000000 N

答案文件(10.out

2000000000

用户输出

2000000000

系统信息

Exited with return code 0
测试点 #11
Accepted
得分:100
用时:4 ms
内存:276 KiB

输入文件(11.in

9
-105 S
-81 F
-47 N
-25 S
-23 F
55 N
57 S
67 F
76 N

答案文件(11.out

272

用户输出

272

系统信息

Exited with return code 0
测试点 #12
Accepted
得分:100
用时:4 ms
内存:352 KiB

输入文件(12.in

6
-13 S
-10 N
-6 S
-1 N
4 S
10 N

答案文件(12.out

32

用户输出

32

系统信息

Exited with return code 0
测试点 #13
Accepted
得分:100
用时:6 ms
内存:300 KiB

输入文件(13.in

8
-839 N
-820 N
-488 N
-334 S
-83 F
187 S
380 F
804 N

答案文件(13.out

2935

用户输出

2935

系统信息

Exited with return code 0
测试点 #14
Accepted
得分:100
用时:4 ms
内存:300 KiB

输入文件(14.in

8
-12 N
-9 F
-2 S
-1 S
2 F
8 F
9 S
15 N

答案文件(14.out

54

用户输出

54

系统信息

Exited with return code 0
测试点 #15
Accepted
得分:100
用时:4 ms
内存:348 KiB

输入文件(15.in

6
0 F
3 N
7 F
9 F
11 N
13 F

答案文件(15.out

17

用户输出

17

系统信息

Exited with return code 0
测试点 #16
Accepted
得分:100
用时:14 ms
内存:3440 KiB

输入文件(16.in

200000
-999993330 S
-999988735 S
-999984678 S
-999977849 S
-999951666 S
-999943701 S
-9999425
<2685579 bytes omitted>

答案文件(16.out

1999992428

用户输出

1999992428

系统信息

Exited with return code 0
测试点 #17
Accepted
得分:100
用时:15 ms
内存:3420 KiB

输入文件(17.in

200000
-999996027 N
-999987416 N
-999967709 N
-999963541 N
-999955415 N
-999952044 N
-9999474
<2686720 bytes omitted>

答案文件(17.out

3320054196

用户输出

3320054196

系统信息

Exited with return code 0
测试点 #18
Accepted
得分:100
用时:14 ms
内存:3464 KiB

输入文件(18.in

200000
-999990213 F
-999982840 S
-999968801 F
-999967841 F
-999962299 S
-999959418 F
-9999393
<2686251 bytes omitted>

答案文件(18.out

3999956454

用户输出

3999956454

系统信息

Exited with return code 0
测试点 #19
Accepted
得分:100
用时:16 ms
内存:3460 KiB

输入文件(19.in

200000
-999993029 N
-999991469 N
-999986935 F
-999985436 F
-999972536 N
-999942131 F
-9999228
<2686073 bytes omitted>

答案文件(19.out

2610648739

用户输出

2610648739

系统信息

Exited with return code 0
测试点 #20
Accepted
得分:100
用时:16 ms
内存:3444 KiB

输入文件(20.in

200000
-999995755 S
-999990441 N
-999985911 S
-999985634 N
-999985320 S
-999983113 S
-9999819
<2686104 bytes omitted>

答案文件(20.out

2615049664

用户输出

2615049664

系统信息

Exited with return code 0
测试点 #21
Accepted
得分:100
用时:16 ms
内存:3408 KiB

输入文件(21.in

200000
-999991777 S
-999983793 S
-999981785 N
-999977644 F
-999975825 F
-999972503 F
-9999695
<2685682 bytes omitted>

答案文件(21.out

3559440156

用户输出

3559440156

系统信息

Exited with return code 0
测试点 #22
Accepted
得分:100
用时:16 ms
内存:3448 KiB

输入文件(22.in

200000
-999995726 S
-999995703 F
-999979384 S
-999973371 S
-999964577 F
-999964134 F
-9999486
<2685782 bytes omitted>

答案文件(22.out

3557779308

用户输出

3557779308

系统信息

Exited with return code 0
测试点 #23
Accepted
得分:100
用时:16 ms
内存:3396 KiB

输入文件(23.in

200000
-999995137 S
-999994133 N
-999977895 N
-999966642 F
-999962968 N
-999953746 N
-9999116
<2686247 bytes omitted>

答案文件(23.out

2546503759

用户输出

2546503759

系统信息

Exited with return code 0
测试点 #24
Accepted
得分:100
用时:14 ms
内存:3368 KiB

输入文件(24.in

200000
-999994908 N
-999981350 N
-999980985 N
-999967224 N
-999960985 N
-999957419 N
-9999549
<2685946 bytes omitted>

答案文件(24.out

2062081408

用户输出

2062081408

系统信息

Exited with return code 0
测试点 #25
Accepted
得分:100
用时:19 ms
内存:3472 KiB

输入文件(25.in

200000
-999994097 N
-999985335 N
-999978822 N
-999977074 N
-999966823 N
-999965932 N
-9999657
<2686448 bytes omitted>

答案文件(25.out

1999989645

用户输出

1999989645

系统信息

Exited with return code 0