提出 #72913829


ソースコード 拡げる

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 2e5 + 10;
int dx[]{-1, -1, -1};
int dy[]{-1, 0, 1};

void solve()
{
    int n;
    cin >> n;
    if (n % 10 == 0)
    {
        cout << -1 << "\n";
        return;
    }
    vector<vector<int>> vis(10, vector<int>(n + 1, -1));
    vector<vector<int>> res(10, vector<int>(n + 1, 0));
    vector<vector<int>> len(10, vector<int>(n + 1, 1e9));

    vector<int> ans;
    queue<array<int, 2>> q;
    q.push({0, 0});
    len[0][0] = 0;
    int now = 0;
    while (q.size())
    {
        auto [pre, mod] = q.front();
        q.pop();
        if (mod == 0 and pre != 0)
        {
            now = pre;
            break;
        }
        for (int i = max(1ll, pre); i <= 9; i++)
        {
            if (vis[i][(mod * 10 + i) % n] == -1)
            {
                q.push({i, (mod * 10 + i) % n});
                vis[i][(mod * 10 + i) % n] = pre;
                res[i][(mod * 10 + i) % n] = mod;
                len[i][(mod * 10 + i) % n] = len[pre][mod] + 1;
            }
        }
    }

    // int minn = 1e9;
    // for (int i = 1; i <= 9; i++)
    // {
    //     if (minn > len[i][0])
    //     {
    //         minn = len[i][0];
    //         now = i;
    //     }
    // }
    if (now == 0)
    {
        cout << -1 << '\n';
        return;
    }
    ans.push_back(now);
    int mod = res[now][0];
    now = vis[now][0];
    while (now != 0)
    {
        ans.push_back(now);
        int temp = vis[now][mod];
        mod = res[now][mod];
        now = temp;
    }

    for (int i = ans.size() - 1; i >= 0; i--)
        cout << ans[i];
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    while (T--)
        solve();

    return 0;
}

提出情報

提出日時
問題 F - Non-Increasing Number
ユーザ Hirasawaa
言語 C++23 (GCC 15.2.0)
得点 525
コード長 1876 Byte
結果 AC
実行時間 1442 ms
メモリ 730060 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 525 / 525
結果
AC × 4
AC × 67
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_max_00.txt, 01_max_01.txt, 01_max_02.txt, 01_max_03.txt, 01_max_04.txt, 01_max_05.txt, 01_max_06.txt, 01_max_07.txt, 01_max_08.txt, 01_max_09.txt, 01_max_10.txt, 01_max_11.txt, 01_max_12.txt, 01_max_13.txt, 01_max_14.txt, 01_max_15.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt, 03_handmade_09.txt, 03_handmade_10.txt, 03_handmade_11.txt, 03_handmade_12.txt, 03_handmade_13.txt, 03_handmade_14.txt, 03_handmade_15.txt, 03_handmade_16.txt, 03_handmade_17.txt, 03_handmade_18.txt, 03_handmade_19.txt, 03_handmade_20.txt, 03_handmade_21.txt, 03_handmade_22.txt, 03_handmade_23.txt, 03_handmade_24.txt, 03_handmade_25.txt, 03_handmade_26.txt, 03_handmade_27.txt, 03_handmade_28.txt, 03_handmade_29.txt, 03_handmade_30.txt, 03_handmade_31.txt, 03_handmade_32.txt, 03_handmade_33.txt, 03_handmade_34.txt, 03_handmade_35.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3600 KiB
00_sample_01.txt AC 1 ms 3580 KiB
00_sample_02.txt AC 1 ms 3588 KiB
00_sample_03.txt AC 1 ms 3848 KiB
01_max_00.txt AC 732 ms 729816 KiB
01_max_01.txt AC 924 ms 729928 KiB
01_max_02.txt AC 726 ms 729944 KiB
01_max_03.txt AC 735 ms 729948 KiB
01_max_04.txt AC 746 ms 729896 KiB
01_max_05.txt AC 791 ms 729680 KiB
01_max_06.txt AC 1 ms 3440 KiB
01_max_07.txt AC 396 ms 729944 KiB
01_max_08.txt AC 417 ms 730000 KiB
01_max_09.txt AC 403 ms 729840 KiB
01_max_10.txt AC 417 ms 729984 KiB
01_max_11.txt AC 483 ms 730060 KiB
01_max_12.txt AC 410 ms 730024 KiB
01_max_13.txt AC 568 ms 729952 KiB
01_max_14.txt AC 415 ms 729928 KiB
01_max_15.txt AC 469 ms 729972 KiB
02_random_00.txt AC 303 ms 273976 KiB
02_random_01.txt AC 485 ms 401228 KiB
02_random_02.txt AC 566 ms 705216 KiB
02_random_03.txt AC 401 ms 350764 KiB
02_random_04.txt AC 429 ms 666840 KiB
02_random_05.txt AC 119 ms 227868 KiB
02_random_06.txt AC 1 ms 3540 KiB
02_random_07.txt AC 31 ms 51788 KiB
02_random_08.txt AC 587 ms 612848 KiB
02_random_09.txt AC 120 ms 224544 KiB
02_random_10.txt AC 68 ms 110708 KiB
03_handmade_00.txt AC 1 ms 3588 KiB
03_handmade_01.txt AC 1 ms 3552 KiB
03_handmade_02.txt AC 1 ms 3400 KiB
03_handmade_03.txt AC 1 ms 3396 KiB
03_handmade_04.txt AC 1 ms 3596 KiB
03_handmade_05.txt AC 211 ms 245488 KiB
03_handmade_06.txt AC 148 ms 245468 KiB
03_handmade_07.txt AC 135 ms 136748 KiB
03_handmade_08.txt AC 242 ms 158964 KiB
03_handmade_09.txt AC 336 ms 203476 KiB
03_handmade_10.txt AC 194 ms 245556 KiB
03_handmade_11.txt AC 199 ms 243420 KiB
03_handmade_12.txt AC 1 ms 3976 KiB
03_handmade_13.txt AC 77 ms 92308 KiB
03_handmade_14.txt AC 85 ms 69952 KiB
03_handmade_15.txt AC 25 ms 25424 KiB
03_handmade_16.txt AC 1 ms 3884 KiB
03_handmade_17.txt AC 700 ms 726800 KiB
03_handmade_18.txt AC 697 ms 723476 KiB
03_handmade_19.txt AC 680 ms 702208 KiB
03_handmade_20.txt AC 654 ms 676832 KiB
03_handmade_21.txt AC 636 ms 660212 KiB
03_handmade_22.txt AC 587 ms 725404 KiB
03_handmade_23.txt AC 429 ms 488680 KiB
03_handmade_24.txt AC 590 ms 701652 KiB
03_handmade_25.txt AC 458 ms 594012 KiB
03_handmade_26.txt AC 384 ms 601124 KiB
03_handmade_27.txt AC 1029 ms 553340 KiB
03_handmade_28.txt AC 831 ms 453256 KiB
03_handmade_29.txt AC 582 ms 507628 KiB
03_handmade_30.txt AC 349 ms 364384 KiB
03_handmade_31.txt AC 257 ms 246036 KiB
03_handmade_32.txt AC 1231 ms 729940 KiB
03_handmade_33.txt AC 1442 ms 728756 KiB
03_handmade_34.txt AC 1398 ms 727264 KiB
03_handmade_35.txt AC 1331 ms 727076 KiB