結果

問題 No.3735 Offbeat Permutation Tree
コンテスト
ユーザー 👑 Nachia
提出日時 2026-09-19 14:17:06
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 23 ms / 2,000 ms
+ 359µs
コード長 2,043 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 657 ms
コンパイル使用メモリ 101,708 KB
実行使用メモリ 10,028 KB
最終ジャッジ日時 2026-09-19 14:17:17
合計ジャッジ時間 5,423 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
// disable assert
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }

V<string> f4 = {
  "###.###",
  "#.#...#",
  "#.#.###",
  "#...#..",
  "#####.#",
  "..#.#.#",
  "###.###"
};
V<string> f5 = {
  "#######.#",
  "#.....#.#",
  "#####.###",
  "#.....#.#",
  "#.###.#.#",
  "#...#.#.#",
  "#####.#.#",
  "........#",
  "#########"
};
V<string> f6 = {
  "#########.#",
  "#.......#.#",
  "#######.###",
  "..........#",
  "#######.###",
  "#.....#...#",
  "#####.###.#",
  "#.......#.#",
  "###.#####.#",
  "....#.....#",
  "###########"
};
V<string> ex = {
  "#.#.#",
  "....#",
  "#.###",
  "..#..",
  "#####"
};

V<string> G(ll N){
  V<string> ans(N*2-1, string(N*2-1, '.'));
  REP(i,N) REP(j,N) ans[i*2][j*2] = '#';
  while(N >= 7){
    REP(f,3) REP(j,N*2-5) ans[N*2-2-f*2][j] = '#';
    REP(f,3) REP(j,N*2-5) ans[j][N*2-2-f*2] = '#';
    ans[0][(N-2)*2+1] = ans[0][(N-3)*2+1] = '#';
    ans[(N-2)*2+1][0] = '#';
    ans[(N-3)*2-1][0] = '#';
    REP(i,5) REP(j,5) ans[N*2-6+i][N*2-6+j] = ex[i][j];
    N -= 3;
  }
  auto buf = f4;
  if(N == 5) buf = f5;
  if(N == 6) buf = f6;
  ll K = buf.size();
  REP(i,K) REP(j,K) ans[i][j] = buf[j][K-1-i];
  return ans;
}

void testcase(){
  ll N; cin >> N;
  if(N <= 3){ cout << "-1\n"; return; }
  auto ans = G(N);
  // for(auto& a : ans) cout << a << "\n";
  auto idx = [&](ll y, ll x){ return y*N+x +1; };
  REP(i,N) REP(j,N-1) if(ans[i*2][j*2+1] == '#'){ cout << idx(i,j) << " " << idx(i,j+1) << "\n"; }
  REP(i,N-1) REP(j,N) if(ans[i*2+1][j*2] == '#'){ cout << idx(i,j) << " " << idx(i+1,j) << "\n"; }
  // cout << endl;
}

int main(){
  cin.tie(0)->sync_with_stdio(0);
  testcase();
  return 0;
}
0