Submission #500895


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef long long ll;

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

ll convert(string a){
    return atoll(a.c_str());
}

void solve(string str,int depth,int bit){
    if(depth == str.size()){
        if(isPrime(convert(str))){
            cout << str << "\n";
            exit(0);
        }
        return ;
    }
    string copy = str;
    char x = str[depth];
    if(isdigit(x)){
        solve(str,depth+1,bit);
    }
    else{
        string num = "13579";
        rep(j,5){
            if(1&(bit>>j))continue;
            str = copy;
            rep(i,str.size()){
                if(str[i] == x){
                    str[i] = num[j];
                }
            }
            solve(str,depth+1,bit|(1<<j));
        }
    }
    return ;
}

int main(){

    string str;
    cin >> str;

    solve(str,0,0);
    cout << "-1" << "\n";
    return 0;
}

Submission Info

Submission Time
Task D - 文字列と素数
User Pelchigi
Language C++ (GCC 4.9.2)
Score 50
Code Size 1492 Byte
Status AC
Exec Time 31 ms
Memory 924 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 29 ms 896 KiB
00_sample_01 AC 27 ms 860 KiB
00_sample_02 AC 26 ms 864 KiB
05_rand_00 AC 28 ms 868 KiB
05_rand_01 AC 27 ms 864 KiB
05_rand_02 AC 26 ms 796 KiB
05_rand_03 AC 27 ms 924 KiB
05_rand_04 AC 27 ms 872 KiB
05_rand_05 AC 27 ms 864 KiB
05_rand_06 AC 30 ms 872 KiB
05_rand_07 AC 28 ms 796 KiB
05_rand_08 AC 27 ms 916 KiB
05_rand_09 AC 28 ms 868 KiB
15_rand_00 AC 29 ms 912 KiB
15_rand_01 AC 28 ms 784 KiB
15_rand_02 AC 27 ms 860 KiB
15_rand_03 AC 28 ms 912 KiB
15_rand_04 AC 28 ms 900 KiB
15_rand_05 AC 28 ms 924 KiB
15_rand_06 AC 31 ms 804 KiB
15_rand_07 AC 28 ms 864 KiB
15_rand_08 AC 27 ms 876 KiB
15_rand_09 AC 27 ms 920 KiB
20_teuti_00 AC 27 ms 860 KiB
20_teuti_01 AC 28 ms 876 KiB