結果

問題 No.3024 等式
ユーザー rickythetarickytheta
提出日時 2017-03-31 23:46:10
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,322 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 162,656 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-21 12:43:57
合計ジャッジ時間 9,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 98 ms
5,312 KB
testcase_07 AC 112 ms
6,460 KB
testcase_08 AC 152 ms
8,756 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 4 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];

map<pll,vi> M;
set<pll> S;
vector<pll> V;

void dfs(int mask){
  if(mask==0 && V.size()==1){
    S.insert(pll(V[0].first,V[0].second));
    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;
      ll g = __gcd(za,zb);
      V.push_back(pll(za/g,zb/g));
      dfs(mask);
      V.pop_back();
    }
    // sub
    {
      ll zb = xb*yb;
      ll za = xa*yb - ya*xb;
      ll g = __gcd(za,zb);
      V.push_back(pll(za/g,zb/g));
      dfs(mask);
      V.pop_back();
    }
    // mul
    {
      ll za = xa*ya;
      ll zb = xb*yb;
      if(zb<0){
        zb*=-1;
        za*=-1;
      }
      ll g = __gcd(za,zb);
      V.push_back(pll(za/g,zb/g));
      dfs(mask);
      V.pop_back();
    }
    // div
    if(ya!=0){
      ll za = xa*yb;
      ll zb = xb*ya;
      if(zb<0){
        zb*=-1;
        za*=-1;
      }
      ll g = __gcd(za,zb);
      V.push_back(pll(za/g,zb/g));
      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