結果

問題 No.3024 等式
ユーザー rickythetarickytheta
提出日時 2017-03-31 23:55:10
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,454 bytes
コンパイル時間 1,805 ms
コンパイル使用メモリ 162,704 KB
実行使用メモリ 35,572 KB
最終ジャッジ日時 2023-09-21 13:02:18
合計ジャッジ時間 9,014 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 82 ms
4,968 KB
testcase_07 AC 74 ms
5,920 KB
testcase_08 AC 84 ms
8,136 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl

int n;
int a[7];

namespace std{
  template <>
  class hash<pll> {
  public:
    size_t operator()(const pll &x) const {
      return hash<int>()(hash<int>()(x.first)) ^ hash<int>()(x.second);
    }
  };
}

unordered_map<pll,vi> M;
unordered_set<pll> S;
vector<pll> V;

void dfs(int mask){
  if(mask==0 && V.size()==1){
    ll g = __gcd(V[0].first, V[0].second);
    S.insert(pll(V[0].first/g,V[0].second/g));
    return;
  }
  if(mask != 0){
    // push
    REP(i,n)if((mask>>i)&1){
      int nmsk = mask ^ (1<<i);
      V.push_back(pll(a[i],1));
      dfs(nmsk);
      V.pop_back();
    }
  }
  if(V.size()>=2){
    // pop
    pll x = V.back(); V.pop_back();
    pll y = V.back(); V.pop_back();
    ll xa = x.first;
    ll xb = x.second;
    ll ya = y.first;
    ll yb = y.second;
    // add
    {
      ll zb = xb*yb;
      ll za = xa*yb + ya*xb;
      V.push_back(pll(za,zb));
      dfs(mask);
      V.pop_back();
    }
    // sub
    {
      ll zb = xb*yb;
      ll za = xa*yb - ya*xb;
      V.push_back(pll(za,zb));
      dfs(mask);
      V.pop_back();
    }
    // mul
    {
      ll za = xa*ya;
      ll zb = xb*yb;
      if(zb<0){
        zb*=-1;
        za*=-1;
      }
      V.push_back(pll(za,zb));
      dfs(mask);
      V.pop_back();
    }
    // div
    if(ya!=0){
      ll za = xa*yb;
      ll zb = xb*ya;
      if(zb<0){
        zb*=-1;
        za*=-1;
      }
      V.push_back(pll(za,zb));
      dfs(mask);
      V.pop_back();
    }
    V.push_back(y);
    V.push_back(x);
  }
}

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i);
  REP(mask,1<<n){
    int po = __builtin_popcount(mask);
    if(po==0 || po==7)continue;
    S.clear();
    V.clear();
    dfs(mask);
    for(pll x : S){
      for(int another : M[x]){
        if((mask&another)==0){
          puts("YES");
          // DEBUG(mask);
          // DEBUG(another);
          // DEBUG(x.first);
          // DEBUG(x.second);
          return 0;
        }
      }
      M[x].push_back(mask);
    }
  }
  puts("NO");
  return 0;
}
0