結果

問題 No.774 tatyamと素数大富豪
ユーザー Shuz*Shuz*
提出日時 2018-06-22 12:32:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,132 bytes
コンパイル時間 1,266 ms
コンパイル使用メモリ 145,752 KB
実行使用メモリ 7,584 KB
最終ジャッジ日時 2023-09-13 07:54:14
合計ジャッジ時間 5,597 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

bool IsPrime(ll num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    ll sqrtNum = sqrtf(num);
    for (ll i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;}}
    return true;}

int main(){
    ll n,i,p=1,ans,j,k,l;
    cin>>n;
    int a[n];
    ll t[3*n];
    t[1]=1;
    for(i=2;i-3*n;++i)t[i]=t[i-1]*10;
    for(i=0;i-n;++i)cin>>a[i],p*=2;
    ll s[p]={},y[p]={};
    ll aa=0,bb=0;
    for(i=0;i-p;++i){
         k=i;
         ans=a[0];
         l=a[0]>9?2:1;
         for(j=1;j-n;++j){
             l+=a[j]>9?2:1;
             if(k%2)ans+=a[j]*t[l];
             else{ans*=a[j]>9?100:10;ans+=a[j];}
             k/=2;}
         ll k=0;
         for(j=0;j-aa;++j)if(s[j]==ans){k=1;break;}
         if(!k)for(j=0;j-bb;++j)if(y[j]==ans){k=1;break;}
         if(!k){
             if(IsPrime(ans))s[aa++]=ans;
             else y[bb++]=ans;
         }}
    ll max=0;
    for(i=0;i-aa;++i)max=max>s[i]?max:s[i];
    if(max)cout<<max<<"\n";
    else cout<<"No"<<"\n";
}
0