結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー milanis48663220milanis48663220
提出日時 2023-05-20 00:12:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 382 ms / 2,000 ms
コード長 3,073 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 133,024 KB
実行使用メモリ 22,444 KB
最終ジャッジ日時 2023-08-23 02:12:34
合計ジャッジ時間 15,099 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 237 ms
8,584 KB
testcase_02 AC 303 ms
12,836 KB
testcase_03 AC 266 ms
12,832 KB
testcase_04 AC 265 ms
13,540 KB
testcase_05 AC 275 ms
14,116 KB
testcase_06 AC 315 ms
18,236 KB
testcase_07 AC 303 ms
17,384 KB
testcase_08 AC 325 ms
19,412 KB
testcase_09 AC 340 ms
19,480 KB
testcase_10 AC 271 ms
12,972 KB
testcase_11 AC 301 ms
13,152 KB
testcase_12 AC 298 ms
13,020 KB
testcase_13 AC 290 ms
12,976 KB
testcase_14 AC 298 ms
12,968 KB
testcase_15 AC 296 ms
13,176 KB
testcase_16 AC 320 ms
13,012 KB
testcase_17 AC 293 ms
13,312 KB
testcase_18 AC 294 ms
13,076 KB
testcase_19 AC 297 ms
13,048 KB
testcase_20 AC 299 ms
13,148 KB
testcase_21 AC 382 ms
22,356 KB
testcase_22 AC 366 ms
22,396 KB
testcase_23 AC 377 ms
22,392 KB
testcase_24 AC 377 ms
22,388 KB
testcase_25 AC 378 ms
22,380 KB
testcase_26 AC 373 ms
22,424 KB
testcase_27 AC 380 ms
22,432 KB
testcase_28 AC 375 ms
22,388 KB
testcase_29 AC 369 ms
22,444 KB
testcase_30 AC 373 ms
22,388 KB
testcase_31 AC 181 ms
22,332 KB
testcase_32 AC 181 ms
22,388 KB
testcase_33 AC 182 ms
22,396 KB
testcase_34 AC 196 ms
22,364 KB
testcase_35 AC 196 ms
22,436 KB
testcase_36 AC 195 ms
22,392 KB
testcase_37 AC 10 ms
4,376 KB
testcase_38 AC 303 ms
13,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/segtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int op(int x, int y){
    return x+y;
}

int e(){
    return 0;
}

using Seg = atcoder::segtree<int, op, e>;

void solve(){
    int n; cin >> n;
    vector<int> x(n);
    vector<bool> del(n);
    set<int> st;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        assert(s == "True" || s == "False");
        x[i] = (s[0] == 'T');
        st.insert(i);
    }
    Seg seg(vector<int>(n-1, 1));
    vector<string> y(n-1);
    vector<int> s(n-1);
    for(int i = 0; i < n-1; i++) cin >> y[i];
    for(int i = 0; i < n-1; i++) {
        cin >> s[i];
    }
    for(int i = 0; i < n-1; i++){
        assert(seg.all_prod() == n-1-i);
        auto g = [&](int x){
            return x < s[i];
        };
        int c = seg.max_right(0, g);
        bool ans = 0;
        auto p = st.upper_bound(c);
        assert(p != st.end());
        int ir = *p;
        int il = *prev(p);
        assert(!del[il]);
        assert(!del[ir]);
        assert(ir == c+1);
        bool fl = x[il];
        bool fr = x[ir];
        assert(il <= c);
        del[ir] = true;
       
        assert(il >= 0);
        assert(ir < n);
        assert(seg.get(c) == 1);
        assert(seg.prod(0, c+1) == s[i]);
        st.erase(ir);
        if(y[c] == "and"){
            ans = (fl&fr); 
        }else if(y[c] == "or"){
            ans = (fl|fr); 
        }else if(y[c] == "xor"){
            ans = (fl^fr);
        }else{
            assert(y[c] == "imp");
            if(fl) ans = fr;
            else ans = 1;
        }
        x[il] = ans;
        seg.set(c, 0);
        // for(auto [i, f]: st) cout << f << ' ';
        // cout << endl;
    }
    if(x[0] == 1){
        cout << "True\n";
    }else{
        cout << "False\n";
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--) solve();
}
0