結果

問題 No.1515 Making Many Multiples
ユーザー MisterMister
提出日時 2021-05-21 21:55:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,344 bytes
コンパイル時間 910 ms
コンパイル使用メモリ 83,404 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-04-18 15:16:45
合計ジャッジ時間 3,633 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 164 ms
18,944 KB
testcase_03 AC 134 ms
19,072 KB
testcase_04 AC 165 ms
18,560 KB
testcase_05 AC 163 ms
18,944 KB
testcase_06 AC 106 ms
18,944 KB
testcase_07 AC 118 ms
18,944 KB
testcase_08 AC 32 ms
6,940 KB
testcase_09 AC 66 ms
10,496 KB
testcase_10 AC 68 ms
11,136 KB
testcase_11 AC 95 ms
13,952 KB
testcase_12 AC 54 ms
9,600 KB
testcase_13 AC 4 ms
6,944 KB
testcase_14 AC 111 ms
15,232 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 125 ms
17,792 KB
testcase_17 AC 23 ms
11,008 KB
testcase_18 AC 19 ms
13,568 KB
testcase_19 AC 6 ms
7,808 KB
testcase_20 AC 22 ms
7,424 KB
testcase_21 AC 95 ms
18,304 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 90 ms
18,432 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 125 ms
18,432 KB
testcase_28 AC 68 ms
18,688 KB
testcase_29 AC 4 ms
6,944 KB
testcase_30 AC 8 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

constexpr int INF = 1 << 30;

void solve() {
    int n, k;
    cin >> n >> k;

    auto dp = vector(k, vector(k, -INF));
    vector<int> xmax(k, -INF), ymax(k, -INF);

    {
        int x, y;
        cin >> x >> y;
        x %= k, y %= k;

        dp[x][y] = dp[y][x] = 0;

        xmax[x] = xmax[y] = 0;
        ymax[x] = ymax[y] = 0;
    }

    while (n--) {
        int x;
        cin >> x;
        x %= k;

        for (int i = 0; i < k; ++i) {
            // i+j+x=0 mod k
            // j=-(i+x) mod k
            int j = -(i + x) % k;
            if (j < 0) j += k;

            ++dp[i][j];
            xmax[i] = max(xmax[i], dp[i][j]);
            ymax[j] = max(ymax[j], dp[i][j]);
        }

        auto pymax = ymax;
        for (int i = 0; i < k; ++i) {
            dp[i][x] = xmax[i];
            ymax[x] = max(ymax[x], dp[i][x]);
        }

        for (int j = 0; j < k; ++j) {
            dp[x][j] = pymax[j];
            xmax[x] = max(xmax[x], dp[x][j]);
        }
    }

    int ans = -INF;
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < k; ++j) {
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0