結果

問題 No.3024 等式
ユーザー latte0119latte0119
提出日時 2017-04-01 00:15:43
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,466 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 157,528 KB
実行使用メモリ 81,456 KB
最終ジャッジ日時 2023-09-22 14:06:09
合計ジャッジ時間 4,744 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 15 ms
4,672 KB
testcase_07 AC 17 ms
4,532 KB
testcase_08 AC 25 ms
5,508 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 524 ms
45,068 KB
testcase_13 AC 527 ms
46,664 KB
testcase_14 AC 769 ms
81,456 KB
testcase_15 AC 87 ms
12,344 KB
testcase_16 AC 8 ms
4,488 KB
testcase_17 AC 32 ms
6,820 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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(a==b){
                cout<<"YES"<<endl;
                exit(0);
            }
            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);
    }

    if(N==7){
        puts("YES");
        return 0;
    }
    
    dfs((1<<N)-1);
    for(int i=1;i<(1<<N);i++){
        if(find(all(mem[i]),pint(0,1))!=mem[i].end()){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}
0