개발자 톡
해설 2번대로 풀었는데 오류가 발생합니다...왜일까요?
- 등록일
- 2024-09-01 14:36:51
- 조회수
- 131
- 작성자
- sy0303b
#include <iostream>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <vector>
#include <climits>
#define MAX INT_MAX
using namespace std;
int N, K;
vector<tuple<int,int,int>> v;
int size(int start, int end){
int s_x = get<0>(v[start]);
int s_y = get<1>(v[start]);
int e_x = get<0>(v[end]);
int e_y = get<1>(v[end]);
int x = abs(s_x - e_x);
int y = abs(s_y - e_y);
return y*x;
}
bool check(int start, int end){
vector<bool> check_v(K+1);
fill(check_v.begin(),check_v.end(), false);
int s_x = get<0>(v[start]);
int s_y = get<1>(v[start]);
int e_x = get<0>(v[end]);
int e_y = get<1>(v[end]);
for(int i=start; i<=end; ++i){
int x = get<0>(v[i]);
int y = get<1>(v[i]);
int color = get<2>(v[i]);
if(x>=s_x && x<=e_x || x<=s_x && x>=e_x){
if(y>=s_y && y<=e_y || y<=s_y && y>=e_y){
check_v[color] = true;
}
}
}
for(int i=1; i<K+1; ++i){
if(check_v[i] == false) return false;
}
return true;
}
int main(int argc, char** argv)
{
cin>>N>>K;
for(int i=0; i<N; ++i){
int x,y,k;
cin>>x>>y>>k;
v.push_back(make_tuple(x,y,k));
}
sort(v.begin(),v.end());
//vector 순회
int min_size = MAX;
for(int i=0; i<N; ++i){
for(int j=i+1; j<N; ++j){
if(check(i, j)){
int temp_size = size(i,j);
min_size = min(min_size, temp_size);
}
}
}
if(K == 1) min_size = 0;
cout<<min_size;
return 0;
}