毒瘤题求调
查看原帖
毒瘤题求调
1287451
MuktorFM楼主2025/7/22 20:41
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[2005];
signed main(){
    int T; cin >> T;
    for(int _ = 1;_ <= T;_++){
        memset(a,-1,sizeof a);
        string s; cin >> s;
        int n = s.size();
        stack<int> st;
        for (int i = 0;i < n;i++){
            if(s[i] == '(') st.push(i);
            else if(s[i] == ')'){
                if(!st.empty()){
                    int j = st.top();
                    st.pop();
                    a[j] = i;
                    a[i] = j;
                }
            }
        }
        int pos = 0,ans = 0;
        map<int,int> bx;
        int pc = 0;
        while(pc < n){
            char c = s[pc];
            if(c == 'b'){
                pos = (pos - 1 + (1LL << 40)) % (1LL << 40);
                ans++;
                pc++;
            }else if(c == 'f'){
                pos = (pos + 1) % (1LL << 40);
                ans++;
                pc++;
            }else if(c == 'u'){
                int cnt = 1;
                if(bx.find(pos) != bx.end()) cnt = bx[pos];
                cnt--;
                if(cnt == 0) cnt = 256;
                if(cnt == 1){
                    if(bx.find(pos) != bx.end()) bx.erase(pos);
                }else bx[pos] = cnt;
                pc++;
            }else if(c == 'd'){
                int cnt = 1;
                if(bx.find(pos) != bx.end()) cnt = bx[pos];
                cnt++;
                if(cnt == 257) cnt = 1;
                if(cnt == 1){
                    if(bx.find(pos) != bx.end()) bx.erase(pos);
                }else bx[pos] = cnt;
                pc++;
            }else if(c == '(') pc++;
            else if(c == ')'){
                int cnt = 1;
                if(bx[pos]) cnt = bx[pos];
                if(cnt > 1) pc = a[pc] + 1;
                else pc++;
            }else pc++;
        }
        cout << "Case #" << _ << ": " << ans << "\n";
    }
    return 0;
}

if(bx[pos]) cnt = bx[pos]; 删掉就不会 TLE 了(但会WA),求调,玄 2 关

2025/7/22 20:41
加载中...