Submission #13063944


Source Code Expand

/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)


ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

bool comp(pll a,pll b)
{
    return a.sec-a.fs>b.sec-b.fs;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/

		//cout<<"Case #"<<test+1<<": ";
		ll n=nxt();
        vc<pll> v;
        ll tot_open=0,tot_close=0;
        bool flag=false;
        rep(a,0,n)
        {
            string s;
            cin>>s;
            ll open=0,close=0,temp=0;
            for(auto y:s)
            {
                if(y=='(')
                    temp++;
                else if(temp==0)
                    close++;
                else
                    temp--;
            }
            open=temp;
            if(open>0 and close>0)
                v.pb({close,open});
            else if(open)
                tot_open+=open;
            else
                tot_close+=close;
        }
        sort(all(v),comp);
        for(auto y:v)
        {
            tot_open-=y.fs;
            if(tot_open<0)
                flag=true;
            tot_open+=y.sec;
        }
        if(flag)
            cout<<"No\n";
        else if(tot_open==tot_close)
            cout<<"Yes\n";
        else
            cout<<"No\n";
	printclock;
	return 0;
}

Submission Info

Submission Time
Task F - Bracket Sequencing
User swapnil159
Language C++ (GCC 9.2.1)
Score 600
Code Size 3824 Byte
Status AC
Exec Time 50 ms
Memory 7412 KiB

Compile Error

./Main.cpp: In function ‘void err(std::istream_iterator<std::__cxx11::basic_string<char> >)’:
./Main.cpp:53:35: warning: unused parameter ‘it’ [-Wunused-parameter]
   53 | void err(istream_iterator<string> it) {}
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 32
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 32 ms 5220 KiB
random_02 AC 47 ms 4204 KiB
random_03 AC 41 ms 5284 KiB
random_04 AC 49 ms 3696 KiB
random_05 AC 50 ms 3776 KiB
random_06 AC 30 ms 3704 KiB
random_07 AC 14 ms 3716 KiB
random_08 AC 10 ms 3728 KiB
random_09 AC 11 ms 3816 KiB
random_10 AC 28 ms 3704 KiB
random_11 AC 2 ms 3688 KiB
random_12 AC 2 ms 3712 KiB
random_13 AC 2 ms 3776 KiB
random_21 AC 2 ms 3756 KiB
random_22 AC 2 ms 3784 KiB
random_23 AC 2 ms 3708 KiB
random_31 AC 2 ms 3720 KiB
random_32 AC 2 ms 3784 KiB
random_33 AC 2 ms 3784 KiB
random_41 AC 2 ms 3748 KiB
random_42 AC 2 ms 3708 KiB
random_43 AC 2 ms 3692 KiB
random_51 AC 4 ms 3696 KiB
random_52 AC 2 ms 3700 KiB
random_53 AC 2 ms 3804 KiB
random_61 AC 26 ms 5260 KiB
random_62 AC 33 ms 7412 KiB
random_63 AC 38 ms 7368 KiB
sample_01 AC 2 ms 3704 KiB
sample_02 AC 2 ms 3776 KiB
sample_03 AC 2 ms 3768 KiB
sample_04 AC 2 ms 3700 KiB