結果

問題 No.1515 Making Many Multiples
ユーザー beet
提出日時 2021-05-21 22:14:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,588 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 195,812 KB
最終ジャッジ日時 2025-01-21 15:30:32
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
const int MAX = 2002;
int dp[MAX][MAX];
int mx[MAX];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,k,x,y;
  cin>>n>>k>>x>>y;
  auto as=read(n);
  x%=k;
  y%=k;
  for(int &a:as) a%=k;

  for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
      dp[i][j]=-1e9;

  for(int i=0;i<MAX;i++) mx[i]=-1e9;

  dp[x][y]=dp[y][x]=0;
  mx[x]=mx[y]=0;

  for(int a:as){
    for(int i=0;i<k;i++){
      int j=(k+(-i-a)%k)%k;
      dp[i][j]++;
      chmax(mx[i],dp[i][j]);
      chmax(mx[j],dp[i][j]);
      //cout<<i<<' '<<j<<' '<<a<<':'<<dp[i][j]<<endl;
    }

    for(int i=0;i<k;i++){
      chmax(dp[i][a],mx[i]);
      chmax(dp[a][i],mx[i]);
    }

    for(int i=0;i<k;i++){
      chmax(mx[i],dp[i][a]);
      chmax(mx[i],dp[a][i]);
      chmax(mx[a],dp[a][i]);
      chmax(mx[a],dp[i][a]);
    }

    continue;
    for(int i=0;i<k;i++)
      for(int j=0;j<k;j++)
        if(dp[i][j]>=0) cout<<i<<' '<<j<<':'<<dp[i][j]<<endl;
    for(int i=0;i<k;i++) cout<<i<<':'<<mx[i]<<endl;
    cout<<endl;
  }

  int ans=0;
  for(int i=0;i<k;i++)
    for(int j=0;j<k;j++)
      chmax(ans,dp[i][j]);
  cout<<ans<<newl;
  return 0;
}
0