Submission #13105666


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
bool find(string ans)
{
    int c=0;
for(int i=0;i<ans.size();i++)
{
    if(ans[i]=='(')
        c+=1;
    else
        c-=1;
    if(c<0)
    {

        return 0;
    }
}
if(c==0)
{
    return 1;
}
return 0;


}

int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
string str[n];
map<int,string> mp;
vector<pair<int,pair<int,int > > > arr;
string ans="";
for(int i=0;i<n;i++)
{
    cin>>str[i];
    int c=0;
    int mneg=0;
    int x=str[i].size();
    for(int j=0;j<x;j++)
    {
        if(str[i][j]=='(')
            c+=1;
        else
            c-=1;
        mneg=min(mneg,c);
    }
    if(mneg==0)
    {
        ans+=str[i];
    }
    else
    {
        arr.pb({mneg,{c,i}});
    }
    mp[i]=str[i];
}
int vis[n+1]={};
int x=arr.size();
sort(arr.begin(),arr.end());
for(int i=x-1;i>=0;i--)
{
    if(arr[i].ss.ff>=0)
    {vis[i]=1;
        ans+=mp[arr[i].ss.ss];
    }
}
for(int i=x-1;i>=0;i--)
{
    if(!vis[i])
    {
        ans+=mp[arr[i].ss.ss];
        vis[i]=1;
    }
}

if(find(ans))
{
    cout<<"Yes"<<endl;
}
else
    cout<<"No"<<endl;







    return 0;
}

Submission Info

Submission Time
Task F - Bracket Sequencing
User akkipoonia
Language C++ (GCC 9.2.1)
Score 0
Code Size 1411 Byte
Status WA
Exec Time 477 ms
Memory 134980 KiB

Compile Error

./Main.cpp: In function ‘bool find(std::string)’:
./Main.cpp:13:14: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   13 | for(int i=0;i<ans.size();i++)
      |             ~^~~~~~~~~~~
./Main.cpp: In function ‘int32_t main()’:
./Main.cpp:91:1: warning: this ‘else’ clause does not guard... [-Wmisleading-indentation]
   91 | else
      | ^~~~
./Main.cpp:100:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘else’
  100 |     return 0;
      |     ^~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 4
AC × 18
WA × 14
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 WA 135 ms 40716 KiB
random_02 AC 427 ms 111832 KiB
random_03 WA 197 ms 55576 KiB
random_04 AC 473 ms 134980 KiB
random_05 AC 477 ms 134960 KiB
random_06 AC 161 ms 56200 KiB
random_07 AC 34 ms 13100 KiB
random_08 AC 18 ms 8168 KiB
random_09 AC 17 ms 7528 KiB
random_10 AC 160 ms 56420 KiB
random_11 WA 2 ms 3692 KiB
random_12 WA 2 ms 3588 KiB
random_13 WA 2 ms 3580 KiB
random_21 WA 3 ms 3660 KiB
random_22 WA 2 ms 3576 KiB
random_23 WA 2 ms 3700 KiB
random_31 WA 2 ms 3580 KiB
random_32 WA 2 ms 3648 KiB
random_33 WA 3 ms 3568 KiB
random_41 WA 2 ms 3580 KiB
random_42 WA 2 ms 3592 KiB
random_43 WA 2 ms 3648 KiB
random_51 AC 4 ms 3568 KiB
random_52 AC 2 ms 3700 KiB
random_53 AC 2 ms 3628 KiB
random_61 AC 78 ms 27728 KiB
random_62 AC 107 ms 37456 KiB
random_63 AC 182 ms 55720 KiB
sample_01 AC 2 ms 3576 KiB
sample_02 AC 4 ms 3660 KiB
sample_03 AC 2 ms 3460 KiB
sample_04 AC 2 ms 3664 KiB