結果
問題 |
No.684 Prefix Parenthesis
|
ユーザー |
![]() |
提出日時 | 2018-05-11 23:57:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 931 bytes |
コンパイル時間 | 1,360 ms |
コンパイル使用メモリ | 162,772 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 09:07:35 |
合計ジャッジ時間 | 2,335 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 WA * 16 |
ソースコード
#include<bits/stdc++.h> #define INF 1000000007 #define LINF 1000000000000000007 using namespace std; typedef long long Int; typedef pair<Int, Int> P; int n; P r[100000]; string s; int main(){ cin >> n; cin >> s; if(s[0] == ')') r[0] = make_pair(1, 0); else r[0] = make_pair(0,0); bool y = 0, x = 0; if(s[0] == ')') y = 1; else x = 1; for(int i = 1; i < n; i++){ r[i].first = r[i-1].first; if(s[i] == ')'){r[i].first++; y = 1;} else x = 1; r[i].second = i; } if(!x || !y){cout << 0 << endl; return 0;} sort(r, r+ n); Int cnt = 0, migi = 0, hidari = 0; for(int i = 1; i < n; i++){ int j = i, k = i; while(r[j-1].first == r[j].first){ j++; } i = j; while(j >= k){ if(j != 0) migi += r[j].first; hidari += r[j-1].second - r[j-1].first + 1; cnt += min(migi, hidari)*2; migi -= min(migi, hidari); hidari -= min(migi, hidari); j--; } } cout << cnt << endl; return 0; }