結果

問題 No.2784 繰り上がりなし十進和
ユーザー ゼット
提出日時 2024-06-14 22:12:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,868 ms / 2,000 ms
コード長 1,523 bytes
コンパイル時間 1,386 ms
コンパイル使用メモリ 103,740 KB
最終ジャッジ日時 2025-02-21 22:04:54
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <string>
#include <cmath>

using namespace std;

// Function to add two strings representing numbers digit by digit and mod by 10
string f(const string& a, const string& b) {
    string c = "";
    for (int i = 0; i < 6; ++i) {
        int x = (a[i] - '0') + (b[i] - '0');
        x %= 10;
        c += to_string(x);
    }
    return c;
}

int main() {
    set<string> L;
    vector<string> K(6);
    
    // Read input strings
    for (int i = 0; i < 6; ++i) {
        cin >> K[i];
    }

    vector<int> dp(1000001, 0);
    deque<string> S;

    // Initialize the deque with unique strings
    for (const string& s : K) {
        int x = 0;
        for (int i = 0; i < 6; ++i) {
            x += (s[5 - i] - '0') * pow(10, i);
        }
        if (dp[x] == 0) {
            dp[x] = 1;
            S.push_back(s);
        }
    }

    // Process the deque
    while (!S.empty()) {
        string h = S.back();
        S.pop_back();
        for (int i = 0; i < 6; ++i) {
            string s = K[i];
            string b = f(h, s);
            int x = 0;
            for (int j = 0; j < 6; ++j) {
                x += (b[5 - j] - '0') * pow(10, j);
            }
            if (dp[x] == 0) {
                dp[x] = 1;
                S.push_back(b);
            }
        }
    }

    // Sum the dp array
    int result = 0;
    for (int i = 0; i < 1000000; ++i) {
        result += dp[i];
    }

    cout << result << endl;

    return 0;
}
0