Submission #69914352


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)

template <class T> bool chmin(T& x, T y) {
	return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
	return x < y ? (x = y, true) : false;
}

struct io_setup {
	io_setup() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} io_setup;

using mint = atcoder::modint998244353;

void solve() {
	int n;
	cin >> n;
	if (n < 6) {
		cout << "-1\n";
		return;
	}
	if (n == 8) {
		vector<pair<int, int>> ans;
		ans.push_back({1, 2});
		ans.push_back({1, 4});
		ans.push_back({1, 6});
		ans.push_back({2, 3});
		ans.push_back({2, 5});
		ans.push_back({3, 4});
		ans.push_back({3, 8});
		ans.push_back({4, 7});
		ans.push_back({5, 6});
		ans.push_back({5, 8});
		ans.push_back({6, 7});
		ans.push_back({7, 8});
		cout << ans.size() << '\n';
		for (auto [x, y] : ans) cout << x << ' ' << y << '\n';
		return;
	}
	if (n == 9) {
		vector<pair<int, int>> ans;
		ans.push_back({1, 2});
		ans.push_back({1, 4});
		ans.push_back({1, 6});
		ans.push_back({2, 3});
		ans.push_back({2, 5});
		ans.push_back({3, 4});
		ans.push_back({3, 8});
		ans.push_back({4, 7});
		ans.push_back({5, 6});
		ans.push_back({5, 8});
		ans.push_back({6, 7});
		ans.push_back({7, 8});

		ans.push_back({1, 9});
		ans.push_back({3, 9});
		ans.push_back({5, 9});
		ans.push_back({7, 9});
		cout << ans.size() << '\n';
		for (auto [x, y] : ans) cout << x << ' ' << y << '\n';
		return;
	}
	vector<pair<int, int>> ans;
	vector<int> v(n);
	if (n % 4 == 3) {
		n--;
		int m = (n - 2) / 2;
		rep(i, 0, n) {
			for (int j = 1; j < m; j += 2) {
				ans.push_back({i, (i + j) % n});
			}
		}
		rep(i, 0, n) {
			if (i & 1) ans.push_back({i, n});
		}
		rep(i, 0, n / 2) v[i] = i + 1;
		rep(i, n / 2, n) v[i] = n + n / 2 - i;
		v[n] = n + 1;
	} else if (n % 4 == 1) {
		n--;
		int n1 = n - 6, n2 = 6;
		{
			int m = (n1 - 2) / 2;
			rep(i, 0, n1) {
				for (int j = 1; j < m; j += 2) {
					ans.push_back({i, (i + j) % n1});
				}
			}
			rep(i, 0, n1 / 2) v[i] = i + 1;
			rep(i, n1 / 2, n1) v[i] = n + n1 / 2 - i;
		}
		{
			int m = (n2 - 2) / 2;
			rep(i, 0, n2) {
				for (int j = 1; j < m; j += 2) {
					ans.push_back({n1 + i, n1 + (i + j) % n2});
				}
			}
			rep(i, 0, n2 / 2) v[n1 + i] = i + 1 + n1 / 2;
			rep(i, n2 / 2, n2) v[n1 + i] = n - n1 / 2 + n2 / 2 - i;
		}
		rep(i, 0, n1) {
			int t = i & 1;
			rep(j, 0, 3) {
				ans.push_back({i, n1 + j * 2 + t});
			}
		}
		rep(i, 0, n) {
			if (i & 1) ans.push_back({i, n});
		}
		v[n] = n + 1;
	} else if (n % 4 == 2) {
		int m = (n - 2) / 2;
		rep(i, 0, n) {
			for (int j = 1; j < m; j += 2) {
				ans.push_back({i, (i + j) % n});
			}
		}
		rep(i, 0, n / 2) v[i] = i + 1;
		rep(i, n / 2, n) v[i] = n + n / 2 - i;
	} else {
		int n1 = n - 6, n2 = 6;
		{
			int m = (n1 - 2) / 2;
			rep(i, 0, n1) {
				for (int j = 1; j < m; j += 2) {
					ans.push_back({i, (i + j) % n1});
				}
			}
			rep(i, 0, n1 / 2) v[i] = i + 1;
			rep(i, n1 / 2, n1) v[i] = n + n1 / 2 - i;
		}
		{
			int m = (n2 - 2) / 2;
			rep(i, 0, n2) {
				for (int j = 1; j < m; j += 2) {
					ans.push_back({n1 + i, n1 + (i + j) % n2});
				}
			}
			rep(i, 0, n2 / 2) v[n1 + i] = i + 1 + n1 / 2;
			rep(i, n2 / 2, n2) v[n1 + i] = n - n1 / 2 + n2 / 2 - i;
		}
		rep(i, 0, n1) {
			int t = i & 1;
			rep(j, 0, 3) {
				ans.push_back({i, n1 + j * 2 + t});
			}
		}
	}
	for (auto& [x, y] : ans)
		if (x > y) swap(x, y);
	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	cout << ans.size() << '\n';
	for (auto [i, j] : ans) cout << v[i] << ' ' << v[j] << '\n';
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) solve();
}

Submission Info

Submission Time
Task B - Balanced Neighbors 2
User cho57020
Language C++ 20 (gcc 12.2)
Score 800
Code Size 3955 Byte
Status AC
Exec Time 6 ms
Memory 3628 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 2
AC × 27
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All case_01.txt, case_02.txt, case_03.txt, case_04.txt, case_05.txt, case_06.txt, case_07.txt, case_08.txt, case_09.txt, case_10.txt, case_11.txt, case_12.txt, case_13.txt, case_14.txt, case_15.txt, case_16.txt, case_17.txt, case_18.txt, case_19.txt, case_20.txt, case_21.txt, case_22.txt, case_23.txt, case_24.txt, case_25.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
case_01.txt AC 6 ms 3500 KiB
case_02.txt AC 1 ms 3416 KiB
case_03.txt AC 1 ms 3460 KiB
case_04.txt AC 1 ms 3592 KiB
case_05.txt AC 1 ms 3576 KiB
case_06.txt AC 1 ms 3404 KiB
case_07.txt AC 1 ms 3504 KiB
case_08.txt AC 1 ms 3452 KiB
case_09.txt AC 1 ms 3448 KiB
case_10.txt AC 1 ms 3388 KiB
case_11.txt AC 2 ms 3524 KiB
case_12.txt AC 2 ms 3620 KiB
case_13.txt AC 2 ms 3572 KiB
case_14.txt AC 2 ms 3628 KiB
case_15.txt AC 2 ms 3620 KiB
case_16.txt AC 2 ms 3624 KiB
case_17.txt AC 2 ms 3624 KiB
case_18.txt AC 2 ms 3512 KiB
case_19.txt AC 1 ms 3572 KiB
case_20.txt AC 1 ms 3556 KiB
case_21.txt AC 1 ms 3524 KiB
case_22.txt AC 1 ms 3500 KiB
case_23.txt AC 1 ms 3464 KiB
case_24.txt AC 1 ms 3516 KiB
case_25.txt AC 1 ms 3564 KiB
sample_01.txt AC 1 ms 3480 KiB
sample_02.txt AC 1 ms 3460 KiB