結果
| 問題 |
No.2500 Products in a Range
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-16 21:47:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,137 bytes |
| コンパイル時間 | 916 ms |
| コンパイル使用メモリ | 78,608 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 22:17:59 |
| 合計ジャッジ時間 | 2,408 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 61 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int N;
long L,R;
int ans=1;
vector<int>f(vector<long>&A)
{
sort(A.begin(),A.end());
vector<int>l(A.size());
for(int i=0;i<A.size();i++)
{
l[i]=i;
for(int j=i-1;j>=0;j--)
{
long v=A[i]*A[j];
if(L<=v&&v<=R)
{
ans=max(ans,2);
if(l[i]==j+1)
{
long vv=A[j]*A[j+1];
if(L<=vv&&vv<=R)
{
l[i]=j;
ans=max(ans,i-j+1);
}
}
}
}
}
return l;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>N>>L>>R;
vector<long>pos,neg;
int zero=0;
for(int i=0;i<N;i++)
{
long A;
cin>>A;
if(A==0)zero++;
else if(A>0)pos.push_back(A);
else neg.push_back(-A);
}
vector<int>pl=f(pos),nl=f(neg);
for(long p:pos)for(long n:neg)
{
long v=p*-n;
if(L<=v&&v<=R)ans=max(ans,2);
}
if(R>=1&&L<=-1)
{
for(int i=0;i<pos.size();i++)
{
if(i>0&&pos[i-1]*pos[i]>R)continue;
for(int j=0;j<neg.size();j++)
{
if(j>0&&neg[j-1]*neg[j]>R)continue;
if(pos[i]*neg[j]<=-L)ans=max(ans,i+1+j+1);
}
}
}
if(L<=0&&0<=R)ans+=zero;
cout<<min(ans,N)<<endl;
}