結果

問題 No.2593 Reorder and Mod 120
ユーザー suisensuisen
提出日時 2023-12-21 18:17:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 33,664 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-21 18:17:02
合計ジャッジ時間 1,483 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 3 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>

// mod 3: constant
// mod 5: determined only by the lowest one digit
// mod 8: determined only by the lowest three digits

int main() {
    int n;
    std::scanf("%d", &n);
    char s[200000]{};
    std::scanf("%s", s);
    int cnt[10]{}, flg[40]{};
    for (int i = 0; i < n; ++i) ++cnt[s[i] - '0'];
    for (int x = 1; x <= 9; ++x) {
        --cnt[x];
        for (int y = 1; y <= 9; ++y) {
            if (n <= 1) y = 0;
            else --cnt[y];
            for (int z = 1; z <= 9; ++z) {
                if (n <= 2) z = 0;
                else --cnt[z];
                if (cnt[x] >= 0 and cnt[y] >= 0 and cnt[z] >= 0) {
                    int mod8 = (100 * z + 10 * y + x) % 8;
                    int mod5 = x % 5;
                    flg[mod8 * 5 + mod5] = 1;
                }
                if (n <= 2) break;
                else ++cnt[z];
            }
            if (n <= 1) break;
            else ++cnt[y];
        }
        ++cnt[x];
    }
    int ans = 0;
    for (int v = 0; v < 40; ++v) ans += flg[v];
    std::printf("%d\n", ans);
}
0