結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 22 ms
6,944 KB
testcase_02 WA -
testcase_03 AC 86 ms
19,072 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 41 ms
19,200 KB
testcase_07 AC 36 ms
19,200 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 49 ms
18,560 KB
testcase_28 AC 15 ms
11,136 KB
testcase_29 AC 4 ms
6,944 KB
testcase_30 AC 15 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(tmp[i+2][need],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