Submission #21717150


Source Code Expand

/** author: samari06,  created: 12.04.2021 20:10:41 **/
#include <bits/stdc++.h>
#define REP(i, N) for(int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;

int main(){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    vector<int> cnt(30, 0);
    REP(i,s1.size()) {
        cnt[s1[i]-'a']++;
    }
    REP(i,s2.size()) {
        cnt[s2[i]-'a']++;
    }
    REP(i,s3.size()) {
        cnt[s3[i]-'a']++;
    }

    int c = 0;
    REP(i, 30) if(cnt[i] > 0) c++;
    if(c > 10) {
        puts("UNSOLVABLE");
        return 0;
    }

    map<char, int> mp;
    vector<int> v;
    REP(i, 30) {
        if(cnt[i] > 0) {
            c--;
            mp['a'+i] = c;
        }
    }
    REP(i,10) v.emplace_back(i);

    ll a1 = 0, a2 = 0, a3 = 0;
    do{
        bool comf = false;
        a1 = 0, a2 = 0, a3 = 0;
        REP(i,s1.size()){
            if(i == 0 && v[mp[s1[i]]] == 0) comf = true;
            a1 *= 10;
            a1 += v[mp[s1[i]]];
        }
        if(comf) continue;
        REP(i,s2.size()){
            if(i == 0 && v[mp[s2[i]]] == 0) comf = true;
            a2 *= 10;
            a2 += v[mp[s2[i]]];
        }
        if(comf) continue;
        REP(i,s3.size()){
            if(i == 0 && v[mp[s3[i]]] == 0) comf = true;
            a3 *= 10;
            a3 += v[mp[s3[i]]];
        }
        if(comf) continue;


        if(a1+a2 == a3){
            printf("%lld\n%lld\n%lld\n", a1, a2, a3);
            return 0;
        }
    }while(next_permutation(v.begin(), v.end()));

    puts("UNSOLVABLE");
    return 0;
}

Submission Info

Submission Time
Task D - Send More Money
User samari06
Language C++ (GCC 9.2.1)
Score 400
Code Size 1621 Byte
Status AC
Exec Time 566 ms
Memory 3696 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 40
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_05.txt
Case Name Status Exec Time Memory
hand_01.txt AC 161 ms 3568 KiB
hand_02.txt AC 501 ms 3504 KiB
hand_03.txt AC 277 ms 3556 KiB
hand_04.txt AC 14 ms 3600 KiB
hand_05.txt AC 323 ms 3564 KiB
random_01.txt AC 146 ms 3596 KiB
random_02.txt AC 430 ms 3568 KiB
random_03.txt AC 122 ms 3516 KiB
random_04.txt AC 32 ms 3548 KiB
random_05.txt AC 121 ms 3552 KiB
random_06.txt AC 222 ms 3548 KiB
random_07.txt AC 84 ms 3552 KiB
random_08.txt AC 64 ms 3692 KiB
random_09.txt AC 116 ms 3632 KiB
random_10.txt AC 386 ms 3560 KiB
random_11.txt AC 67 ms 3632 KiB
random_12.txt AC 303 ms 3624 KiB
random_13.txt AC 9 ms 3552 KiB
random_14.txt AC 210 ms 3612 KiB
random_15.txt AC 46 ms 3568 KiB
random_16.txt AC 127 ms 3612 KiB
random_17.txt AC 316 ms 3612 KiB
random_18.txt AC 472 ms 3632 KiB
random_19.txt AC 182 ms 3548 KiB
random_20.txt AC 175 ms 3624 KiB
random_21.txt AC 3 ms 3624 KiB
random_22.txt AC 285 ms 3504 KiB
random_23.txt AC 2 ms 3564 KiB
random_24.txt AC 85 ms 3696 KiB
random_25.txt AC 6 ms 3580 KiB
random_26.txt AC 220 ms 3624 KiB
random_27.txt AC 3 ms 3484 KiB
random_28.txt AC 566 ms 3484 KiB
random_29.txt AC 67 ms 3692 KiB
random_30.txt AC 460 ms 3468 KiB
sample_01.txt AC 44 ms 3564 KiB
sample_02.txt AC 25 ms 3516 KiB
sample_03.txt AC 90 ms 3480 KiB
sample_04.txt AC 2 ms 3472 KiB
sample_05.txt AC 99 ms 3568 KiB