Submission #21682539


Source Code Expand

# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second

using namespace std;

const int N = 1e5 + 7;

int mp[N];

int32_t main() {
    string s1, s2, s3, no = "UNSOLVABLE";
    cin >> s1 >> s2 >> s3;
    int n = s1.size(), m = s2.size(), k = s3.size();
    if ( k != max( { n, m, k } ) ) {
        cout << no;
        return 0;
    }
    set < char > st;
    for ( auto i: s1 ) {
        st.insert(i);
    }
    for ( auto i: s2 ) {
        st.insert(i);
    }
    for ( auto i: s3 ) {
        st.insert(i);
    }
    if ( st.size() > 10 ) {
        cout << no;
        return 0;
    }
    vector < char > vc;
    for ( auto i: st ) {
        vc.push_back(i);
    }
    int sz = vc.size();
    vector < int > v;
    for ( int i = 0; i < 10; i++ ) {
        v.push_back(i);
    }
    do {
        for ( int i = 0; i < sz; i++ ) {
            mp[ vc[i] + 0 ] = v[i];
        }
        int a = 0, b = 0, c = 0, ok = 1;
        for ( int i = 0; i < n; i++ ) {
            a *= 10;
            a += mp[ s1[i] + 0 ];
            if ( a == 0 ) {
                ok = 0;
                break;
            }
        }
        for ( int i = 0; i < m; i++ ) {
            b *= 10;
            b += mp[ s2[i] + 0 ];
            if ( b == 0 ) {
                ok = 0;
                break;
            }
        }
        for ( int i = 0; i < k; i++ ) {
            c *= 10;
            c += mp[ s3[i] + 0 ];
            if ( c == 0 ) {
                ok = 0;
                break;
            }
        }
        if ( a + b == c && a > 0 && b > 0 && c > 0 && ok ) {
            cout << a << '\n' << b << "\n" << c;
            return 0;
        }
    }
    while ( next_permutation(v.begin(), v.end()) );
    cout << no;
}
    

Submission Info

Submission Time
Task D - Send More Money
User Dilshod_Imomov
Language C++ (GCC 9.2.1)
Score 400
Code Size 1902 Byte
Status AC
Exec Time 127 ms
Memory 3620 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 59 ms 3572 KiB
hand_02.txt AC 122 ms 3464 KiB
hand_03.txt AC 90 ms 3484 KiB
hand_04.txt AC 87 ms 3596 KiB
hand_05.txt AC 97 ms 3588 KiB
random_01.txt AC 15 ms 3468 KiB
random_02.txt AC 122 ms 3564 KiB
random_03.txt AC 81 ms 3516 KiB
random_04.txt AC 88 ms 3544 KiB
random_05.txt AC 17 ms 3480 KiB
random_06.txt AC 43 ms 3616 KiB
random_07.txt AC 17 ms 3480 KiB
random_08.txt AC 119 ms 3544 KiB
random_09.txt AC 5 ms 3416 KiB
random_10.txt AC 65 ms 3476 KiB
random_11.txt AC 29 ms 3516 KiB
random_12.txt AC 57 ms 3416 KiB
random_13.txt AC 33 ms 3416 KiB
random_14.txt AC 17 ms 3412 KiB
random_15.txt AC 48 ms 3596 KiB
random_16.txt AC 105 ms 3480 KiB
random_17.txt AC 37 ms 3408 KiB
random_18.txt AC 49 ms 3476 KiB
random_19.txt AC 37 ms 3596 KiB
random_20.txt AC 126 ms 3476 KiB
random_21.txt AC 2 ms 3564 KiB
random_22.txt AC 75 ms 3548 KiB
random_23.txt AC 3 ms 3480 KiB
random_24.txt AC 8 ms 3592 KiB
random_25.txt AC 2 ms 3620 KiB
random_26.txt AC 15 ms 3464 KiB
random_27.txt AC 2 ms 3620 KiB
random_28.txt AC 127 ms 3424 KiB
random_29.txt AC 14 ms 3596 KiB
random_30.txt AC 110 ms 3548 KiB
sample_01.txt AC 12 ms 3600 KiB
sample_02.txt AC 9 ms 3424 KiB
sample_03.txt AC 48 ms 3548 KiB
sample_04.txt AC 3 ms 3616 KiB
sample_05.txt AC 69 ms 3480 KiB