Submission #501819


Source Code Expand

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef LL ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<ut,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=5+3*1e+4;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

map<char, bool> check;
int cnt, L;
LL tenb[10];
string s;
VI data;

bool is_prime(LL n){
	for(int i = 2; i * i <= n; ++i){
		if(n % i == 0)
			return false;
	}
	return n != 1;
}


int main() {
	cin >> s;
	REP(i,s.size()){
		if(!check[s[i]]){
			check[s[i]] = true;
			cnt++;
		}
	}
	if(cnt > 5){
		cout << "-1" << endl;
		return 0;
	}
	L = s.size();
	REP(i,L)
		tenb[i] = pow(10, i);
	
	REP(i,5)
		data.push_back(i * 2 + 1);
	
	int loop = 1e+5 * 2;
	while(loop--){
    	time_t nowtime;
    	time(&nowtime);
    	srand((int)nowtime);
		random_shuffle(BE(data));

		LL res = 0;
		map<char, int> nums;
		int c = 0;
		REP(i,L){
			if(nums[s[i]] == 0){
				nums[s[i]] = data[c];
				c++;
			}
			res += nums[s[i]] * tenb[L-i-1];
		}
		if(is_prime(res)){
			cout << res << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}

Submission Info

Submission Time
Task D - 文字列と素数
User anct
Language C++ (GCC 4.9.2)
Score 50
Code Size 1667 Byte
Status AC
Exec Time 1493 ms
Memory 928 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 50 / 50
Status
AC × 3
AC × 25
Set Name Test Cases
Sample 00_sample_00, 00_sample_01, 00_sample_02
All 00_sample_00, 00_sample_01, 00_sample_02, 05_rand_00, 05_rand_01, 05_rand_02, 05_rand_03, 05_rand_04, 05_rand_05, 05_rand_06, 05_rand_07, 05_rand_08, 05_rand_09, 15_rand_00, 15_rand_01, 15_rand_02, 15_rand_03, 15_rand_04, 15_rand_05, 15_rand_06, 15_rand_07, 15_rand_08, 15_rand_09, 20_teuti_00, 20_teuti_01
Case Name Status Exec Time Memory
00_sample_00 AC 26 ms 808 KiB
00_sample_01 AC 726 ms 792 KiB
00_sample_02 AC 26 ms 800 KiB
05_rand_00 AC 789 ms 676 KiB
05_rand_01 AC 25 ms 804 KiB
05_rand_02 AC 24 ms 924 KiB
05_rand_03 AC 541 ms 800 KiB
05_rand_04 AC 586 ms 796 KiB
05_rand_05 AC 24 ms 924 KiB
05_rand_06 AC 634 ms 928 KiB
05_rand_07 AC 1182 ms 796 KiB
05_rand_08 AC 587 ms 808 KiB
05_rand_09 AC 26 ms 804 KiB
15_rand_00 AC 26 ms 808 KiB
15_rand_01 AC 26 ms 800 KiB
15_rand_02 AC 25 ms 804 KiB
15_rand_03 AC 27 ms 800 KiB
15_rand_04 AC 1170 ms 920 KiB
15_rand_05 AC 25 ms 728 KiB
15_rand_06 AC 1493 ms 868 KiB
15_rand_07 AC 25 ms 928 KiB
15_rand_08 AC 588 ms 924 KiB
15_rand_09 AC 27 ms 916 KiB
20_teuti_00 AC 647 ms 800 KiB
20_teuti_01 AC 24 ms 924 KiB