結果
| 問題 | No.2593 Reorder and Mod 120 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-12-21 18:17:00 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 1,075 bytes | 
| コンパイル時間 | 373 ms | 
| コンパイル使用メモリ | 29,440 KB | 
| 最終ジャッジ日時 | 2025-02-18 13:06:25 | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 26 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     std::scanf("%d", &n);
      |     ~~~~~~~~~~^~~~~~~~~~
main.cpp:11:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     std::scanf("%s", s);
      |     ~~~~~~~~~~^~~~~~~~~
            
            ソースコード
#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);
}
            
            
            
        