結果

問題 No.1515 Making Many Multiples
ユーザー 沙耶花沙耶花
提出日時 2021-05-21 22:10:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 1,127 bytes
コンパイル時間 4,458 ms
コンパイル使用メモリ 256,916 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-04-18 15:40:06
合計ジャッジ時間 7,189 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 169 ms
19,200 KB
testcase_03 AC 163 ms
19,456 KB
testcase_04 AC 157 ms
18,944 KB
testcase_05 AC 152 ms
19,200 KB
testcase_06 AC 124 ms
19,200 KB
testcase_07 AC 132 ms
19,328 KB
testcase_08 AC 39 ms
7,040 KB
testcase_09 AC 74 ms
10,880 KB
testcase_10 AC 76 ms
11,520 KB
testcase_11 AC 108 ms
14,336 KB
testcase_12 AC 61 ms
9,984 KB
testcase_13 AC 4 ms
6,944 KB
testcase_14 AC 112 ms
15,488 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 146 ms
18,176 KB
testcase_17 AC 24 ms
11,264 KB
testcase_18 AC 19 ms
13,952 KB
testcase_19 AC 5 ms
8,320 KB
testcase_20 AC 24 ms
7,936 KB
testcase_21 AC 91 ms
18,688 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 98 ms
18,816 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,940 KB
testcase_27 AC 133 ms
18,944 KB
testcase_28 AC 82 ms
18,816 KB
testcase_29 AC 4 ms
6,944 KB
testcase_30 AC 10 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

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];
		A[i] %= K;
	}
	
	vector dp(K,vector<int>(K,-Inf));
	dp[X][Y] = 0;
	dp[Y][X] = 0;
	
	vector<int> r(K,-Inf),c(K,-Inf);
	
	r[X] = 0;
	r[Y] = 0;
	c[X] = 0;
	c[Y] = 0;
	
	rep(i,N){
		rep(j,K){
			int t = -j-A[i];
			t += 3*K;
			t %= K;
			dp[j][t] ++;
			r[j] = max(r[j],dp[j][t]);
			c[t] = max(c[t],dp[j][t]);
		}
		
		rep(j,K){
			dp[j][A[i]] = max(dp[j][A[i]],r[j]);
			dp[A[i]][j] = max(dp[A[i]][j],c[j]);
		}
		
		rep(j,K){
			r[j] = max(r[j],dp[j][A[i]]);
			c[j] = max(c[j],dp[A[i]][j]);
			r[A[i]] = max(r[A[i]],dp[j][A[i]]);
			c[A[i]] = max(c[A[i]],dp[A[i]][j]);
		}
		
		/*
		rep(j,K){
			cout<<r[j]<<endl;
			rep(k,K){
				cout<<dp[j][k]<<',';
			}
			cout<<endl;
		}
		*/
		
	}
	
	int ans = 0;
	rep(i,K){
		ans = max(ans,r[i]);
		ans = max(ans,c[i]);
	}
	
	cout<<ans<<endl;
			
	return 0;
}
0