結果
| 問題 |
No.1754 T-block Tiling
|
| コンテスト | |
| ユーザー |
toyama
|
| 提出日時 | 2021-11-20 13:34:10 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 3,489 bytes |
| コンパイル時間 | 9,879 ms |
| コンパイル使用メモリ | 274,580 KB |
| 最終ジャッジ日時 | 2025-01-25 21:35:57 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 |
ソースコード
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#ifndef MODINT_HPP
#define MODINT_HPP
#include <iostream>
template <uint64_t p>
struct ModInt {
using u64 = unsigned long long;
using i64 = long long;
u64 d;
ModInt(const i64 x = 0) : d((x % p + p) % p){};
ModInt(const ModInt &) = default;
ModInt operator+(ModInt x) const {
if (d + x.d >= p)
return ModInt(d + x.d - p);
else
return ModInt(d + x.d);
};
ModInt operator-(ModInt x) const {
if (d - x.d < 0)
return ModInt(d - x.d + p);
else
return ModInt(d - x.d);
};
ModInt operator*(ModInt x) const { return ModInt(d * x.d); }
ModInt operator/(ModInt x) const {
ModInt inv = 1;
u64 exp = p - 2;
while (exp) {
if (exp & 1) inv *= x;
x *= x;
exp >>= 1;
}
return ModInt(d * inv.d);
}
ModInt operator+() { return *this; };
ModInt operator-() { return ModInt(-d); };
ModInt &operator+=(ModInt x) { return *this = *this + x; };
ModInt &operator-=(ModInt x) { return *this = *this - x; };
ModInt &operator*=(ModInt x) { return *this = *this * x; };
ModInt &operator/=(ModInt x) { return *this = *this / x; };
ModInt operator+(const i64 x) const { return *this + ModInt(x); };
ModInt operator-(const i64 x) const { return *this - ModInt(x); };
ModInt operator*(const i64 x) const { return *this * ModInt(x); };
ModInt operator/(const i64 x) const { return *this / ModInt(x); };
ModInt operator+=(const i64 x) { return *this = *this + x; };
ModInt operator-=(const i64 x) { return *this = *this - x; };
ModInt operator*=(const i64 x) { return *this = *this * x; };
ModInt operator/=(const i64 x) { return *this = *this / x; };
};
template <uint64_t p>
ModInt<p> operator+(const long long x, const ModInt<p> y) {
return ModInt<p>(x) + y;
};
template <uint64_t p>
ModInt<p> operator-(const long long x, const ModInt<p> y) {
return ModInt<p>(x) - y;
};
template <uint64_t p>
ModInt<p> operator*(const long long x, const ModInt<p> y) {
return ModInt<p>(x) * y;
};
template <uint64_t p>
ModInt<p> operator/(const long long x, const ModInt<p> y) {
return ModInt<p>(x) / y;
};
template <uint64_t p>
std::ostream &operator<<(std::ostream &stream, const ModInt<p> mi) {
return stream << mi.d;
};
template <uint64_t p>
std::istream &operator>>(std::istream &stream, ModInt<p> &mi) {
long long a;
stream >> a;
mi = ModInt<p>(a);
return stream;
};
#endif
#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, A, B) _rep3(Itr, A, B, 1)
#define _rep3(Itr, A, B, S) for(i64 (Itr) = A; (Itr) < B; (Itr) += S)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#include <bits/stdc++.h>
using i64 = long long;
using namespace std;
using M = ModInt<998244353>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
i64 t;
cin >> t;
rep(_, t) {
i64 n;
cin >> n;
vector<M> dp(n);
vector<bool> is_null(n, true);
auto dfs = [&](int i, auto &&f) -> M {
if (i == n) return 1;
if (!is_null[i]) return dp[i];
is_null[i] = false;
rep(j, i + 1, n + 1) {
dp[i] += 2 * f(j, f);
}
return dp[i];
};
cout << dfs(0, dfs) << '\n';
}
return 0;
};
toyama