結果

問題 No.2308 [Cherry 5th Tune B] もしかして、真?
ユーザー 👑 eoeoeoeo
提出日時 2023-05-20 01:13:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 459 ms / 2,000 ms
コード長 7,013 bytes
コンパイル時間 6,963 ms
コンパイル使用メモリ 286,836 KB
実行使用メモリ 23,680 KB
最終ジャッジ日時 2024-12-21 04:15:35
合計ジャッジ時間 19,586 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 282 ms
9,436 KB
testcase_02 AC 356 ms
13,492 KB
testcase_03 AC 332 ms
13,560 KB
testcase_04 AC 328 ms
14,328 KB
testcase_05 AC 352 ms
14,848 KB
testcase_06 AC 385 ms
18,664 KB
testcase_07 AC 370 ms
17,648 KB
testcase_08 AC 408 ms
20,224 KB
testcase_09 AC 403 ms
20,068 KB
testcase_10 AC 365 ms
13,824 KB
testcase_11 AC 374 ms
13,656 KB
testcase_12 AC 375 ms
13,524 KB
testcase_13 AC 380 ms
13,652 KB
testcase_14 AC 378 ms
13,528 KB
testcase_15 AC 390 ms
13,528 KB
testcase_16 AC 387 ms
13,552 KB
testcase_17 AC 384 ms
13,528 KB
testcase_18 AC 387 ms
13,656 KB
testcase_19 AC 383 ms
13,656 KB
testcase_20 AC 380 ms
13,652 KB
testcase_21 AC 441 ms
23,552 KB
testcase_22 AC 429 ms
23,608 KB
testcase_23 AC 434 ms
23,648 KB
testcase_24 AC 434 ms
23,552 KB
testcase_25 AC 436 ms
23,548 KB
testcase_26 AC 437 ms
23,424 KB
testcase_27 AC 448 ms
23,552 KB
testcase_28 AC 459 ms
23,680 KB
testcase_29 AC 433 ms
23,552 KB
testcase_30 AC 447 ms
23,552 KB
testcase_31 AC 209 ms
23,552 KB
testcase_32 AC 219 ms
23,552 KB
testcase_33 AC 216 ms
23,552 KB
testcase_34 AC 230 ms
23,552 KB
testcase_35 AC 234 ms
23,680 KB
testcase_36 AC 239 ms
23,576 KB
testcase_37 AC 18 ms
5,248 KB
testcase_38 AC 367 ms
13,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef MY_DEBUG
#define dbg(...) debug_out(__VA_ARGS__)
#define dbgn(var) debug_out(#var, "=", var)
#else
#define dbg(...)
#define dbgn(...)
#endif
void debug_out();
template <class Head, class... Tail> void debug_out(Head, Tail...);
template <class T> bool chmax(T&, const T&);
template <class T> bool chmin(T&, const T&);
template <class T> T pwr(T, ll);
template <class T> T squ(T x) { return x * x; }
ll fact(ll);
ll comb(ll, ll);
ll ctoll(char);
char lltoc(ll);
bool flg(ll b, ll i) { return ((b) >> (i)) & 1LL; }  // flg(0b010, 1LL) -> true
const ll LINF = (ll)1e18 + 7;
const double EPS = 1e-9;
const int MAX_DUBUG_SIZE = 10;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set =
    tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve([[maybe_unused]] int test) {
    ll n;
    cin >> n;
    vector<bool> x(n);
    for (ll i = 0; i < n; i++) {
        string tmp;
        cin >> tmp;
        if (tmp == "True") {
            x[i] = true;
        }
        else {
            x[i] = false;
        }
    }
    vector<string> y(n - 1);
    for (ll i = 0; i < n - 1; i++) {
        cin >> y[i];
    }
    vector<ll> s(n - 1);
    for (ll i = 0; i < n - 1; i++) {
        cin >> s[i];
        s[i]--;
    }

    ordered_set<ll> st;
    for (ll i = 0; i < n; i++) {
        st.insert(i);
    }

    bool ans = false;

    for (ll i = 0; i < n - 1; i++) {
        dbg(x);
        ll s_now = *st.find_by_order(s[i]);
        ll s_next = *st.find_by_order(s[i] + 1);
        auto s_next_itr = st.find_by_order(s[i] + 1);

        dbg(s_now, s_next);
        if (y[s_now] == "and") {
            x[s_next] = (x[s_now] && x[s_next]);
        }
        else if (y[s_now] == "or") {
            x[s_next] = (x[s_now] || x[s_next]);
        }
        else if (y[s_now] == "xor") {
            x[s_next] = (x[s_now] ^ x[s_next]);
        }
        else {
            x[s_next] = ((!x[s_now]) || x[s_next]);
        }

        st.erase(s_now);

        ans = x[s_next];
    }

    dbg(x);

    cout << (ans ? "True" : "False") << endl;
}

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12);

    int testcase_size = 1;
    cin >> testcase_size;

    for (int _t = 0; _t < testcase_size; _t++) {
        solve(_t);
    }
}

/*



























-----------------------------------MY_FUNCTIONS------------------------------------ */
template <class First, class Second> ostream& operator<<(ostream& os, const pair<First, Second>& pp) {
    return os << "{" << pp.first << "," << pp.second << "}";
}

template <class T> ostream& operator<<(ostream& os, const vector<T>& V) {
    if (V.empty()) return os << "[]";
    os << "[";
    for (ll i = 0; i < (ll)V.size(); i++) {
        os << V[i] << (i == int(V.size() - 1) ? "]" : ",");
    }
    return os;
}

template <class T> ostream& operator<<(ostream& os, const vector<vector<T>>& VV) {
    if (VV.empty()) return os << "[[]]";
    os << "[\n";
    for (auto&& V : VV) {
        os << V << "\n";
    }
    os << "]";
    return os;
}

template <class T> ostream& operator<<(ostream& os, const vector<vector<vector<T>>>& VVV) {
    if (VVV.empty()) return os << "[[[]]]";
    os << "["
       << "\n";
    int cnt = 0;
    for (auto&& VV : VVV) {
        os << cnt++ << VV << "\n\n";
    }
    os << "]";
    return os;
}

template <class T> ostream& operator<<(ostream& os, const set<T>& SS) {
    if (SS.empty()) return os << "[]";
    os << "[";
    auto ii = SS.begin();
    for (; ii != SS.end(); ii++) os << *ii << (ii == prev(SS.end()) ? "]" : ",");
    return os;
}

template <class Key, class Tp> ostream& operator<<(ostream& os, const map<Key, Tp>& MM) {
    if (MM.empty()) return os << "[{:}]";
    os << "[";
    auto ii = MM.begin();
    for (; ii != MM.end(); ii++)
        os << "{" << ii->first << ":" << ii->second << "}" << (ii == prev(MM.end()) ? "]" : ",");
    return os;
}

void debug_out() { cerr << endl; }

void debug_out_vl(vector<ll> V) {
    const int MAX_SIZE = min((int)V.size(), MAX_DUBUG_SIZE);

    cerr << "\033[33m";
    if (V.empty()) {
        cerr << "[]" << endl;
        return;
    }
    cerr << "[";
    for (int i = 0; i < MAX_SIZE; i++) {
        if (V[i] == LINF)
            cerr << "INF";
        else
            cerr << V[i];

        if (i == (int)V.size() - 1)
            cerr << "]\n";
        else if (i == MAX_DUBUG_SIZE - 1)
            cerr << ",...\n";
        else
            cerr << ",";
    }
    return;
}

void debug_out_vvl(vector<vector<ll>> VV) {
    cerr << "\033[33m";
    if (VV.empty()) {
        cerr << "[[]]" << endl;
        return;
    }
    cerr << "[\n";

    int MAX_ROW = min((int)VV.size(), MAX_DUBUG_SIZE);
    for (int i = 0; i < MAX_ROW; i++) {
        const int MAX_COLUMN = min((int)VV[i].size(), MAX_DUBUG_SIZE);
        if (VV[i].empty()) {
            cerr << "[]" << endl;
            continue;
        }
        cerr << "[";
        for (int j = 0; j < MAX_COLUMN; j++) {
            if (VV[i][j] == LINF)
                cerr << "INF";
            else
                cerr << VV[i][j];

            if (j == (int)VV[i].size() - 1)
                cerr << "]\n";
            else if (j == MAX_DUBUG_SIZE - 1)
                cerr << ",...\n";
            else
                cerr << ",";
        }

        if (i != (int)VV.size() - 1 and i == MAX_DUBUG_SIZE - 1) {
            cerr << ":\n:\033[m\n";
            return;
        }
    }

    cerr << "]\033[m\n";
    return;
}

template <class Head, class... Tail> void debug_out(Head H, Tail... T) {
    if constexpr (std::is_same_v<Head, vector<ll>>) {
        debug_out_vl(H);
    }
    else if constexpr (std::is_same_v<Head, vector<vector<ll>>>) {
        debug_out_vvl(H);
    }
    else {
        cerr << "\033[33m" << H << "\033[m ";
    }

    debug_out(T...);
}

template <class T> bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T> bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template <class T> T pwr(T x, ll n) {
    T res = 1;
    for (int i = 0; i < n; i++) {
        res *= x;
    }
    return res;
}

ll fact(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) res *= i;
    return res;
}

ll comb(ll n, ll r) {  // comb(60, 30)までオーバーフローなし
    ll res = 1;
    for (int i = 1; i <= r; i++) {
        res *= n--;
        res /= i;
    }
    return res;
}

ll ctoll(char c) {
    if (c < '0' or '9' < c) {
        cerr << "\n\033[33m ctoll に '0'~'9' 以外の文字が入りました.\033[m\n" << endl;
    }
    return ll(c - '0');
}

char lltoc(ll n) {
    if (n < 0 or 9 < n) {
        cerr << "\n\033[33m lltoc に 0 ~ 9 以外の数字が入りました.\033[m\n" << endl;
    }
    return char(n + '0');
}
0