Submission #13101726


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)1e6+5
#define N (1ll<<10)

ll sum[MAXN] = {0};
ll mn[MAXN] = {0};

bool comp1(ll &a, ll &b){
    return mn[a] > mn[b];
}

bool comp2(ll &a, ll &b){
    return mn[a] < mn[b];

}

void solve(){
    ll n;
    cin>>n;
    string s[n];
    loop(i,0,n){
        cin>>s[i];
    }
    loop(i,0,n){
        loop(j,0,s[i].len()){
            if(s[i][j] == '('){
                sum[i]++;
                mn[i] = min(mn[i], sum[i]);
            }
            else {
                sum[i]--;
                mn[i] = min(mn[i], sum[i]);
            }
        }
    }

    // loop(i,0,n){
    //     trace(sum[i], mn[i]);
    // }

    vl pos, neg, extra;
    loop(i,0,n){
        if(sum[i] == 0){
            if(mn[i] == 0) continue;
            else {
                extra.pb(i);
            }
        }
        else if(sum[i] > 0){
            pos.pb(i);
        }
        else if(sum[i] < 0){
            neg.pb(i);
        }
    }

    ll curSum = 0;
    vl v;
    for(auto x: pos){
        if(mn[x] == 0){
            curSum += sum[x];
        }
        else {
            v.pb(x);
        }
    }
    // printc(v);
    sort(all(v), comp1);
    // printc(v);
    for(auto x: v){
        if(curSum + mn[x] < 0){
            print("No");
            ret;
        }
        curSum += sum[x];
    }
    for(auto x: extra){
        if(curSum + mn[x] < 0){
            print("No");
            ret;
        }
    }
    // printc(neg);
    sort(all(neg), comp2);
    // printc(neg);
    for(auto x: neg){
        if(curSum + mn[x] < 0){
            print("No");
            ret;
        }
        curSum += sum[x];
    }
    if(curSum != 0){
        print("No");
        ret;
    }
    print("Yes");
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
        
    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}

Submission Info

Submission Time
Task F - Bracket Sequencing
User latestart
Language C++ (GCC 9.2.1)
Score 0
Code Size 4287 Byte
Status WA
Exec Time 112 ms
Memory 58172 KiB

Compile Error

./Main.cpp:6: warning: ignoring #pragma comment  [-Wunknown-pragmas]
    6 | #pragma comment(linker, "/stack:200000000")
      | 
./Main.cpp: In function ‘void solve()’:
./Main.cpp:29:33: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   29 | #define loop(i,a,b) for(ll i=a;i<b;i++)
......
   87 |         loop(j,0,s[i].len()){
      |              ~~~~~~~~~~~~~~      
./Main.cpp:87:9: note: in expansion of macro ‘loop’
   87 |         loop(j,0,s[i].len()){
      |         ^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 4
AC × 20
WA × 12
Set Name Test Cases
Sample sample_01, sample_02, sample_03, sample_04
All random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_21, random_22, random_23, random_31, random_32, random_33, random_41, random_42, random_43, random_51, random_52, random_53, random_61, random_62, random_63, sample_01, sample_02, sample_03, sample_04
Case Name Status Exec Time Memory
random_01 AC 46 ms 17756 KiB
random_02 AC 103 ms 48080 KiB
random_03 AC 65 ms 24228 KiB
random_04 AC 110 ms 58172 KiB
random_05 AC 112 ms 58124 KiB
random_06 AC 42 ms 24012 KiB
random_07 AC 17 ms 7068 KiB
random_08 AC 11 ms 5000 KiB
random_09 AC 13 ms 4644 KiB
random_10 AC 40 ms 24128 KiB
random_11 WA 2 ms 3480 KiB
random_12 WA 2 ms 3524 KiB
random_13 WA 2 ms 3524 KiB
random_21 WA 2 ms 3644 KiB
random_22 WA 2 ms 3688 KiB
random_23 WA 2 ms 3632 KiB
random_31 WA 2 ms 3640 KiB
random_32 WA 2 ms 3640 KiB
random_33 WA 5 ms 3524 KiB
random_41 WA 2 ms 3644 KiB
random_42 WA 2 ms 3612 KiB
random_43 WA 2 ms 3536 KiB
random_51 AC 2 ms 3596 KiB
random_52 AC 2 ms 3536 KiB
random_53 AC 2 ms 3604 KiB
random_61 AC 28 ms 12176 KiB
random_62 AC 37 ms 16336 KiB
random_63 AC 44 ms 22964 KiB
sample_01 AC 2 ms 3580 KiB
sample_02 AC 2 ms 3616 KiB
sample_03 AC 2 ms 3516 KiB
sample_04 AC 2 ms 3516 KiB