제출 #1340280

#제출 시각아이디문제언어결과실행 시간메모리
1340280trungcanTomahawk (COCI26_tomahawk)C++20
6 / 70
10 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;
int cL, cR, cnt;


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

    cin >> n >> q;
    while (q--){
        char S; cin >> S;
        int x; cin >> x;
        if (S == 'D') {
            m1 += x; m2 += x;
            if (x == n) ++L, ++R, ++cnt;
        }
        if (S == 'L') {
            m1 += x;
            if (x == ((n + 1) >> 1))
                L += (n & 1 ? 2 : 1), ++cL;
        }
        if (S == 'R') {
            m2 += x;
            if (x == ((n + 1) >> 1))
                R += (n & 1 ? 2 : 1), ++cR;
        }
    }

    cout << max(m1, m2) - min({L, R, n & 1 ? L - cL + R - cR + cnt : INF});
}
#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...