제출 #1340443

#제출 시각아이디문제언어결과실행 시간메모리
1340443trungcanTomahawk (COCI26_tomahawk)C++20
70 / 70
11 ms456 KiB
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll INF = 1e18;

int n, q;
ll m1, m2, L, R, mid;
ll mid1, mid2;


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> q;
    if (!(n & 1)) mid1 = INF, mid2 = -INF;
    while (q--){
        char S; cin >> S;
        int x; cin >> x;
        if (S == 'D') {
            m1 += x; m2 += x; mid2 += x;
            if (x == n) ++L, ++R, ++mid1;
        }
        if (S == 'L') {
            m1 += x;
            L += max(x - (n >> 1) + 1, 0);
        }
        if (S == 'R') {
            m2 += x;
            R += max((n >> 1) + (n & 1 ? 2 : 1) - n + x, 0);
        }
        if ((n & 1) && (S == 'L' || S == 'R') && x == ((n + 1) >> 1))
            ++mid1, ++mid2;
    }

    cout << max({m1, m2, mid2}) - min({L, R, mid1});
//    cout << "\n";
//    cout << m1 << " " << m2 << " " << mid2 << "\t" << L << " " << R << " " << mid1 << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...