結果

問題 No.684 Prefix Parenthesis
ユーザー beetbeet
提出日時 2018-05-11 23:28:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 914 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 170,512 KB
実行使用メモリ 5,668 KB
最終ジャッジ日時 2023-09-10 18:34:31
合計ジャッジ時間 64,124 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,912 ms
4,380 KB
testcase_01 AC 1,910 ms
4,380 KB
testcase_02 AC 1,911 ms
4,380 KB
testcase_03 AC 1,913 ms
4,376 KB
testcase_04 AC 1,914 ms
4,580 KB
testcase_05 AC 1,917 ms
5,316 KB
testcase_06 AC 1,911 ms
4,376 KB
testcase_07 AC 1,915 ms
5,296 KB
testcase_08 AC 1,911 ms
4,376 KB
testcase_09 AC 1,910 ms
4,384 KB
testcase_10 AC 1,916 ms
5,288 KB
testcase_11 AC 1,915 ms
5,252 KB
testcase_12 AC 1,909 ms
4,376 KB
testcase_13 AC 1,918 ms
5,280 KB
testcase_14 AC 1,915 ms
5,272 KB
testcase_15 AC 1,912 ms
4,380 KB
testcase_16 AC 1,916 ms
5,256 KB
testcase_17 AC 1,913 ms
4,380 KB
testcase_18 AC 1,909 ms
4,376 KB
testcase_19 AC 1,916 ms
5,348 KB
testcase_20 AC 1,914 ms
5,348 KB
testcase_21 AC 1,916 ms
5,344 KB
testcase_22 AC 1,916 ms
5,228 KB
testcase_23 AC 1,915 ms
5,268 KB
testcase_24 AC 1,917 ms
5,276 KB
testcase_25 AC 1,913 ms
5,344 KB
testcase_26 AC 1,910 ms
4,380 KB
testcase_27 AC 1,911 ms
4,380 KB
testcase_28 AC 1,910 ms
4,380 KB
testcase_29 WA -
testcase_30 AC 1,914 ms
5,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  auto start=clock();
  Int n;
  string s;
  cin>>n>>s;
  

  using P = pair<Int, Int>;
  vector<P> v;
  Int a=0,b=0,c=0,ans=0;
  for(Int i=0;i<n;i++){
    if(s[i]=='(') a++;
    else if(a) a--,c++;
    else b++;
    ans+=c;
    v.emplace_back(a,b);
  }
  
  Int res=0;
  while((double)(clock()-start)/CLOCKS_PER_SEC<1.9){
    Int tmp=0;
    a=0;b=0;
    for(Int i=0;i<n;i++){
      Int x,y;
      tie(x,y)=v[i];
      if(min(a,y)<min(x,b)) swap(a,x),swap(b,y);
      Int z=min(a,y);
      b+=y-z;
      a=x+a-z;
      tmp+=z;
    }
    chmax(res,tmp);
    random_shuffle(v.begin(),v.end());
  }

  ans+=res;
  ans<<=1;
  cout<<ans<<endl;
  return 0;
}
0