結果

問題 No.1515 Making Many Multiples
ユーザー SSRSSSRS
提出日時 2021-05-21 21:49:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 172,740 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-18 15:05:08
合計ジャッジ時間 5,030 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 187 ms
19,456 KB
testcase_03 AC 197 ms
19,456 KB
testcase_04 AC 179 ms
19,200 KB
testcase_05 AC 181 ms
19,456 KB
testcase_06 AC 125 ms
19,328 KB
testcase_07 AC 128 ms
19,456 KB
testcase_08 AC 53 ms
7,168 KB
testcase_09 AC 99 ms
11,136 KB
testcase_10 AC 109 ms
11,520 KB
testcase_11 AC 146 ms
14,208 KB
testcase_12 AC 87 ms
9,856 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 161 ms
15,744 KB
testcase_15 AC 6 ms
6,940 KB
testcase_16 AC 176 ms
18,048 KB
testcase_17 AC 32 ms
11,392 KB
testcase_18 AC 27 ms
13,952 KB
testcase_19 AC 9 ms
8,448 KB
testcase_20 AC 40 ms
8,064 KB
testcase_21 AC 119 ms
18,816 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 127 ms
18,816 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 137 ms
19,072 KB
testcase_28 AC 76 ms
18,944 KB
testcase_29 AC 7 ms
6,940 KB
testcase_30 AC 16 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
int main(){
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    A[i] %= K;
  }
  vector<vector<int>> dp(K, vector<int>(K, -INF));
  dp[X % K][Y % K] = 0;
  vector<int> r(K, -INF), c(K, -INF);
  r[X % K] = 0;
  c[Y % K] = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < K; j++){
      int k = (K * 2 - j - A[i]) % K;
      dp[j][k]++;
      r[j] = max(r[j], dp[j][k]);
      c[k] = max(c[k], dp[j][k]);
    }
    vector<tuple<int, int, int>> T;
    for (int j = 0; j < K; j++){
      T.push_back(make_tuple(A[i], j, r[j]));
      T.push_back(make_tuple(A[i], j, c[j]));
    }
    for (int j = 0; j < K * 2; j++){
      int r2 = get<0>(T[j]);
      int c2 = get<1>(T[j]);
      int x = get<2>(T[j]);
      dp[r2][c2] = max(dp[r2][c2], x);
      r[r2] = max(r[r2], x);
      c[c2] = max(c[c2], x);
    }
  }
  int ans = 0;
  for (int i = 0; i < K; i++){
    for (int j = 0; j < K; j++){
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
}
0