結果
| 問題 | No.1594 Three Classes | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-07-10 09:28:46 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 117 ms / 2,000 ms | 
| コード長 | 2,630 bytes | 
| コンパイル時間 | 1,142 ms | 
| コンパイル使用メモリ | 102,144 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-16 08:24:37 | 
| 合計ジャッジ時間 | 2,709 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 18 | 
ソースコード
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <cstring>
#include <set>
#include <utility>
#include <iostream>
#include <iomanip>
#include <list>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <cassert>
#include <numeric>
#include <complex>
#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SUM(v) accumulate(ALL(v),0ll)
using ll = long long;
const ll INF=1e18;
const ll eps=1;
const double pi=3.14159265359;
const ll mod=1e9+1;
using namespace std;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
    }
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
//------------------------------------------------------------------------
string eight_to_ten(string a)
{
  ll ans;
  string ten;
  ll cnt=1;
  ll tmp=1;
  REP(i,a.size())
  {
    tmp+=tmp*8+(a[i]-'0');
  }
  ten=to_string(tmp);
  reverse(ten.begin(),ten.end());
  return ten;
}
string ten_to_nine(string a)
{
  string ans;
  ll cnt=stoll(a);
  while(cnt>0)
  {
    ll tmp=cnt%9;
    ans=to_string(tmp%9)+ans;
    cnt/=9;
  }
  reverse(ans.begin(),ans.end());
  return ans;
}
int main()
{
  int n;
  cin>>n;
  ll sum=0;
  vector<ll> a(n),cnt(n+1);
  REP(i,n)
  {
    cin>>a[i];
  }
  cnt[0]=1;
  REP(i,n+1)
  {
    if(i==0)continue;
    cnt[i]=3*cnt[i-1];
  }
  REP(i,cnt[n])
  {
    ll suma=0,sumb=0,sumc=0;
    REP(j,n)
    {
      ll bit=(i/cnt[j])%3;
      if(bit==0)suma+=a[j];
      else if(bit==1)sumb+=a[j];
      else if(bit==2)sumc+=a[j];
    }
    if(suma==sumb&&sumb==sumc)
    {
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}
            
            
            
        