結果

問題 No.774 tatyamと素数大富豪
ユーザー chocopuuchocopuu
提出日時 2018-12-22 03:29:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,603 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 186,516 KB
実行使用メモリ 159,328 KB
最終ジャッジ日時 2023-10-26 01:52:59
合計ジャッジ時間 33,451 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,770 ms
159,068 KB
testcase_01 AC 1,437 ms
159,264 KB
testcase_02 AC 1,537 ms
159,320 KB
testcase_03 AC 1,492 ms
159,320 KB
testcase_04 AC 1,388 ms
159,264 KB
testcase_05 AC 1,475 ms
159,320 KB
testcase_06 WA -
testcase_07 AC 1,351 ms
159,320 KB
testcase_08 AC 1,366 ms
159,320 KB
testcase_09 AC 1,482 ms
159,320 KB
testcase_10 AC 1,645 ms
159,320 KB
testcase_11 AC 1,571 ms
159,320 KB
testcase_12 AC 1,606 ms
159,320 KB
testcase_13 AC 1,658 ms
159,320 KB
testcase_14 AC 1,374 ms
159,320 KB
testcase_15 AC 1,640 ms
159,320 KB
testcase_16 AC 1,456 ms
159,320 KB
testcase_17 AC 1,563 ms
159,320 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(191313131);  
    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;
        }
    }
    cout<<-1<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}
0