結果
| 問題 | No.3735 Offbeat Permutation Tree |
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2026-08-16 00:30:13 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 37 ms / 2,000 ms |
| + 707µs | |
| コード長 | 1,570 bytes |
| 記録 | |
| コンパイル時間 | 2,447 ms |
| コンパイル使用メモリ | 345,564 KB |
| 実行使用メモリ | 7,796 KB |
| 最終ジャッジ日時 | 2026-09-19 12:38:48 |
| 合計ジャッジ時間 | 7,134 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using Edge = array<int, 4>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
if (N <= 3) {
cout << -1 << '\n';
return 0;
}
int n = N % 2 ? 5 : 4;
vector<string> h, v;
if (n == 4) {
h = {"#.#", "##.", ".##", "#.#"};
v = {"#.##", ".#..", "##.#"};
} else {
h = {"####", "#.##", "###.", ".###", "####"};
v = {".#..#", "#...#", "#...#", "#...."};
}
vector<Edge> ans;
auto add = [&](int r, int c, int nr, int nc) {
ans.push_back({r, c, nr, nc});
};
for (int r = 0; r < n; ++r)
for (int c = 0; c + 1 < n; ++c)
if (h[r][c] == '#') add(r, c, r, c + 1);
for (int r = 0; r + 1 < n; ++r)
for (int c = 0; c < n; ++c)
if (v[r][c] == '#') add(r, c, r + 1, c);
while (n < N) {
for (auto& e : ans) {
e[0] += 2;
e[2] += 2;
e[1] = n + 1 - e[1];
e[3] = n + 1 - e[3];
}
n += 2;
for (int r = 0; r + 1 < n; ++r) add(r, 0, r + 1, 0);
add(n - 1, 0, n - 1, 1);
for (int r = n - 1; r > 2; --r) add(r, 1, r - 1, 1);
add(2, 1, 2, 2);
add(1, 1, 0, 1);
for (int c = 1; c + 1 < n; ++c) add(0, c, 0, c + 1);
add(0, n - 1, 1, n - 1);
for (int c = n - 1; c > 2; --c) add(1, c, 1, c - 1);
add(1, 2, 2, 2);
}
for (auto [r, c, nr, nc] : ans)
cout << r * N + c + 1 << ' ' << nr * N + nc + 1 << '\n';
}