Submission #2972983


Source Code Expand

#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define int unsigned long long
#define sqr(a) ((a) * (a))

void solve () {
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size ();
    vector <vector <int>> d (n, vector <int> (2, 0));
    for (int i = 0; i < n; ++i) {
        if (a[i] == '?' && b[i] == '?') {
            for (int an = 0; an < 10; ++an) {
                for (int bn = 0; bn < 10; ++bn) {
                    for (int cn = 0; cn < 2; ++cn) {
                        if (i == 0 && (an == 0 || bn == 0)) continue;
                        if ((an + bn + cn) % 10 == c[i] - '0' || c[i] == '?') {
                            if (an + bn + cn >= 10) d[i][cn] = (i == 0 ? d[i][cn] : (d[i][cn] + d[i - 1][1]) % 1000000007);
                            else d[i][cn] = (i == 0 ? d[i][cn] + 1 : (d[i][cn] + d[i - 1][0]) % 1000000007);
                        }
                    }
                }
            }
        }
        else if (a[i] == '?') {
            for (int an = 0; an < 10; ++an) {
                for (int cn = 0; cn < 2; ++cn) {
                    if (i == 0 && (an == 0)) continue;
                    if ((an + b[i] - '0' + cn) % 10 == c[i] - '0' || c[i] == '?') {
                        if (an + b[i] - '0' + cn >= 10) d[i][cn] = (i == 0 ? d[i][cn] : (d[i][cn] + d[i - 1][1]) % 1000000007);
                        else d[i][cn] = (i == 0 ? d[i][cn] + 1 : (d[i][cn] + d[i - 1][0]) % 1000000007);
                    }
                }
            }
        }
        else if (b[i] == '?') {
            for (int bn = 0; bn < 10; ++bn) {
                for (int cn = 0; cn < 2; ++cn) {
                    if (i == 0 && (bn == 0)) continue;
                    if ((a[i] - '0' + bn + cn) % 10 == c[i] - '0' || c[i] == '?') {
                        if (a[i] - '0' + bn + cn >= 10) d[i][cn] = (i == 0 ? d[i][cn] : (d[i][cn] + d[i - 1][1]) % 1000000007);
                        else d[i][cn] = (i == 0 ? d[i][cn] + 1 : (d[i][cn] + d[i - 1][0]) % 1000000007);
                    }
                }
            }
        }
        else {
            for (int cn = 0; cn < 2; ++cn) {

                if ((a[i] - '0' + b[i] - '0' + cn) % 10 == c[i] - '0' || c[i] == '?') {
                    if ((a[i] - '0' + b[i] - '0' + cn) > 10) d[i][cn] = (i == 0 ? d[i][cn] : (d[i][cn] + d[i - 1][1]) % 1000000007);
                    else d[i][cn] = (i == 0 ? d[i][cn] + 1 : (d[i][cn] + d[i - 1][0]) % 1000000007);
                }
            }
        }
        d[i][0] %= 1000000007;
        d[i][1] %= 1000000007;
    }
    cout << d[n - 1][0] % 1000000007;
}

signed main (int argc, char *argv[]) {
    int test = 1;
    //cin >> test;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    while (test--)
        solve ();
    return 0;
}

Submission Info

Submission Time
Task B - Restore Calculation
User zakr608
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2912 Byte
Status WA
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp:64:8: warning: first argument of ‘int main(long long unsigned int, char**)’ should be ‘int’ [-Wmain]
 signed main (int argc, char *argv[]) {
        ^

Judge Result

Set Name all
Score / Max Score 0 / 100
Status
WA × 1
Set Name Test Cases
all Merged
Case Name Status Exec Time Memory
Merged WA 1 ms 256 KB