1 条题解

  • 0
    @ 2025-11-21 12:01:38
    #include<bits/stdc++.h>
    using namespace std;
    #define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
    using LL = long long;
    using PII = pair<int,int>;
    int main(){
        fre("bracket");
        cin.tie(nullptr) -> ios::sync_with_stdio(false);
        int n;
        cin >> n;
        string s;
        cin >> s;
        int mn = 0,add = 0;
        for(char c:s){
            if(c == '(')add ++;
            else add --;
            mn = min(mn,add);
        }
        int ans = 0,res = 0;
        for(char c:s){
            if(c == '(')res ++;
            else res --;
            if(res < 0)break;
            // if(res * k + mn >= 0 && res * k + add == 0)ans ++;
            int k;
            if(res != 0)k = -add / res;
            else k = 0;
            if(res * k + mn >= 0 && res * k + add == 0)ans ++;
        }
        cout << ans <<"\n";
    }
    
    • 1

    信息

    ID
    23
    时间
    1000ms
    内存
    512MiB
    难度
    5
    标签
    递交数
    33
    已通过
    15
    上传者