結果
問題 | No.3142 Balancing with O=>X Flip |
ユーザー |
![]() |
提出日時 | 2025-05-16 22:27:11 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 3,388 bytes |
コンパイル時間 | 2,812 ms |
コンパイル使用メモリ | 281,928 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-05-16 23:54:11 |
合計ジャッジ時間 | 3,668 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<int, int>; using PP = pair<int, P>; using PLL = pair<ll, ll>; using PPLL = pair<ll, PLL>; #define rep(i, n) for(ll i = 0; i < n; ++i) #define rrep(i, n) for(ll i = n - 1; i >= 0; --i) #define loop(i, a, b) for(ll i = a; i <= b; ++i) #define all(v) v.begin(), v.end() #define nC2(n) n * (n - 1) / 2 constexpr ll INF = 9009009009009009009LL; constexpr int INF32 = 2002002002; constexpr ll MOD = 998244353; constexpr ll MOD107 = 1000000007; // Linear Algebra //////////////////////////////////////////////// const double Rad2Deg = 180.0 / M_PI; const double Deg2Rad = M_PI / 180.0; ////////////////////////////////////////////////////////////////// int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1}; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename Container, typename = std::enable_if_t< !std::is_same_v<Container, std::string> && std::is_convertible_v<decltype(std::declval<Container>().begin()), typename Container::iterator>>> ostream &operator<<(ostream &os, const Container &container) { auto it = container.begin(); auto end = container.end(); if (it != end) { os << *it; ++it; } for (; it != end; ++it) { os << " " << *it; } return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (size_t i = 0; i < v.size(); ++i) { os << v[i]; if (i != v.size() - 1) os << " "; } return os; } template <typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& vv) { for (size_t i = 0; i < vv.size(); ++i) { os << vv[i]; if (i != vv.size() - 1) os << "\n"; } return os; } template <typename T> istream& operator>>(istream& is, vector<T>& v) { assert(v.size() > 0); for (size_t i = 0; i < v.size(); ++i) is >> v[i]; return is; } template <typename T> istream& operator>>(istream& is, vector<vector<T>>& vv) { assert(vv.size() > 0); for (size_t i = 0; i < vv.size(); ++i) is >> vv[i]; return is; } struct phash { template<class T1, class T2> inline size_t operator()(const pair<T1, T2> & p) const { auto h1 = hash<T1>()(p.first); auto h2 = hash<T2>()(p.second); size_t seed = h1 + h2; h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b; h1 = ((h1 >> 16) ^ h1) * 0x45d9f3b; h1 = (h1 >> 16) ^ h1; seed ^= h1 + 0x9e3779b9 + (seed << 6) + (seed >> 2); h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b; h2 = ((h2 >> 16) ^ h2) * 0x45d9f3b; h2 = (h2 >> 16) ^ h2; seed ^= h2 + 0x9e3779b9 + (seed << 6) + (seed >> 2); return seed; } }; int solve() { ll n; cin >> n; string s; cin >> s; stack<char> st; rep(i, n) { if (s[i] == '(') { st.push('('); } else if (s[i] == ')') { if (!st.empty()) { st.pop(); } else { cout << "No" << endl; return 0; } } } cout << (st.empty() ? "Yes" : "No") << endl; return 0; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); return solve(); }