Submission #744291

#TimeUsernameProblemLanguageResultExecution timeMemory
744291GrindMachineCrossing (JOI21_crossing)C++17
26 / 100
7013 ms4716 KiB
// Om Namah Shivaya

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a, b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a, b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*



*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

string f(string s1, string s2) {
    string s3 = "";
    rep(i, sz(s1)) {
        if (s1[i] == s2[i]) {
            s3.pb(s1[i]);
        }
        else {
            string joi = "JOI";
            for (auto ch : joi) {
                if (s1[i] != ch and s2[i] != ch) {
                    s3.pb(ch);
                }
            }
        }
    }

    return s3;
}

set<string> st;
string s1, s2, s3;

void go(string s) {
    if (st.count(s)) return;
    st.insert(s);

    go(f(s, s1));
    go(f(s, s2));
    go(f(s, s3));
}

void solve(int test_case)
{
    ll n; cin >> n;
    cin >> s1 >> s2 >> s3;

    for (auto s : {s1, s2, s3}) {
        go(s);
    }

    assert(sz(st) <= 9);

    auto ok = [&](string t) {
        trav(s, st) {
            if (s == t) return true;
        }

        return false;
    };

    ll q; cin >> q;
    string t; cin >> t;
    if (ok(t)) yes;
    else no;

    while (q--) {
        ll l, r; cin >> l >> r;
        char ch; cin >> ch;
        for (int i = l - 1; i < r; ++i) {
            t[i] = ch;
        }

        if (ok(t)) yes;
        else no;
    }
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'std::string f(std::string, std::string)':
Main.cpp:30:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 | #define rep(i, n) for(int i = 0; i < n; ++i)
      |                                    ^
Main.cpp:64:5: note: in expansion of macro 'rep'
   64 |     rep(i, sz(s1)) {
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...