12 pts 求调
查看原帖
12 pts 求调
1286053
Nostopathy楼主2024/3/3 10:19
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#define int long long
#define RFor(a, b, c) for (int i = a; i <= b; i += c)
using namespace std;

int n, m, a[200006], b[200006], c, RR;
string s;

int Read () {
    int i;
    cin >> i;
    return i;
}

signed main () {
    n = Read(), m = Read();
    cin >> s;
    s = s[n - 1] + s;
    
    RFor(1, n, 1) {
        a[i] = Read();
        c = c + a[i];
    }
    
    RFor(0, n, 1) {
        if (s[i] == 'L' && s[i + 1] == 'R') {
            int L = 0, R = 0; int lpos =
                i - 1 <= 0 ? i - 1 + n : i - 1, rpos = i + 2 > n ? i + 2 - n : i + 2;
                
            while (s[lpos] == 'R') {
                L = L + a[lpos];
                lpos = lpos - 1;
                if (lpos < 1)
                    lpos = lpos + n;
            }
            
            while (s[rpos] == 'L') {
                R = R + a[rpos];
                rpos = rpos + 1;
                if (rpos > n)
                    rpos = rpos - n;
            }
            
            RR = RR + min(m, L) + min(m, R);
        }
    }
    
    cout << c - RR;
    if (1 + 1 == 3) return 1;
    return 0;
}

谢谢QaQ

2024/3/3 10:19
加载中...