Submission #1347332

#TimeUsernameProblemLanguageResultExecution timeMemory
1347332reivaxmarTomahawk (COCI26_tomahawk)C++20
70 / 70
7 ms460 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define endl "\n"

#define vi vector<int>
#define vvi vector<vi>

void solve() {
    int n, q;
    cin >> n >> q;

    int l = 0, r = 0;
    int d = 0, u = 0;
    int mid1 = 0, mid2 = 0, mid3 = 0;
    while(q--) {
        char c;
        int x;
        cin >> c >> x;

        if(c == 'L') {
            l += x;
            if(x == (n+1)/2) {
                if(n & 1) { mid1+=2; mid2++; }
                else mid1++;
            } else if(n & 1 && x == n/2) mid1++;
        } else if(c == 'R') {
            r += x;
            if(x == (n+1)/2) {
                if(n & 1) { mid3+=2; mid2++; }
                else mid2++;
            } else if(n & 1 && x == n/2) mid3++;
        } else { // c == 'D'
            d += x;
            if(x == n) u++;
        }
    }

    int mx = max(d + r, d + l);
    int mn = 0;
    if(n & 1) {
        // mn = mid1 + u;
        mn = min(min(mid1 + u, mid2 + u), mid3 + u);
    } else {
        mn = min(mid1 + u, mid2 + u);
    }

    // cout << "dr: " << d+r << ", dl: " << d + l << ", m1: " << mid1+u << ", m2: " << mid2+u << endl;

    // cout << "mx, mn: " << mx << ", " << mn << endl;

    cout << mx - mn << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    // int t;
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    solve();
}
#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...