제출 #1343728

#제출 시각아이디문제언어결과실행 시간메모리
1343728ByeWorldA String Problem (EGOI25_stringproblem)C++20
100 / 100
67 ms7988 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "Ofast")
#define int long long
#define ll long long
#define se second
#define fi first
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ipii;
const int MAXN = 5e5+10;
const int MAXA = 5e4+10;
const int SQRT = 300;
const ll INF = 2e18;
const int MOD = 1e9+7;
const int LOG = 32;
ll sum(auto a, auto b){ 
	ll te = a+MOD+b; 
	for(; te >= MOD; ) te -= MOD;
	return te;
}
void chsum(auto &a, auto b){ a = sum(a,b); }
ll mul(auto a, auto b){ return 1ll*a*b%MOD; }
void chmul(auto &a, auto b){ a = mul(a,b); }
void chmn(auto &a, auto b){ a = min(a, b); }
void chmx(auto &a, auto b){ a = max(a, b); }

ll expo(int a, int b){
	if(b==0) return 1;
	ll te = expo(a, b/2); te = mul(te,te); // temporary -> te
	return (b%2 ? mul(te, a) : te);
}
vector <int> dx = {0, 0, -1, 1};
vector<int> dy = {-1, 1, 0, 0};

int n, cnt[MAXN];
pii a[MAXN];
int wa[MAXN];
bool done[MAXN];

void dfs(int nw){
	if(done[nw] == 1) return;
	done[nw] = 1; done[wa[nw]] = 1;

	if(a[nw].fi == wa[nw]) return;

	cout << a[nw].se << ' ' << a[nw].fi << ' '<< wa[nw] << '\n';
	int oth = a[wa[nw]].fi; 
	dfs(oth);
}
signed main(){ 
	// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=0; i<n; i++){
		int x, y; cin>>x>>y;
		if(x > y) swap(x, y);

		a[x] = {y, i}; a[y] = {x, i};

		if((y-x-1)%2 == 0){
			int p = x+y;
			p /= 2;
			if(p>=n) p -= n;
			cnt[p]++;
		}
	}
	int mx = 0, idx=0;
	for(int i=0; i<n; i++){
		if(mx < cnt[i]){
			mx = cnt[i];
			idx = i;
		}
	}
	cout << n-mx << '\n';
	int l=idx, r=idx+1;
	while(true){
		if(wa[l] != 0) break;
		wa[l] = r; wa[r] = l;
		l--; r++;
		if(l < 0) l += 2*n;
		if(r >= 2*n) r -= 2*n;
	}
	int nw = idx;
	for(int i=0; i<2*n; i++){
		if(!done[i]){
			dfs(i);
		}
	}
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...