Submission #501492


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define rep2(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define inf (1e9)
#define eps (1e-9)

int check(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return 0;
    }
  }
  return 1;
}

int main() {
  string s; cin >> s;
  map<char,int> m;
  int d[5] = {1,3,5,7,9};
  for (int i = 0; i < s.length(); i++) m[s[i]]++;
  if (m.size() > 5) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < s.length(); i++) m[s[i]] = -1;
    int x = 0;
    for (int i = 0; i < s.length(); i++) {
      if (m[s[i]] == -1) {
	m[s[i]] = x;
	x++;
      }
    }
    bool hit = false;
    do {
      long long num = 0;
      long long dg = 1;
      for (int i = s.length()-1; i >= 0; i--) {
	num += dg * d[m[s[i]]];
	dg *= 10;
      }
      if (num != 1 && check(num) == 1) {
        cout << num << endl;
	hit = true;
	break;
      }
    } while (next_permutation(d,d+5));
    if (!hit)
      cout << -1 << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task D - 文字列と素数
User penzant
Language C++ (GCC 4.9.2)
Score 50
Code Size 1081 Byte
Status AC
Exec Time 32 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 30 ms 768 KiB
00_sample_01 AC 26 ms 920 KiB
00_sample_02 AC 25 ms 800 KiB
05_rand_00 AC 30 ms 800 KiB
05_rand_01 AC 26 ms 800 KiB
05_rand_02 AC 26 ms 808 KiB
05_rand_03 AC 26 ms 928 KiB
05_rand_04 AC 26 ms 800 KiB
05_rand_05 AC 26 ms 700 KiB
05_rand_06 AC 26 ms 920 KiB
05_rand_07 AC 27 ms 796 KiB
05_rand_08 AC 26 ms 920 KiB
05_rand_09 AC 28 ms 920 KiB
15_rand_00 AC 27 ms 712 KiB
15_rand_01 AC 26 ms 920 KiB
15_rand_02 AC 32 ms 804 KiB
15_rand_03 AC 27 ms 796 KiB
15_rand_04 AC 28 ms 792 KiB
15_rand_05 AC 28 ms 920 KiB
15_rand_06 AC 30 ms 920 KiB
15_rand_07 AC 29 ms 796 KiB
15_rand_08 AC 26 ms 808 KiB
15_rand_09 AC 28 ms 796 KiB
20_teuti_00 AC 26 ms 916 KiB
20_teuti_01 AC 28 ms 924 KiB