Submission #501793


Source Code Expand

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <algorithm>
#define ll long long 

using namespace std;

int indexof(vector<char> &s, char c){
	for(int i=0;i<s.size();i++){
		if(s[i]==c) return i;
	}
	return -1;
}

ll make_num( string &str,vector<char> &s)
{
	ll num = 0;
	for(char c : str){
		num*=10;
		int idx = indexof(s,c);
		ll n = idx*2+1;
		num += n;
	}
	return num;
}

bool check(ll n)
{
	if(n%2==0) return false;
	for(ll i=3;i*i<=n;i+=2){
		if( n%i == 0 ){
			return false;
		}
	}
	return true;
}

int main() {

	string str;
	cin >> str;
	
	vector<char> s;
	for( char c : str ){
		auto f = find( s.begin(),s.end(), c);
		if( f==s.end() ){
			s.push_back(c);
		}
	}
	
	if( s.size()>5 ){
		cout << "-1" << endl;
		return 0;
	}
	char a='A';
	while(s.size()<5){
		s.push_back(a);
		a++;
	}

	sort(s.begin(),s.end());
	do{
		// for(auto c:s)cout<<c;
		// cout<<endl;
		ll n=make_num(str,s);
		if( check(n) ){
			cout << n << endl;
			return 0;
		}
		
	}while(next_permutation(s.begin(),s.end()));

	cout << "-1" << endl;

	return 0;
}

Submission Info

Submission Time
Task D - 文字列と素数
User phoenix
Language C++11 (GCC 4.9.2)
Score 50
Code Size 1168 Byte
Status AC
Exec Time 29 ms
Memory 932 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 27 ms 804 KiB
00_sample_01 AC 26 ms 924 KiB
00_sample_02 AC 25 ms 928 KiB
05_rand_00 AC 29 ms 928 KiB
05_rand_01 AC 23 ms 928 KiB
05_rand_02 AC 24 ms 752 KiB
05_rand_03 AC 25 ms 924 KiB
05_rand_04 AC 25 ms 796 KiB
05_rand_05 AC 26 ms 800 KiB
05_rand_06 AC 26 ms 928 KiB
05_rand_07 AC 25 ms 920 KiB
05_rand_08 AC 27 ms 800 KiB
05_rand_09 AC 23 ms 924 KiB
15_rand_00 AC 24 ms 928 KiB
15_rand_01 AC 26 ms 780 KiB
15_rand_02 AC 25 ms 924 KiB
15_rand_03 AC 26 ms 920 KiB
15_rand_04 AC 26 ms 928 KiB
15_rand_05 AC 28 ms 804 KiB
15_rand_06 AC 26 ms 928 KiB
15_rand_07 AC 28 ms 928 KiB
15_rand_08 AC 25 ms 932 KiB
15_rand_09 AC 26 ms 928 KiB
20_teuti_00 AC 25 ms 796 KiB
20_teuti_01 AC 27 ms 800 KiB