結果

問題 No.774 tatyamと素数大富豪
ユーザー 👑 tatyam
提出日時 2018-09-11 23:55:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,281 bytes
コンパイル時間 1,764 ms
コンパイル使用メモリ 205,036 KB
最終ジャッジ日時 2025-01-06 13:14:39
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 13 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define fcout cout << fixed << setprecision(10)

vector<int> card;
vector<ll> permlist;

bool is_prime(ll n){
    if (n < 2) return false;
    if (n < 4) return true;
    if (!(n % 2)) return false;
    if (!(n % 3)) return false;
    ll sq = sqrt(n);
    for(int i = 5 ;i <= sq; i += 4 - i % 6 / 2){
        if (sq < i) return true;
        if (!(n % i)) return false;
    }
    return true;
}
ll putBack(ll a, int b){
    return a * (b < 10 ? 10 : 100) + b;
}
vector<int> erase(vector<int> v,int pos){
    v.erase(v.begin()+pos);
    return v;
}
void permutations(vector<int> v,ll cnt){
    if(v.size()==1){
        permlist.push_back(putBack(cnt, v[0]));
        return;
    }
    rep(i,0,v.size()){
        permutations(erase(v,i), putBack(cnt, v[i]));
    }
}
int main(){
    int n,a;
    cin >> n;
    card.reserve(n);
    rep(i, 0, n){
        cin >> a;
        card.push_back(a);
    }
    permlist.push_back(0);
    permutations(card,0);
    sort(permlist.begin()+1, permlist.end(), greater<ll>());
    rep(i,1,permlist.size())if(permlist[i-1]!=permlist[i]&&is_prime(permlist[i])){
        cout<<permlist[i]<<endl;
        return 0;
    }
    cout<<-1<<endl;
}
0