結果

問題 No.1594 Three Classes
ユーザー mtmtmtmtmtmtmtmtmtmt
提出日時 2021-07-10 09:28:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 2,630 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 103,704 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 00:35:59
合計ジャッジ時間 2,438 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 109 ms
5,376 KB
testcase_05 AC 105 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 105 ms
5,376 KB
testcase_09 AC 105 ms
5,376 KB
testcase_10 AC 105 ms
5,376 KB
testcase_11 AC 103 ms
5,376 KB
testcase_12 AC 105 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 14 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0