제출 #1164066

#제출 시각아이디문제언어결과실행 시간메모리
1164066ozner77Security Gate (JOI18_security_gate)C++17
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef unordered_map<ll,ll> umll;
typedef set<ll> sl;
typedef unordered_set<ll> usl;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef vector<vvi> vvvi;
typedef vector<vvl> vvvl;
vector<string> L;
vector<string> L2;
vector<vector<char>> L3;
ll ans=0;
vector<bool> visited;
void generar(vector<char> V){
    bool ok=true;
    for(ll i=0;i<V.size();i++){
        if(V[i]=='x'){
            V[i]='(';
            generar(V);
            V[i]=')';
            generar(V);
            ok=false;
            break;
        }
    }
    if(ok){
        string uwu;
        for(auto x:V){
            uwu+=x;
        }
        L.pb(uwu);
    }
}
bool check(vector<char> V){
    ll c=0;
    for(ll i=0;i<V.size();i++){
        if(V[i]=='('){
            c++;
        }else{
            c--;
        }
        if(c<0){
            return false;
        }
    }
    if(c>0){
        return false;
    }
    return true;
}
vector<char> flip2(vector<char> V,ll i,ll j){
    for(ll k=i;i<=j;i++){
        if(V[i]=='('){
            V[i]=')';
        }else{
            V[i]='(';
        }
    }
    return V;
}
void flip(ll n){
    for(ll i=0;i<L2.size();i++){
        if(visited[i]){
            continue;
        }
        vector<char> cad2;
        string cad=L2[i];
        for(auto x:cad){
            cad2.pb(x);
        }
        ll t=cad2.size();
        for(ll j=0;j<t-n;j++){
            ll lol=j+n;
            cad2=flip2(cad2,j,lol);
            if(check(cad2)){
                visited[i]=true;
                ans++;
                break;
            }
            cad2=flip2(cad2,j,lol);
        }
    }
}
void check2(){
    for(auto x:L){
        bool ok=false;
        ll c=0;
        for(auto y:x){
            if(y=='('){
                c++;
            }else{
                c--;
            }
            if(c<0){
                ok=true;
            }
        }
        if(c>0){
            ok=true;
        }
        if(ok){
            L2.pb(x);
        }
    }
}
int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    vector<char> caca;
    for(auto x:s){
        caca.pb(x);
    }
    generar(caca);
    check2();
    for(ll i=0;i<L2.size();i++){
        visited.pb(false);
    }
    for(ll i=0;i<n;i++){
        flip(i);
    }
    cout<<ans;
}
#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...