結果

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

ソースコード

diff #
raw source code

//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i=0;i<(ll)n;i++)
#define rrep(i,n) for (ll i=(n)-1;i>=(ll)0;i--)
#define loop(i,m,n) for(ll i=m;i<=(ll)n;i++)
#define rloop(i,m,n) for(ll i=m;i>=(ll)n;i--)
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vdbg(a) rep(ii,a.size()){cout<<a[ii]<<" ";}cout<<endl;
#define vpdbg(a) rep(ii,a.size()){cout<<"{"<<a[ii].first<<","<<a[ii].second<<"} ";}cout<<endl;
#define vvdbg(a) rep(ii,a.size()){rep(jj,a[ii].size()){cout<<a[ii][jj]<<" ";}cout<<endl;}
#define setdbg(a) for(const auto & ii:a){cout<<ii<<" ";}cout<<endl;
#define inf 4000000000000000000LL
#define mod 998244353LL
//#define mod 1000000007LL
#define eps 0.000000001
#define circlepi 3.14159265358979323846
random_device rnd;// 非決定的な乱数生成器
mt19937 mt(rnd());// メルセンヌ・ツイスタの32ビット版、引数は初期シード

//#include<boost/multiprecision/cpp_int.hpp>
//#define bbi boost::multiprecision::cpp_int
//#include<atcoder/lazysegtree>


//整数同士の累乗の計算をする。
ll power(ll A, ll B) {
	ll result = 1;
	for (ll i=0;i<B;i++){
		result *= A;
	}
	return result;
}

// nのk乗をmodで割った余りを計算
ll power_mod(ll n, ll k){
	n%=mod;
	ll ans = 1;
	while (k > 0){
		if ((k&1) ==1)ans=(ans*n)%mod;
		n=n*n%mod;
		k >>= 1;
	}
	return ans;
}

//受け取った2次元文字の外側に、文字pをコーティングする。
vector<string> pad(vector<string> &s,char p){
	ll h=s.size();
	ll w=s[0].size();
	vector<string> res(h+2,string(w+2,p));
	rep(i,h)rep(j,w)res[i+1][j+1]=s[i][j];
	return res;
}

// Union-Find
struct UnionFind {
	vector<int> par, siz;
	UnionFind(int n) : par(n, -1) , siz(n, 1) { }
	// 根を求める
	int root(int x) {
		if (par[x] == -1) return x;
		else return par[x] = root(par[x]);
	}
	// x と y が同じグループに属するかどうか (根が一致するかどうか)
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	// x を含むグループと y を含むグループとを併合する
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return false; 
		if (siz[x] < siz[y]) swap(x, y);
		par[y] = x;
		siz[x] += siz[y];
		return true;
	}
	// x を含むグループのサイズ
	int size(int x) {
		return siz[root(x)];
	}
};


//グリッド問題等用
vl dx={1,0,-1,0};
vl dy={0,1,0,-1};


//メイン
int main(){
	ll n;
	cin>>n;
	if(n<=3){
		cout<<-1<<endl;
		return 0;
	}
	vvl g;
	ll nown;
	if(n%2==0){
		g.push_back({0,0,0,1});
		g.push_back({0,2,0,3});
		g.push_back({1,1,1,2});
		g.push_back({1,2,1,3});
		g.push_back({2,0,2,1});
		g.push_back({2,2,2,3});
		g.push_back({3,0,3,1});
		g.push_back({3,1,3,2});
		g.push_back({0,0,1,0});
		g.push_back({2,0,3,0});
		g.push_back({0,1,1,1});
		g.push_back({1,2,2,2});
		g.push_back({2,2,3,2});
		g.push_back({0,3,1,3});
		g.push_back({2,3,3,3});
		nown=4;
	}else{
		g.push_back({0,0,1,0});
		g.push_back({1,0,2,0});
		g.push_back({3,0,4,0});
		g.push_back({0,1,1,1});
		g.push_back({2,1,3,1});
		g.push_back({0,2,1,2});
		g.push_back({1,2,2,2});
		g.push_back({1,3,2,3});
		g.push_back({3,3,4,3});
		g.push_back({0,4,1,4});
		g.push_back({1,4,2,4});
		g.push_back({2,4,3,4});
		g.push_back({3,4,4,4});
		g.push_back({0,1,0,2});
		g.push_back({0,2,0,3});
		g.push_back({0,3,0,4});
		g.push_back({1,2,1,3});
		g.push_back({2,0,2,1});
		g.push_back({2,1,2,2});
		g.push_back({3,0,3,1});
		g.push_back({3,2,3,3});
		g.push_back({4,0,4,1});
		g.push_back({4,1,4,2});
		g.push_back({4,2,4,3});
		nown=5;
	}

	while(nown<n){
		g.push_back({nown-1,nown-1,nown-1,nown});

		g.push_back({nown-2,nown-1,nown-2,nown});
		rep(i,nown-2){
			g.push_back({i,nown,i+1,nown});
		}
		g.push_back({0,nown,0,nown+1});
		rep(i,nown){
			g.push_back({i,nown+1,i+1,nown+1});
		}
		g.push_back({nown,nown,nown,nown+1});
		g.push_back({nown,nown,nown+1,nown});
		g.push_back({nown+1,nown,nown+1,nown+1});

		g.push_back({nown-1,nown-2,nown,nown-2});
		rep(i,nown-2){
			g.push_back({nown,i,nown,i+1});
		}
		g.push_back({nown,0,nown+1,0});
		rep(i,nown-1){
			g.push_back({nown+1,i,nown+1,i+1});
		}
		g.push_back({nown,nown-1,nown+1,nown-1});
		nown+=2;
	}

	rep(i,g.size()){
		vl tmp=g[i];
		ll fir=tmp[0]*n+tmp[1]+1;
		ll sec=tmp[2]*n+tmp[3]+1;

		cout<<fir<<" "<<sec<<endl;
	}
}
0