結果
| 問題 |
No.1717 Levi-Civita Triangle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-15 18:13:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 17 ms / 2,000 ms |
| コード長 | 4,667 bytes |
| コンパイル時間 | 7,031 ms |
| コンパイル使用メモリ | 354,228 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-07-15 18:13:13 |
| 合計ジャッジ時間 | 8,750 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
#define USE_ACLIBRARY 0
#if __has_include("all.hpp")
#include "all.hpp"
#else
#include <bits/extc++.h>
#if __has_include(<atcoder/all>) || USE_ACLIBRARY
#include <atcoder/all>
#endif
#endif
using ll = long long int;
using pll = std::pair<ll, ll>;
using pil = std::pair<int, ll>;
using pli = std::pair<ll, int>;
using pii = std::pair<int, int>;
using namespace std::literals;
template <class T>
bool chmin(T &x, const T &val) {
if (x > val) {
x = val;
return true;
} else {
return false;
}
}
template <class T>
bool chmax(T &x, const T &val) {
if (x < val) {
x = val;
return true;
} else {
return false;
}
}
ll isqrt(ll n) {
assert(n >= 0);
if (n == 0) return 0;
uint32_t c = (std::bit_width(uint64_t(n)) - 1) / 2;
ll a = 1;
ll d = 0;
for (int s = std::bit_width(c) - 1; s >= 0; s--) {
ll e = d;
d = c >> s;
a = (a << (d - e - 1)) + (n >> (2 * c - e - d + 1)) / a;
}
return a - (a * a > n);
}
#if __has_include(<atcoder/all>) || USE_ACLIBRARY
template <class mint, atcoder::internal::is_static_modint_t<mint> * = nullptr>
std::ostream &operator<<(std::ostream &os, const mint &v) {
return os << v.val();
}
template <class mint, atcoder::internal::is_static_modint_t<mint> * = nullptr>
std::istream &operator>>(std::istream &is, mint &v) {
int tmp;
is >> tmp;
v = tmp;
return is;
}
#endif
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
return is >> p.first >> p.second;
}
template <class... T>
std::istream &operator>>(std::istream &is, std::tuple<T...> &tpl) {
std::apply([&](auto &&...args) { (is >> ... >> args); }, tpl);
return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
for (T &x : v) is >> x;
return is;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
for (size_t i = 0; i < v.size(); i++)
os << v[i] << (i == v.size() - 1 ? "" : " ");
return os;
}
struct Initialization {
Initialization() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} initialization;
constexpr std::pair<int, int> dir[] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
template <typename T>
using infs = std::numeric_limits<T>;
template <typename T>
class factorials {
public:
static size_t n;
static std::vector<T> fact, inv_fact;
static void extend(size_t m) {
if (m <= n) return;
fact.resize(m + 1);
inv_fact.resize(m + 1);
for (size_t i = n + 1; i <= m; i++) fact[i] = fact[i - 1] * i;
inv_fact[m] = fact[m].inv();
for (size_t i = m; i > n + 1; i--) inv_fact[i - 1] = inv_fact[i] * i;
n = m;
}
static T inv(int k) {
extend(k);
return inv_fact[k];
}
static T get(int k) {
extend(k);
return fact[k];
}
static T perm(int n, int k) {
if (n < k) return 0;
if (k < 0) return 0;
extend(n);
return fact[n] * inv_fact[n - k];
}
static T choose(int n, int k) {
if (n < k) return 0;
if (k < 0) return 0;
extend(n);
return fact[n] * inv_fact[n - k] * inv_fact[k];
}
static T catalan(int n) { return get(2 * n) * inv(n + 1) * inv(n); }
};
template <typename T>
size_t factorials<T>::n = 0;
template <typename T>
std::vector<T> factorials<T>::fact = {1};
template <typename T>
std::vector<T> factorials<T>::inv_fact = {1};
#if __has_include(<atcoder/all>) || USE_ACLIBRARY
using mint = atcoder::modint998244353;
// using mint = atcoder::modint1000000007;
using fs = factorials<mint>;
#endif
template <typename T>
using pq_rev = std::priority_queue<T, std::vector<T>, std::greater<T>>;
namespace pbds = __gnu_pbds;
template <typename T>
using tree = pbds::tree<T, pbds::null_type, std::less<T>, pbds::rb_tree_tag,
pbds::tree_order_statistics_node_update>;
int main() {
int N;
std::cin >> N;
std::vector<int> A(2 * N + 1);
std::cin >> A;
auto f = [&](int i) {
using t = std::tuple<int, int, int>;
t a = {A[i], A[i + 1], A[i + 2]};
if (a == t{0, 1, 2} || a == t{1, 2, 0} || a == t{2, 0, 1}) {
return 1;
} else if (a == t{0, 2, 1} || a == t{1, 0, 2} || a == t{2, 1, 0}) {
return 2;
} else {
return 0;
}
};
std::vector<int> Q(A.size() - 2);
for (int k = 0; k < A.size() - 2; k++) {
Q[k] = f(k);
}
bool isok = true;
for (int i = 0; i < N; i++) {
if (i & 1) {
isok = isok && (Q[i] == 0);
} else if (i == 0) {
} else {
isok = isok && Q[i] != 0 && Q[i] != Q[i - 2];
}
if (!isok) break;
}
if (isok) {
std::cout << Q.back() << "\n";
} else {
std::cout << 0 << "\n";
}
}