結果
| 問題 |
No.3142 Balancing with O=>X Flip
|
| ユーザー |
it_is_a_pity_
|
| 提出日時 | 2025-05-16 21:30:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 921 bytes |
| コンパイル時間 | 3,937 ms |
| コンパイル使用メモリ | 251,912 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-16 23:53:10 |
| 合計ジャッジ時間 | 4,583 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(v) v.begin(),v.end()
const ll INF = (ll)2e18;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
string S;
cin >> N >> S;
if(N%2==1){
cout << "No" << endl;
return 0;
}
ll cnt = 0;
rep(i,N){
if(S[i]=='('){
cnt++;
}
}
if(cnt!=N-cnt){
cout << "No" << endl;
return 0;
}
if(S[0]==')'){
cout << "No" << endl;
return 0;
}
ll num = 0;
rep(i,N){
if(S[i]=='('){
num++;
}
else{
num--;
}
if(num<0){
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
}
it_is_a_pity_