답안 #634949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634949 2022-08-25T09:24:54 Z inksamurai Paralelogrami (COCI17_paralelogrami) C++17
14 / 140
537 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3PGDklf ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

struct P{
	int x,y;
	P(int _x=0,int _y=0):
	x(_x),y(_y){}
	P operator+(const P&a)const{return {x+a.x,y+a.y};}
	P operator-(const P&a)const{return {x-a.x,y-a.y};}
	bool operator<(const P&a)const{
		return x<a.x;
	}
};

ll ccw(P a,P b,P c){
	return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y);
}

struct N
{
	P pa,pb,pc;
	int i,j,k;
};

signed main(){
_3PGDklf;
	int n;
	cin>>n;
	vec(P) pnts(n);
	rep(i,n){
		cin>>pnts[i].x>>pnts[i].y;
	}
	int si=-1,sj=-1,sk=-1;
	for(int i=0;i<n and si==-1;i++){
		for(int j=i+1;j<n and si==-1;j++){
			for(int k=j+1;k<n and si==-1;k++){
				if(ccw(pnts[i],pnts[j],pnts[k])!=0){
					si=i,sj=j,sk=k;
					break;
				}
			}
		}
	}
	if(si==-1){
		print(-1);
		return 0;
	}
	queue<vec(P)> que;
	que.push(vec(P){pnts[si],pnts[sj],pnts[sk]});
	std::map<vec(P),N> dp;
	dp[vec(P){pnts[si],pnts[sj],pnts[sk]}].i=-1;
	dp[vec(P){pnts[si],pnts[sj],pnts[sk]}].j=-1;
	dp[vec(P){pnts[si],pnts[sj],pnts[sk]}].k=-1;
	auto push=[&](P a,P b,P c,int i,int j,int k,P pa,P pb,P pc){
		if(dp.find(vec(P){a,b,c})==dp.end()){
			vec(P) now={a,b,c};
			dp[now].i=i;
			dp[now].j=j;
			dp[now].k=k;
			dp[now].pa=pa;
			dp[now].pb=pb;
			dp[now].pc=pc;
			que.push(now);
		}
	};
	vec(tuple<int,int,int>) pns;
	while(sz(que)){
		auto top=que.front();
		que.pop();
		P a=top[0];
		P b=top[1];
		P c=top[2];
		if(min({a.x,a.y,b.x,b.y,c.x,c.y})>10){
			// print("lets goo");
			// print(a.x,a.y,b.x,b.y,c.x,c.y);
			vec(P) now={a,b,c}; 
			while(1){
				if(dp[now].i==-1) break;
				// cout<<dp[now].i+1<<" "<<dp[now].j+1<<" "<<dp[now].k+1<<"\n";
				pns.pb({dp[now].i,dp[now].j,dp[now].k});
				vec(P) nenow(3);
				nenow[0]=dp[now].pa;
				nenow[1]=dp[now].pb;
				nenow[2]=dp[now].pc;
				now=nenow;
			}
			pnts[si]=a;
			pnts[sj]=b;
			pnts[sk]=c;
			break;
		}
		if(min({a.x,a.y,b.x,b.y,c.x,c.y})<-10){
			continue;
		}
		// shift a
		push(c+b-a,b,c,sj,sk,si,a,b,c);
		// shift b
		push(a,c+a-b,c,si,sk,sj,a,b,c);
		// shift c
		push(a,b,a+b-c,si,sj,sk,a,b,c);
	}
	reverse(pns.begin(), pns.end());
	// assert(sz(pns)<=2500-n);
	rep(i,n){
		if(pnts[i].x<0 or pnts[i].y<0){
			if(ccw(pnts[si],pnts[sj],pnts[i])!=0){
				pns.pb({si,sj,i});
			}else{
				pns.pb({si,sk,i});
			}
		}
	}
	print(sz(pns));
	for(auto [i,j,k]:pns){
		print(i+1,j+1,k+1);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 497 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 537 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB selected three points is not collinear
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB selected three points is not collinear
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB selected three points is not collinear
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB selected three points is not collinear
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB selected three points is not collinear
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 212 KB selected three points is not collinear
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB selected three points is not collinear
3 Halted 0 ms 0 KB -