結果

問題 No.774 tatyamと素数大富豪
ユーザー FF256grhyFF256grhy
提出日時 2018-12-22 00:24:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,160 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 175,916 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-26 01:40:54
合計ジャッジ時間 5,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
7,764 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 68 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 4 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 64 ms
4,348 KB
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;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, p[9];
string a[9];

bool f(LL v) {
	for(LL i = 2; i * i <= v; i++) {
		if(v % i == 0) { return false; }
	}
	return true;
}

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) { if(a[i] == "10") { a[i] = "00"; } }
	inc(i, n) { if(a[i] ==  "1") { a[i] = "01"; } }
	sort(a, a + n, greater<string>());
	inc(i, n) { if(a[i] == "00") { a[i] = "10"; } }
	inc(i, n) { if(a[i] == "01") { a[i] =  "1"; } }
	
	
	inc(i, n) { p[i] = i; }
	LL ans = -1;
	do {
		string s;
		inc(i, n) { s += a[p[i]]; }
		LL v = stoll(s);
		if(f(v)) { ans = v; break; }
	} while(next_permutation(p, p + n));
	
	cout << ans << endl;
	
	return 0;
}
0