結果

問題 No.1515 Making Many Multiples
ユーザー momoyuumomoyuu
提出日時 2023-04-28 13:54:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,596 bytes
コンパイル時間 4,083 ms
コンパイル使用メモリ 274,332 KB
実行使用メモリ 80,672 KB
最終ジャッジ日時 2024-04-28 19:17:11
合計ジャッジ時間 8,124 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 34 ms
6,940 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define chmax(a,b) a = max(a,b)

pair<int,int> calc(int a,int b){
    return make_pair(min(a,b),max(a,b));
}
int main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    vector<int> a(n);
    for(int i = 0;i<n;i++) cin>>a[i];
    map<pair<int,int>,int> d;
    vector<int> b(n+2);
    x %= k;
    y %= k;
    b[0] = x % k;
    b[1] = y % k;
    for(int i = 0;i<n;i++) b[i+2] = a[i] % k;
    map<int,set<pair<int,int>>>s;
    d[make_pair(min(x,y),max(x,y))] = 0;
    s[(x+y)%k].insert(make_pair(min(x,y),max(x,y)));
    int ans = 0;
    vector<int> tmp(n+2,0);
    for(int i = 0;i<n;i++){
        int now = b[i+2];
        int need = 2 * k - now;
        need %= k;
        //cout<<i<<" "<<need<<endl;
        vector<pair<int,pair<int,int>>>use;
        for(auto itr:s[need]){
            int aa = itr.first;
            int bb = itr.second;
            int can = d[itr];
            ans = max(ans,can+1);
            use.push_back(make_pair(can+1,calc(aa,now)));
            use.push_back(make_pair(can+1,calc(bb,now)));
            chmax(tmp[i+2],can+1);
            //cout<<aa<<" "<<bb<<" "<<can+1<<" "<<i<<endl;
        }
        for(auto&itr:use){
            chmax(d[itr.second],itr.first);
            s[(itr.second.first+itr.second.second)%k].insert(itr.second);
        }
        for(int j = 0;j<i+2;j++){
            s[(now+b[j])%k].insert(calc(b[j],now));
            chmax(d[calc(now,b[j])],tmp[j]);
            chmax(tmp[i+2],tmp[j]);
        }
    }
    //for(int i = 0;i<n+2;i++) cout<<tmp[i]<<endl;
    cout<<ans<<endl;
}
0