結果
| 問題 | No.1515 Making Many Multiples |
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-04-28 13:54:04 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,596 bytes |
| 記録 | |
| コンパイル時間 | 3,926 ms |
| コンパイル使用メモリ | 273,728 KB |
| 実行使用メモリ | 90,688 KB |
| 最終ジャッジ日時 | 2024-11-17 14:19:22 |
| 合計ジャッジ時間 | 45,574 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 9 TLE * 11 |
ソースコード
#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;
}
momoyuu