結果

問題 No.1515 Making Many Multiples
ユーザー chocoruskchocorusk
提出日時 2021-05-21 22:54:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 3,609 ms
コンパイル使用メモリ 186,540 KB
実行使用メモリ 19,472 KB
最終ジャッジ日時 2024-04-18 16:23:06
合計ジャッジ時間 5,618 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 28 ms
11,392 KB
testcase_02 AC 92 ms
19,456 KB
testcase_03 AC 75 ms
19,288 KB
testcase_04 AC 85 ms
19,456 KB
testcase_05 AC 82 ms
19,328 KB
testcase_06 AC 58 ms
19,456 KB
testcase_07 AC 65 ms
19,472 KB
testcase_08 AC 55 ms
18,432 KB
testcase_09 AC 61 ms
19,292 KB
testcase_10 AC 64 ms
18,688 KB
testcase_11 AC 66 ms
19,072 KB
testcase_12 AC 70 ms
18,688 KB
testcase_13 AC 29 ms
11,776 KB
testcase_14 AC 72 ms
18,720 KB
testcase_15 AC 30 ms
12,416 KB
testcase_16 AC 91 ms
19,200 KB
testcase_17 AC 9 ms
7,680 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 16 ms
10,880 KB
testcase_21 AC 32 ms
12,672 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 38 ms
13,696 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 75 ms
19,072 KB
testcase_28 AC 25 ms
11,392 KB
testcase_29 AC 5 ms
5,632 KB
testcase_30 AC 24 ms
12,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
int dp[2020][2020], mx[2020], mx2[2020];
int a[2020];
int n, k;
int main()
{
    cin>>n>>k>>a[0]>>a[1];
    for(int i=2; i<n+2; i++) cin>>a[i];
    for(int i=0; i<n+2; i++) a[i]%=k;
    const int INF=1e9;
    for(int i=0; i<n+2; i++) for(int j=0; j<k; j++) dp[i][j]=-INF;
    fill(mx, mx+k, -INF);
    fill(mx2, mx2+k, -INF);
    dp[0][(a[0]+a[1])%k]=0;
    mx[a[1]]=0;
    dp[1][(a[0]+a[1])%k]=0;
    mx[a[0]]=0;
    mx2[0]=0, mx2[1]=0;
    for(int i=2; i<n+2; i++){
        int r=(k-a[i])%k;
        for(int j=0; j<i; j++){
            dp[j][r]++;
            mx[(r+k-a[j])%k]=max(mx[(r+k-a[j])%k], dp[j][r]);
            mx2[j]=max(mx2[j], dp[j][r]);
        }
        for(int s=0; s<k; s++){
            int t=(s+r)%k;
            dp[i][s]=max(dp[i][s], mx[t]);
        }
        for(int j=0; j<i; j++){
            dp[j][(a[j]+a[i])%k]=max(dp[j][(a[j]+a[i])%k], mx2[j]);
        }
        for(int s=0; s<k; s++){
            int t=(s+r)%k;
            mx[t]=max(mx[t], dp[i][s]);
            mx2[i]=max(mx2[i], dp[i][s]);
        }
    }
    int ans=0;
    for(int i=0; i<k; i++) ans=max(ans, dp[n+1][i]);
    cout<<ans<<endl;
    return 0;
}
0