結果

問題 No.1515 Making Many Multiples
ユーザー beetbeet
提出日時 2021-05-21 22:14:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 1,588 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 198,292 KB
実行使用メモリ 19,320 KB
最終ジャッジ日時 2024-04-18 15:43:35
合計ジャッジ時間 5,235 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
18,968 KB
testcase_01 AC 8 ms
19,172 KB
testcase_02 AC 214 ms
19,200 KB
testcase_03 AC 158 ms
19,168 KB
testcase_04 AC 164 ms
19,216 KB
testcase_05 AC 173 ms
19,212 KB
testcase_06 AC 106 ms
19,212 KB
testcase_07 AC 121 ms
18,984 KB
testcase_08 AC 45 ms
19,200 KB
testcase_09 AC 84 ms
19,200 KB
testcase_10 AC 78 ms
19,200 KB
testcase_11 AC 114 ms
19,132 KB
testcase_12 AC 66 ms
19,316 KB
testcase_13 AC 10 ms
19,296 KB
testcase_14 AC 127 ms
19,040 KB
testcase_15 AC 10 ms
19,152 KB
testcase_16 AC 149 ms
19,296 KB
testcase_17 AC 30 ms
19,220 KB
testcase_18 AC 24 ms
19,320 KB
testcase_19 AC 11 ms
19,200 KB
testcase_20 AC 28 ms
19,200 KB
testcase_21 AC 105 ms
19,208 KB
testcase_22 AC 8 ms
19,188 KB
testcase_23 AC 102 ms
19,200 KB
testcase_24 AC 6 ms
19,192 KB
testcase_25 AC 7 ms
19,072 KB
testcase_26 AC 7 ms
19,200 KB
testcase_27 AC 136 ms
19,172 KB
testcase_28 AC 72 ms
19,196 KB
testcase_29 AC 10 ms
19,200 KB
testcase_30 AC 16 ms
19,108 KB
権限があれば一括ダウンロードができます

ソースコード

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