結果
| 問題 | No.3735 Offbeat Permutation Tree |
| コンテスト | |
| ユーザー |
shinchan
|
| 提出日時 | 2026-09-19 17:15:15 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 181 ms / 2,000 ms |
| + 258µs | |
| コード長 | 4,916 bytes |
| 記録 | |
| コンパイル時間 | 2,302 ms |
| コンパイル使用メモリ | 359,500 KB |
| 実行使用メモリ | 7,804 KB |
| 最終ジャッジ日時 | 2026-09-19 17:15:33 |
| 合計ジャッジ時間 | 8,733 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb emplace_back
#define rep(i, n) for(int i=0;i<(n);i++)
#define foa(e, v) for(auto& e : v)
#define dout(a) cout<<fixed<<setprecision(10)<<a<<'\n';
#define Cout(a) cout<<a<<'\n';
using ll = long long;
using ld = long double;
using Int = __int128;
template <class T> using pqr = priority_queue<T, vector<T>, greater<T>>;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
bool compare = a < b;
if(compare) a = b;
return compare;
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
bool compare = a > b;
if(compare) a = b;
return compare;
}
template <typename T> inline T back(std::set<T> &s) {
return *s.rbegin();
}
template <typename T> inline T back(std::multiset<T> &s) {
return *s.rbegin();
}
template <typename T> inline T pop_back(std::set<T> &s) {
auto it = prev(s.end());
T val = *it;
s.erase(it);
return val;
}
template <typename T> inline T pop_back(std::multiset<T> &s) {
auto it = prev(s.end());
T val = *it;
s.erase(it);
return val;
}
const int dy[8] = {-1, 0, 0, 1, 1, -1, 1, -1};
const int dx[8] = {0, -1, 1, 0, -1, -1, 1, 1};
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (3LL << 59);
const int inf = 1 << 30;
const char br = '\n';
vector<tuple<int, int, int, int>> op;
vector<vector<int>> v4 = {
{0, 0, 0, 1},
{0, 0, 1, 0},
{0, 1, 1, 1},
{0, 2, 0, 3},
{0, 2, 1, 2},
{1, 2, 1, 3},
{2, 0, 2, 1},
{2, 0, 3, 0},
{3, 0, 3, 1},
{2, 2, 3, 2},
{3, 2, 3, 3},
{2, 3, 3, 3},
{1, 1, 1, 2},
{1, 1, 2, 1},
{1, 3, 2, 3}
};
vector<vector<int>> v5 = {
{0, 0, 0, 1},
{0, 0, 1, 0},
{0, 1, 1, 1},
{1, 1, 1, 2},
{0, 2, 1, 2},
{0, 2, 0, 3},
{0, 3, 1, 3},
{1, 3, 1, 4},
{0, 4, 1, 4},
{1, 2, 2, 2},
{2, 0, 2, 1},
{2, 2, 2, 3},
{2, 3, 2, 4},
{2, 0, 3, 0},
{2, 2, 3, 2},
{2, 3, 3, 3},
{2, 4, 3, 4},
{3, 1, 3, 2},
{3, 0, 4, 0},
{3, 1, 4, 1},
{3, 4, 4, 4},
{4, 0, 4, 1},
{4, 2, 4, 3},
{4, 3, 4, 4}
};
vector<vector<int>> v6 = {
{0, 0, 0, 1},
{0, 2, 0, 3},
{0, 3, 0, 4},
{0, 4, 0, 5},
{0, 0, 1, 0},
{0, 1, 1, 1},
{0, 3, 1, 3},
{0, 5, 1, 5},
{1, 1, 1, 2},
{1, 4, 1, 5},
{1, 0, 2, 0},
{1, 2, 2, 2},
{1, 3, 2, 3},
{2, 1, 2, 2},
{2, 3, 2, 4},
{2, 0, 3, 0},
{2, 1, 3, 1},
{2, 3, 3, 3},
{2, 4, 3, 4},
{2, 5, 3, 5},
{3, 1, 3, 2},
{3, 2, 4, 2},
{3, 3, 4, 3},
{3, 4, 4, 4},
{3, 5, 4, 5},
{4, 0, 4, 1},
{4, 2, 4, 3},
{4, 0, 5, 0},
{4, 2, 5, 2},
{4, 4, 5, 4},
{4, 5, 5, 5},
{5, 0, 5, 1},
{5, 1, 5, 2},
{5, 2, 5, 3},
{5, 4, 5, 5}
};
void calc(int n, int base) {
if(n == 3) {
op.pb(base + 0, base + 0, base + 0, base + 1);
op.pb(base + 0, base + 0, base + 1, base + 0);
op.pb(base - 1, base + 2, base + 0, base + 2);
op.pb(base + 0, base + 2, base + 1, base + 2);
op.pb(base + 1, base + 1, base + 1, base + 2);
op.pb(base + 1, base + 1, base + 2, base + 1);
op.pb(base + 2, base + 0, base + 2, base + 1);
op.pb(base + 2, base + 0, base + 3, base + 0);
} else if(n == 4) {
for(auto a : v4) op.pb(base + a[0], base + a[1], base + a[2], base + a[3]);
} else if(n == 5) {
for(auto a : v5) op.pb(base + a[0], base + a[1], base + a[2], base + a[3]);
} else if(n == 6) {
for(auto a : v6) op.pb(base + a[0], base + a[1], base + a[2], base + a[3]);
} else {
rep(i, n - 2) {
op.pb(base + 0, base + i, base + 0, base + i + 1);
op.pb(base + n - 1, base + i + 1, base + n - 1, base + i + 2);
}
rep(i, n - 1) {
op.pb(base + i, base + 0, base + i + 1, base + 0);
op.pb(base + i, base + n - 1, base + i + 1, base + n - 1);
}
rep(i, n - 3) {
op.pb(base + 1, base + i + 1, base + 1, base + i + 2);
op.pb(base + n - 2, base + i + 1, base + n - 2, base + i + 2);
}
for(int i = 0; i <= n - 4; i ++) {
op.pb(base + i, base + n - 2, base + i + 1, base + n - 2);
op.pb(base + i + 2, base + 1, base + i + 3, base + 1);
}
op.pb(base + 2, base + 1, base + 2, base + 2);
op.pb(base + n - 3, base + n - 3, base + n - 3, base + n - 2);
calc(n - 4, base + 2);
}
}
void solve() {
int n; cin >> n;
if(n <= 3) {
cout << -1 << endl;
return;
}
calc(n, 0);
// cout << op.size() << endl;
for(auto [a, b, c, d] : op) cout << a * n + b + 1 << " " << c * n + d + 1 << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int testcase = 1;
// cin >> testcase;
while(testcase --) solve();
return 0;
}
shinchan