답안 #1087286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087286 2024-09-12T12:29:29 Z jonghak9028 Toilets (JOI16_toilets) C++17
100 / 100
19 ms 7412 KB
/* ************************************************************************** */
/*                                                                            */
/*                                                      :::    :::    :::     */
/*   Problem Number: 17709                             :+:    :+:      :+:    */
/*                                                    +:+    +:+        +:+   */
/*   By: js9028 <boj.kr/u/js9028>                    +#+    +#+          +#+  */
/*                                                  +#+      +#+        +#+   */
/*   https://boj.kr/17709                          #+#        #+#      #+#    */
/*   Solved: 2024/09/12 19:48:56 by js9028        ###          ###   ##.kr    */
/*                                                                            */
/* ************************************************************************** */
#include <bits/stdc++.h>
using namespace std;
#define fastio (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL))
typedef long long ll;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int MAXSIZE = 2000000;
const long long INF = 1e18 + 5;
const double EPSILON = 1e-14;
const ll DIV = 2000003;
const long double pi = 3.14159265358979323846264338327950288419716939937510L;

ll n, m;
string s[200055];
ll cnt[200055];

int main()
{
    fastio;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> s[i];
        cin >> cnt[i];
    }
    ll glt = 0;
    ll mxt = 0;
    for (int i = m - 1; i >= 0; i--)
    {
        string &cs = s[i];

        ll nt = 0;

        for (int j = cs.size() - 1; j >= 0; j--)
        {
            nt += (cs[j] == 'M' ? -1 : 1);
            mxt = min(mxt, nt + glt);

        }
        
        glt += nt * (cnt[i] - 1);
        nt = 0;
        
        for (int j = cs.size() - 1; j >= 0; j--)
        {
            nt += (cs[j] == 'M' ? -1 : 1);
            mxt = min(mxt, nt + glt);
        }

        glt += nt;
        mxt = min(mxt, glt);
    }
    if (glt < 0)
    {
        cout << -1;
    }

    else
    {
        cout << max(0ll, -mxt - 1);
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 3 ms 6608 KB Output is correct
9 Correct 3 ms 6492 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 3 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 3 ms 6608 KB Output is correct
9 Correct 3 ms 6492 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 3 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 3 ms 7000 KB Output is correct
24 Correct 3 ms 7000 KB Output is correct
25 Correct 3 ms 7004 KB Output is correct
26 Correct 3 ms 7004 KB Output is correct
27 Correct 3 ms 7004 KB Output is correct
28 Correct 4 ms 7004 KB Output is correct
29 Correct 3 ms 7004 KB Output is correct
30 Correct 3 ms 7000 KB Output is correct
31 Correct 3 ms 7004 KB Output is correct
32 Correct 3 ms 7004 KB Output is correct
33 Correct 3 ms 7004 KB Output is correct
34 Correct 3 ms 7004 KB Output is correct
35 Correct 3 ms 7004 KB Output is correct
36 Correct 3 ms 7004 KB Output is correct
37 Correct 3 ms 7004 KB Output is correct
38 Correct 3 ms 7004 KB Output is correct
39 Correct 3 ms 7004 KB Output is correct
40 Correct 3 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6488 KB Output is correct
2 Correct 4 ms 6492 KB Output is correct
3 Correct 3 ms 6492 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 3 ms 6608 KB Output is correct
9 Correct 3 ms 6492 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Correct 3 ms 6488 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 3 ms 6492 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 3 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6492 KB Output is correct
23 Correct 3 ms 7000 KB Output is correct
24 Correct 3 ms 7000 KB Output is correct
25 Correct 3 ms 7004 KB Output is correct
26 Correct 3 ms 7004 KB Output is correct
27 Correct 3 ms 7004 KB Output is correct
28 Correct 4 ms 7004 KB Output is correct
29 Correct 3 ms 7004 KB Output is correct
30 Correct 3 ms 7000 KB Output is correct
31 Correct 3 ms 7004 KB Output is correct
32 Correct 3 ms 7004 KB Output is correct
33 Correct 3 ms 7004 KB Output is correct
34 Correct 3 ms 7004 KB Output is correct
35 Correct 3 ms 7004 KB Output is correct
36 Correct 3 ms 7004 KB Output is correct
37 Correct 3 ms 7004 KB Output is correct
38 Correct 3 ms 7004 KB Output is correct
39 Correct 3 ms 7004 KB Output is correct
40 Correct 3 ms 7000 KB Output is correct
41 Correct 19 ms 7260 KB Output is correct
42 Correct 15 ms 7412 KB Output is correct
43 Correct 3 ms 6488 KB Output is correct
44 Correct 3 ms 6492 KB Output is correct
45 Correct 3 ms 6492 KB Output is correct
46 Correct 5 ms 7004 KB Output is correct
47 Correct 4 ms 6748 KB Output is correct
48 Correct 3 ms 6748 KB Output is correct
49 Correct 3 ms 6748 KB Output is correct
50 Correct 3 ms 6908 KB Output is correct
51 Correct 5 ms 7004 KB Output is correct
52 Correct 13 ms 7264 KB Output is correct
53 Correct 13 ms 7260 KB Output is correct
54 Correct 14 ms 7272 KB Output is correct
55 Correct 3 ms 6748 KB Output is correct
56 Correct 3 ms 6748 KB Output is correct