結果

問題 No.1515 Making Many Multiples
ユーザー momoyuumomoyuu
提出日時 2023-04-28 14:32:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 3,123 ms
コンパイル使用メモリ 250,832 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-04-28 19:41:56
合計ジャッジ時間 5,298 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 20 ms
6,940 KB
testcase_02 AC 92 ms
18,944 KB
testcase_03 AC 85 ms
19,072 KB
testcase_04 AC 105 ms
18,688 KB
testcase_05 AC 105 ms
19,200 KB
testcase_06 AC 39 ms
19,200 KB
testcase_07 AC 37 ms
19,072 KB
testcase_08 AC 50 ms
10,624 KB
testcase_09 AC 68 ms
13,824 KB
testcase_10 AC 62 ms
14,080 KB
testcase_11 AC 74 ms
16,000 KB
testcase_12 AC 60 ms
12,800 KB
testcase_13 AC 21 ms
6,940 KB
testcase_14 AC 72 ms
16,640 KB
testcase_15 AC 22 ms
6,940 KB
testcase_16 AC 85 ms
18,304 KB
testcase_17 AC 6 ms
6,944 KB
testcase_18 AC 4 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 15 ms
7,424 KB
testcase_21 AC 27 ms
12,416 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 29 ms
13,440 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 51 ms
18,560 KB
testcase_28 AC 14 ms
11,136 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 13 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define chmax(a,b) a = max(a,b)

pair<int,int> calc(int a,int b){
    return make_pair(min(a,b),max(a,b));
}
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];
    vector<int> b(n+2);
    x %= k;
    y %= k;
    b[0] = x % k;
    b[1] = y % k;
    for(int i = 0;i<n;i++) b[i+2] = a[i] % k;
    int ans = 0;
    vector<vector<int>> tmp(n+2,vector<int>(k+1,-1e9));
    tmp[0][y] = 0;
    tmp[1][x] = 0;
    vector<int> cnt(n+2,0);
    for(int i = 0;i<n;i++){
        int now = b[i+2];
        for(int j = 0;j<i+2;j++){
            int nxt = b[j];
            int need = 2 * k - nxt - now;
            need %= k;
            if(tmp[j][need]>=0){
                int can = max(tmp[j][need]+1,cnt[j]);
                chmax(tmp[i+2][nxt],can);
                chmax(cnt[i+2],can);
                chmax(cnt[j],can);
                chmax(tmp[j][need],tmp[j][need]+1);
                chmax(tmp[j][now],can);
                ans = max(ans,can);
            }else{
                int can = cnt[j];
                chmax(tmp[i+2][nxt],can);
                chmax(cnt[i+2],can);
                chmax(tmp[j][now],can);
                ans = max(ans,can);
            }
        }
    }
    cout<<ans<<endl;
}
0