Submission #28508569


Source Code Expand

#include <bits/stdc++.h>
#define ENABLE_AVX2

using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;

class Range {
    struct Iter {
        int itr;
        constexpr Iter(const int pos) noexcept : itr(pos) {}
        constexpr void operator++() noexcept { ++itr; }
        constexpr bool operator!=(const Iter& other) const noexcept { return itr != other.itr; }
        constexpr int operator*() const noexcept { return itr; }
    };
    const Iter first, last;

  public:
    explicit constexpr Range(const int first, const int last) noexcept : first(first), last(std::max(first, last)) {}
    constexpr Iter begin() const noexcept { return first; }
    constexpr Iter end() const noexcept { return last; }
};

constexpr Range rep(const int l, const int r) noexcept { return Range(l, r); }
constexpr Range rep(const int n) noexcept { return Range(0, n); }

template <class F> struct RecursiveLambda : private F {
    explicit constexpr RecursiveLambda(F&& f) : F(std::forward<F>(f)) {}
    template <class... Args> constexpr decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class F> constexpr decltype(auto) rec_lambda(F&& f) { return RecursiveLambda<F>(std::forward<F>(f)); }

using std::array;
using std::pair;
using std::tuple;
using std::vector;

constexpr int pow4(const int e) { return 1 << (2 * e); }

int read() {
    std::string s;
    std::cin >> s;
    int ret = 0;
    for (const char c : s) {
        ret *= 4;
        if (c == 'R') ret += 1;
        if (c == 'S') ret += 2;
    }
    return ret;
}

void main_() {
    int K, N, M;
    std::cin >> K >> N >> M;
    const int L = pow4(K);
    vector<i64> A(L), B(L);
    for (const int i : rep(N)) {
        A[read()] += 1;
    }
    for (const int i : rep(M)) {
        B[read()] += 1;
    }
    for (const int d : rep(K)) {
        const int j = pow4(d);
        for (const int i : rep(L)) {
            if ((i / j) % 4 == 3) {
                A[i] += A[i - 1 * j] + A[i - 2 * j] + A[i - 3 * j];
                B[i] += B[i - 1 * j] + B[i - 2 * j] + B[i - 3 * j];
            }
        }
    }
    for (const int i : rep(L)) {
        A[i] *= B[i];
    }
    for (const int d : rep(K)) {
        const int j = pow4(d);
        for (const int i : rep(L)) {
            if ((i / j) % 4 == 3) {
                A[i] -= A[i - 1 * j] + A[i - 2 * j] + A[i - 3 * j];
            }
        }
    }
    for (const int d : rep(K)) {
        const int j = pow4(d);
        for (const int i : rep(L)) {
            if ((i / j) % 4 == 3) {
                const i64 a = A[i - 3 * j], b = A[i - 2 * j], c = A[i - 1 * j];
                A[i - 3 * j] = c + a + A[i];
                A[i - 2 * j] = a + b + A[i];
                A[i - 1 * j] = b + c + A[i];
            }
        }
    }
    rec_lambda([&](auto&& dfs, const int k, const int x) -> void {
        if (k == K) {
            std::cout << (i64)N * M - A[x] << '\n';
        } else {
            for (const int i : rep(3)) {
                dfs(k + 1, 4 * x + i);
            }
        }
    })(0, 0);
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    main_();
    return 0;
}

Submission Info

Submission Time
Task F - Takahashi The Strongest
User KoD
Language C++ (GCC 9.2.1)
Score 900
Code Size 3320 Byte
Status AC
Exec Time 2282 ms
Memory 270016 KiB

Compile Error

./Main.cpp: In function ‘void main_()’:
./Main.cpp:63:20: warning: unused variable ‘i’ [-Wunused-variable]
   63 |     for (const int i : rep(N)) {
      |                    ^
./Main.cpp:66:20: warning: unused variable ‘i’ [-Wunused-variable]
   66 |     for (const int i : rep(M)) {
      |                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 2
AC × 29
Set Name Test Cases
Sample sample1.txt, sample2.txt
All full.txt, half1.txt, half10.txt, half11.txt, half12.txt, half2.txt, half3.txt, half4.txt, half5.txt, half6.txt, half7.txt, half8.txt, half9.txt, many10.txt, many11.txt, many12.txt, rnd1.txt, rnd11.txt, rnd12.txt, rnd12_2.txt, rnd12_3.txt, rnd12_4.txt, rnd12_5.txt, rnd3.txt, rnd5.txt, rnd7.txt, rnd9.txt, sample1.txt, sample2.txt
Case Name Status Exec Time Memory
full.txt AC 2261 ms 270016 KiB
half1.txt AC 5 ms 3480 KiB
half10.txt AC 127 ms 19304 KiB
half11.txt AC 519 ms 68552 KiB
half12.txt AC 2191 ms 269492 KiB
half2.txt AC 6 ms 3480 KiB
half3.txt AC 2 ms 3448 KiB
half4.txt AC 2 ms 3572 KiB
half5.txt AC 4 ms 3480 KiB
half6.txt AC 9 ms 3468 KiB
half7.txt AC 6 ms 3400 KiB
half8.txt AC 14 ms 4052 KiB
half9.txt AC 41 ms 7224 KiB
many10.txt AC 134 ms 19428 KiB
many11.txt AC 538 ms 68584 KiB
many12.txt AC 2282 ms 269952 KiB
rnd1.txt AC 5 ms 3440 KiB
rnd11.txt AC 525 ms 68572 KiB
rnd12.txt AC 2162 ms 269452 KiB
rnd12_2.txt AC 2158 ms 268956 KiB
rnd12_3.txt AC 2206 ms 269516 KiB
rnd12_4.txt AC 2189 ms 269524 KiB
rnd12_5.txt AC 2178 ms 268892 KiB
rnd3.txt AC 6 ms 3508 KiB
rnd5.txt AC 3 ms 3520 KiB
rnd7.txt AC 6 ms 3556 KiB
rnd9.txt AC 43 ms 7252 KiB
sample1.txt AC 3 ms 3504 KiB
sample2.txt AC 2 ms 3564 KiB