結果

問題 No.1515 Making Many Multiples
ユーザー SSRSSSRS
提出日時 2021-05-21 21:49:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 1,742 ms
コンパイル使用メモリ 175,652 KB
実行使用メモリ 19,180 KB
最終ジャッジ日時 2023-07-31 15:04:02
合計ジャッジ時間 5,128 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 153 ms
19,068 KB
testcase_03 AC 157 ms
19,180 KB
testcase_04 AC 152 ms
18,864 KB
testcase_05 AC 163 ms
19,104 KB
testcase_06 AC 119 ms
19,172 KB
testcase_07 AC 126 ms
19,136 KB
testcase_08 AC 47 ms
6,848 KB
testcase_09 AC 87 ms
10,996 KB
testcase_10 AC 89 ms
11,296 KB
testcase_11 AC 114 ms
14,332 KB
testcase_12 AC 75 ms
9,720 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 129 ms
15,440 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 144 ms
17,916 KB
testcase_17 AC 30 ms
11,208 KB
testcase_18 AC 23 ms
13,748 KB
testcase_19 AC 7 ms
8,184 KB
testcase_20 AC 32 ms
7,856 KB
testcase_21 AC 93 ms
18,552 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 108 ms
18,568 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 126 ms
18,888 KB
testcase_28 AC 77 ms
18,892 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 15 ms
4,376 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