結果
| 問題 | No.3724 Domination |
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2026-09-19 13:49:47 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 4,177 bytes |
| 記録 | |
| コンパイル時間 | 2,243 ms |
| コンパイル使用メモリ | 351,480 KB |
| 実行使用メモリ | 11,392 KB |
| 最終ジャッジ日時 | 2026-09-19 13:50:07 |
| 合計ジャッジ時間 | 13,778 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge5_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点 | 20 % | AC * 7 WA * 1 |
| 満点 | 80 % | AC * 51 WA * 1 |
| 合計 | 2.5 * 0% = 0 点 |
ソースコード
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
void Solve() {
int n;
IN(n);
vector<int> R(n), C(n);
IN(R, C);
vector ans(n, vector<int>(n));
for (int i : Rep(0, n))
ranges::fill(ans[i], R[i]);
vector<int> from(n);
for (int j : Rep(0, n))
from[j] = int(ranges::find(R, C[j]) - R.begin());
vector<int> to;
to.reserve(n);
vector cnt(n, vector<int>(n));
for (int i : Rep(0, n))
cnt[i][i] = n;
bool res = Fix([&](auto self) -> bool {
if (Len(to) == n)
return true;
int j = Len(to);
for (int x : Rep(0, n)) {
if (x == from[j])
continue;
{
--cnt[x][x];
++cnt[x][from[j]];
int tmp = cnt[x][x];
cnt[x][x] = 0;
bool ok = ranges::max(cnt[x]) < tmp;
cnt[x][x] = tmp;
if (!ok) {
--cnt[x][from[j]];
++cnt[x][x];
continue;
}
}
to.push_back(x);
if (self())
return true;
to.pop_back();
--cnt[x][from[j]];
++cnt[x][x];
}
return false;
})();
if (res) {
for (int j : Rep(0, n))
ans[to[j]][j] = ans[from[j]][j];
ranges::for_each(ans, LIFT(OUT));
} else {
OUT(-1);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
IN(t);
while (t--) {
Solve();
}
}
#elif __INCLUDE_LEVEL__ == 1
#include <bits/stdc++.h>
template <class F>
class Fix {
public:
explicit Fix(F f) : f_(std::move(f)) {}
template <class... Ts>
decltype(auto) operator()(Ts&&... xs) {
return f_(std::ref(*this), std::forward<Ts>(xs)...);
}
template <class... Ts>
decltype(auto) operator()(Ts&&... xs) const {
return f_(std::ref(*this), std::forward<Ts>(xs)...);
}
private:
F f_;
};
template <class T>
concept MyRange =
std::ranges::range<T> &&
!std::convertible_to<T, std::string_view> &&
!std::convertible_to<T, std::filesystem::path>;
template <class T>
concept MyTuple = std::__is_tuple_like<T>::value && !MyRange<T>;
namespace std {
istream& operator>>(istream& is, MyRange auto&& r) {
for (auto&& e : r) {
is >> e;
}
return is;
}
istream& operator>>(istream& is, MyTuple auto&& t) {
apply([&](auto&... xs) { (is >> ... >> xs); }, t);
return is;
}
ostream& operator<<(ostream& os, MyRange auto&& r) {
auto sep = "";
for (auto&& e : r) {
os << exchange(sep, " ") << forward<decltype(e)>(e);
}
return os;
}
ostream& operator<<(ostream& os, MyTuple auto&& t) {
auto sep = "";
apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
return os;
}
} // namespace std
template <class T>
class OneBased {
public:
explicit OneBased(T&& x) : ref_(std::forward<T>(x)) {}
template <class... Ts>
requires(sizeof...(Ts) > 1)
OneBased(Ts&&... xs) : ref_(std::forward_as_tuple(std::forward<Ts>(xs)...)) {}
friend std::istream& operator>>(std::istream& is, OneBased x) {
if constexpr (MyRange<T>) {
for (auto&& e : x.ref_) {
is >> ::OneBased(e);
}
} else if constexpr (MyTuple<T>) {
std::apply([&](auto&... xs) { (is >> ... >> ::OneBased(xs)); }, x.ref_);
} else {
is >> x.ref_;
--x.ref_;
}
return is;
}
friend std::ostream& operator<<(std::ostream& os, OneBased x) {
if constexpr (MyRange<T>) {
auto f = [](auto&& e) { return ::OneBased(std::forward<decltype(e)>(e)); };
os << (x.ref_ | std::views::transform(f));
} else if constexpr (MyTuple<T>) {
std::apply([&](auto&... xs) { os << std::tuple(::OneBased(xs)...); }, x.ref_);
} else {
os << ++x.ref_;
--x.ref_;
}
return os;
}
private:
T ref_;
};
template <class T>
OneBased(T&&) -> OneBased<T>;
template <class... Ts>
OneBased(Ts&&...) -> OneBased<std::tuple<Ts...>>;
using namespace std;
#define LIFT(f) ([&](auto&&... xs) -> decltype(auto) { return f(forward<decltype(xs)>(xs)...); })
#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define Len(r) int(size(r))
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')
#endif // __INCLUDE_LEVEL__ == 1
risujiroh