結果

問題 No.1515 Making Many Multiples
ユーザー yakkiyakki
提出日時 2021-05-22 05:59:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,504 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 120,984 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-18 17:22:24
合計ジャッジ時間 4,251 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
19,328 KB
testcase_01 AC 9 ms
19,340 KB
testcase_02 AC 123 ms
19,156 KB
testcase_03 AC 118 ms
19,220 KB
testcase_04 AC 134 ms
19,328 KB
testcase_05 AC 127 ms
19,328 KB
testcase_06 AC 62 ms
19,328 KB
testcase_07 AC 82 ms
19,360 KB
testcase_08 AC 42 ms
19,404 KB
testcase_09 AC 68 ms
19,328 KB
testcase_10 AC 72 ms
19,328 KB
testcase_11 AC 90 ms
19,424 KB
testcase_12 AC 57 ms
19,328 KB
testcase_13 AC 10 ms
19,280 KB
testcase_14 AC 88 ms
19,404 KB
testcase_15 AC 9 ms
19,344 KB
testcase_16 AC 127 ms
19,288 KB
testcase_17 AC 22 ms
19,456 KB
testcase_18 AC 17 ms
19,428 KB
testcase_19 AC 9 ms
19,328 KB
testcase_20 AC 23 ms
19,456 KB
testcase_21 AC 90 ms
19,276 KB
testcase_22 AC 8 ms
19,200 KB
testcase_23 AC 86 ms
19,368 KB
testcase_24 AC 7 ms
19,328 KB
testcase_25 AC 8 ms
19,456 KB
testcase_26 AC 8 ms
19,328 KB
testcase_27 AC 79 ms
19,340 KB
testcase_28 AC 45 ms
19,208 KB
testcase_29 AC 10 ms
19,200 KB
testcase_30 AC 14 ms
19,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int dp[2010][2010];
int mx[2010];

int main(){
    int n,k,x,y; cin >> n >> k >> x >> y;
    x %= k;
    y %= k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i] %= k;
    rep(i,2010)rep(j,2010) dp[i][j] = -INF;
    rep(i,2010) mx[i] = -INF;
    dp[x][y] = dp[y][x] = 0;
    mx[x] = mx[y] = 0;
    rep(i,n){
        rep(j,k){
            int s = (2*k-j-a[i])%k;
            if(dp[s][j] != -INF) dp[s][j]++;
            mx[j] = max(mx[j],dp[s][j]);
            mx[s] = max(mx[s],dp[s][j]);
        }
        rep(j,k){
            dp[a[i]][j] = max(dp[a[i]][j],mx[j]);
            dp[j][a[i]] = max(dp[j][a[i]],mx[j]);
        }
        rep(j,k) mx[a[i]] = max(mx[a[i]],mx[j]);
    }
    int ans = 0;
    rep(i,k)rep(j,k) ans = max(ans,dp[i][j]);
    cout << ans << endl;
}



0