답안 #635031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635031 2022-08-25T10:22:23 Z inksamurai Paralelogrami (COCI17_paralelogrami) C++17
140 / 140
10 ms 1116 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 pii(x,y)<pii(a.x,a.y);
	}
};

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;
	}
	bool pok=1;
	rep(i,n){
		pok=pok*(pnts[i].x>=0 and pnts[i].y>=0);
	}
	if(pok){
		print(0);
		return 0;
	}
	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;
				}
			}
		}
	}
	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;
	bool here=0;
	while(sz(que)){
		auto top=que.front();
		que.pop();
		P a=top[0];
		P b=top[1];
		P c=top[2];
		if(ccw(a,b,c)==0) continue;
		if(min({a.x,a.y,b.x,b.y,c.x,c.y})>10){
			// print("lets goo");
			pnts[si]=a;
			pnts[sj]=b;
			pnts[sk]=c;
			vec(P) now={a,b,c}; 
			while(1){
				if(dp[now].i==-1) break;
				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;
			}
			break;
		}
		if(min({a.x,a.y,b.x,b.y,c.x,c.y})<-20){
			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());
	rep(i,n){
		if(i==si or i==sj or i==sk) continue;
		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{
				assert(ccw(pnts[si],pnts[sk],pnts[i])!=0);
				pns.pb({si,sk,i});
			}
		}
	}
	print(sz(pns));
	for(auto [i,j,k]:pns){
		print(i+1,j+1,k+1);
	}
}

Compilation message

paralelogrami.cpp: In function 'int main()':
paralelogrami.cpp:51:10: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   51 |   pok=pok*(pnts[i].x>=0 and pnts[i].y>=0);
      |       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
paralelogrami.cpp:90:7: warning: unused variable 'here' [-Wunused-variable]
   90 |  bool here=0;
      |       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1048 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1108 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 980 KB Output is correct
2 Correct 8 ms 1116 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 9 ms 1068 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 10 ms 1048 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 8 ms 1108 KB Output is correct
3 Correct 1 ms 340 KB Output is correct