結果

問題 No.774 tatyamと素数大富豪
ユーザー chocopuuchocopuu
提出日時 2018-12-22 03:55:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,752 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 186,724 KB
実行使用メモリ 92,020 KB
最終ジャッジ日時 2023-10-26 01:56:49
合計ジャッジ時間 28,919 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,451 ms
92,020 KB
testcase_01 AC 1,023 ms
85,300 KB
testcase_02 AC 1,120 ms
85,300 KB
testcase_03 AC 1,092 ms
85,300 KB
testcase_04 AC 1,003 ms
85,300 KB
testcase_05 AC 1,166 ms
85,300 KB
testcase_06 WA -
testcase_07 AC 1,041 ms
85,300 KB
testcase_08 WA -
testcase_09 AC 1,291 ms
85,300 KB
testcase_10 AC 1,327 ms
85,300 KB
testcase_11 AC 1,269 ms
85,300 KB
testcase_12 AC 1,297 ms
85,300 KB
testcase_13 AC 1,329 ms
85,300 KB
testcase_14 AC 1,051 ms
85,300 KB
testcase_15 AC 1,286 ms
85,300 KB
testcase_16 AC 1,191 ms
85,300 KB
testcase_17 AC 1,247 ms
85,300 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define fill(i,n) memset(i,n,sizeof(i))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
string s[13];
unordered_map<string,int>mp;

vector<int> P;
void make_primes(int n)
{
	vector<bool> primes;

	primes.resize(n + 1, true);
	primes[0] = primes[1] = false;
	rep(i, 2, sqrt(n)) if (primes[i]) for (int j = 0; i * (j + 2) < n; j++)
		primes[i * (j + 2)] = false;

	rep(i, 2, n + 1) if (primes[i]) P.push_back(i);
}

int perm2[13];
void permtation2(int n){
  for(int i=0;i<n;i++){
    perm2[i]=i;
  }
  do{
      string tmp="";
    rep(i,0,n)tmp=tmp+s[perm2[i]];
    mp[tmp]++;
  }while(next_permutation(perm2,perm2+n));
  return ;
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
   cin>>N;
   rep(i,0,N){
       cin>>s[i];
   }
   
    make_primes(131313131);  
    permtation2(N);
    std::priority_queue<int>pq;
    bool ok;
    for(auto e:mp)pq.push(stol(e.fi));
    while(!pq.empty()){
        int q=pq.top();
        pq.pop();
        //cout<<q<<endl;
        for(auto e:P){
            ok=true;
            if(q%e==0){
                if(q!=e)ok=false;
                break;
            }
        }
        if(ok){
            cout<<q<<endl;
            return 0;
        }
        else if(sqrt(q)-(int)sqrt(q)==0){
            if(q%(int)sqrt(q)==0){
        cout<<sqrt(q)<<endl;
        return 0;
            }
    }
    }
    
    cout<<-1<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}
0