結果

問題 No.2398 ヒドラ崩し
ユーザー 👑 NachiaNachia
提出日時 2023-07-28 23:08:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,353 bytes
コンパイル時間 779 ms
コンパイル使用メモリ 80,328 KB
最終ジャッジ日時 2025-02-15 20:42:19
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 6 TLE * 5 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

int main(){
    string H; cin >> H;
    vector<int> L;
    vector<int> R;
    auto dfs = [&](auto& dfs, int pos) -> int {
        if(pos == (int)H.size() || H[pos] != '(') return -1;
        int x = L.size();
        L.push_back(-1);
        R.push_back(-1);
        pos++;
        L[x] = dfs(dfs, pos);
        pos++;
        R[x] = dfs(dfs, pos);
        return x;
    };
    int root = dfs(dfs, 0);
    auto dp = [&](auto& dp, int pos) -> int {
        if(pos == -1) return -1;
        int rdp = dp(dp, R[pos]);
        if(abs(rdp) >= 2) return rdp;
        if(L[pos] < 0) return -rdp;
        int tmp = L[pos];
        if(abs(tmp) <= 1) tmp *= 2;
        return tmp;
    };
    int ans = dp(dp, root);
    if(ans > 1) ans = 1;
    if(ans < -1) ans = -1;
    if(ans == 1) cout << 0 << endl;
    if(ans == -1) cout << 1 << endl;
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0