結果
| 問題 |
No.684 Prefix Parenthesis
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-05-27 22:44:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 821 bytes |
| コンパイル時間 | 1,219 ms |
| コンパイル使用メモリ | 80,092 KB |
| 最終ジャッジ日時 | 2025-01-05 10:47:45 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 1 |
ソースコード
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)
struct cmp{
bool operator()(pii a,pii b)const{
int f=a.first-a.second;
f=b.first+max(f,-b.second);
int s=b.first-b.second;
s=a.first+max(s,-a.second);
return f<s;
}
};
int main(){
int n;
string s;
cin>>n>>s;
int mi=0,cur=0;
vector<pii> kenchon(n);
rep(i,n){
cur+=s[i]=='('?1:-1;
mi=min(mi,cur);
kenchon[i]=pii(cur,mi);
}
sort(kenchon.begin(),kenchon.end(),cmp());
lint sum=(lint)n*(lint)(n+1)/2;
lint ans=0;
lint cursum=0;
rep(i,n){
ans=kenchon[i].first+max(ans,(lint)-kenchon[i].second);
cursum+=kenchon[i].first;
}
cout<<sum+(cursum-ans-ans)<<endl;
}
夕叢霧香(ゆうむらきりか)