結果

問題 No.2593 Reorder and Mod 120
ユーザー ldsybldsyb
提出日時 2023-12-24 20:07:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 4,843 ms
コンパイル使用メモリ 271,348 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-24 20:07:55
合計ジャッジ時間 5,894 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 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 6 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 5 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 3 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 6 ms
6,676 KB
testcase_21 AC 7 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 6 ms
6,676 KB
testcase_24 AC 7 ms
6,676 KB
testcase_25 AC 6 ms
6,676 KB
testcase_26 AC 6 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

int main()
{
    int64_t n;
    string s;
    cin >> n >> s;

    if (n < 3)
    {
        set<int64_t> st;

        sort(s.begin(), s.end());
        do
        {
            int64_t x = 0;
            for (auto &&c : s)
            {
                x *= 10;
                x += c - '0';
            }

            st.insert(x % 120);
        } while (next_permutation(s.begin(), s.end()));

        cout << st.size() << endl;
        return 0;
    }

    vector<int64_t> cnt(10, 0);
    for (auto &&c : s)
    {
        cnt[c - '0']++;
    }

    set<int64_t> st;

    for (int64_t a = 0; a < 10; a++)
    {
        for (int64_t b = 0; b < 10; b++)
        {
            for (int64_t c = 0; c < 10; c++)
            {
                cnt[a]--;
                cnt[b]--;
                cnt[c]--;

                if (cnt[a] < 0 || cnt[b] < 0 || cnt[c] < 0)
                {
                    cnt[a]++;
                    cnt[b]++;
                    cnt[c]++;

                    continue;
                }

                st.insert((100 * a + 10 * b + c) % 40);

                cnt[a]++;
                cnt[b]++;
                cnt[c]++;
            }
        }
    }

    cout << st.size() << endl;

    return 0;
}
0