헉..! 그룹을 두 개로 나누는데 가장 작은 것과 나머지를 and한 게 같아야 한다고...?
그룹을 어떻게 나눠야 할까 고민하다가 도저히 못 풀 것 같아서 패스했다.
이걸 조건에 맞는 그룹을 찾는게 아니라 가장 작은 거를 찾고 이 숫자와 and 한 게 같은 숫자들을 모은다. 나머지 숫자를 하나의 그룹으로 묶을 수 있다면 yes고 아니면 no를 출력하면 된다. 오... 워... 어차피 모든 숫자는 그룹에 포함되어 있어야 하니깐 가장 작은 수도 그룹에 있을 것이고 그럼 그 그룹을 기준으로 판단하면 되는구나.
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
template<typename T, typename Pr = less<T>>
using pq = priority_queue<T, vector<T>, Pr>;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int main()
{
int n;
scanf("%d", &n);
vector<int> v(n);
for (int i = 0; i < n; i++)
scanf("%d", &v[i]);
sort(all(v));
vector<int> left;
for (int i = 1; i < n; i++)
{
if ((v[0] & v[i]) != v[0])
left.push_back(v[i]);
}
for (int i = 1; i < left.size(); i++)
{
if ((left[0] & left[i]) != left[0])
{
printf("no");
return 0;
}
}
printf("yes");
return 0;
}
'prompt' 카테고리의 다른 글
[토요라운드] 20/09/05 후기 (0) | 2020.09.05 |
---|---|
[Special Round 2] C. 작업 일지 (0) | 2020.07.18 |
[코드포스 Round 80] C. Little Dima and Equation (0) | 2020.07.06 |
[코드포스 Round 80] B. Buying Shovels (0) | 2020.07.06 |
[코드포스 Round 80] A. Board Moves (0) | 2020.07.06 |