結果

問題 No.3024 等式
ユーザー latte0119latte0119
提出日時 2017-04-01 00:03:47
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 2,256 bytes
コンパイル時間 2,665 ms
コンパイル使用メモリ 157,164 KB
実行使用メモリ 740,488 KB
最終ジャッジ日時 2023-09-21 20:02:04
合計ジャッジ時間 13,293 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 15 ms
4,680 KB
testcase_07 AC 18 ms
4,640 KB
testcase_08 AC 27 ms
5,604 KB
testcase_09 AC 24 ms
5,556 KB
testcase_10 AC 26 ms
5,596 KB
testcase_11 AC 23 ms
5,676 KB
testcase_12 AC 548 ms
44,908 KB
testcase_13 AC 548 ms
46,024 KB
testcase_14 AC 799 ms
80,256 KB
testcase_15 AC 852 ms
80,588 KB
testcase_16 AC 711 ms
80,036 KB
testcase_17 AC 579 ms
46,824 KB
testcase_18 MLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
inline pint f(pint a){
    int g=gcd(abs(a.fi),a.se);
    a.fi/=g;
    a.se/=g;
    return a;
}

bool operator==(pint a,pint b){
    return a.fi==b.fi&&a.se==b.se;
}

pint operator+(pint a,pint b){
    int l=lcm(a.se,b.se);
    a.fi*=l/a.se;
    b.fi*=l/b.se;
    a.se=l;
    a.fi+=b.fi;

    int g=gcd(abs(a.fi),a.se);
    a.fi/=g;a.se/=g;
    return a;
}

pint operator-(pint a,pint b){
    int l=lcm(a.se,b.se);
    a.fi*=l/a.se;
    b.fi*=l/b.se;
    a.se=l;
    a.fi-=b.fi;

    int g=gcd(abs(a.fi),a.se);
    a.fi/=g;a.se/=g;
    return a;
}

pint operator*(pint a,pint b){
    a.fi*=b.fi;
    a.se*=b.se;
    int g=gcd(abs(a.fi),a.se);
    a.fi/=g;
    a.se/=g;
    return a;
}

pint operator/(pint a,pint b){
    assert(b.fi!=0);

    a.fi*=b.se;
    a.se*=b.fi;
    if(a.se<0){
        a.se*=-1;
        a.fi*=-1;
    }
    int g=gcd(abs(a.fi),a.se);
    a.fi/=g;
    a.se/=g;
    return a;
}

int N;
pint A[10];

vpint mem[1<<7];

vpint dfs(int b){
    if(__builtin_popcount(b)==1){
        for(int i=0;i<N;i++)if(b>>i&1)return {A[i]};
    }

    if(mem[b].size()!=0)return mem[b];

    vpint &w=mem[b];
    for(int bb=1;bb<b;bb++){
        if((b&bb)!=bb)continue;
        int bbb=b^bb;

        auto v=dfs(bb);
        auto u=dfs(bbb);

        for(auto &a:v)for(auto &b:u){
            w.pb(a+b);
            w.pb(a-b);
            w.pb(a*b);
            if(b.fi!=0)w.pb(a/b);
        }
    }
    sort(all(w));
    w.erase(unique(all(w)),w.end());
    return w;
}

signed main(){
    cin>>N;
    rep(i,N){
        int a;cin>>a;
        A[i]=pint(a,1);
    }

    auto v=dfs((1<<N)-1);
    if(find(all(v),pint(0,1))!=v.end()){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}
0