結果

問題 No.2500 Products in a Range
ユーザー 沙耶花沙耶花
提出日時 2023-10-13 21:15:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,411 bytes
コンパイル時間 4,548 ms
コンパイル使用メモリ 263,404 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 21:15:28
合計ジャッジ時間 7,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 7 ms
4,348 KB
testcase_08 AC 22 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 19 ms
4,352 KB
testcase_11 AC 24 ms
4,348 KB
testcase_12 AC 10 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 26 ms
4,352 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 18 ms
4,352 KB
testcase_17 AC 10 ms
4,352 KB
testcase_18 AC 11 ms
4,352 KB
testcase_19 AC 23 ms
4,352 KB
testcase_20 AC 26 ms
4,348 KB
testcase_21 AC 4 ms
4,352 KB
testcase_22 AC 28 ms
4,348 KB
testcase_23 AC 27 ms
4,352 KB
testcase_24 AC 27 ms
4,352 KB
testcase_25 AC 35 ms
4,348 KB
testcase_26 AC 35 ms
4,352 KB
testcase_27 AC 35 ms
4,348 KB
testcase_28 AC 21 ms
4,348 KB
testcase_29 AC 6 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 9 ms
4,348 KB
testcase_34 AC 21 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 1 ms
4,352 KB
testcase_41 AC 1 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 1 ms
4,348 KB
testcase_44 AC 7 ms
4,348 KB
testcase_45 AC 2 ms
4,352 KB
testcase_46 AC 9 ms
4,348 KB
testcase_47 AC 35 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,352 KB
testcase_50 AC 10 ms
4,348 KB
testcase_51 AC 11 ms
4,348 KB
testcase_52 AC 22 ms
4,352 KB
testcase_53 AC 5 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 9 ms
4,348 KB
testcase_56 AC 11 ms
4,348 KB
testcase_57 AC 26 ms
4,348 KB
testcase_58 AC 5 ms
4,352 KB
testcase_59 AC 24 ms
4,352 KB
testcase_60 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){
	
	long long n,l,r;
	cin>>n>>l>>r;
	vector<long long> a(n);
	rep(i,n)cin>>a[i];
	sort(a.begin(),a.end());


	int ans = 0;
	rep(_,2){
		vector<long long> t;
		rep(i,n){
			if(_==0&&a[i]>=0)t.push_back(a[i]);
			if(_==1&&a[i]<=0)t.push_back(a[i]);
		}
		if(t.size()==0)continue;
		vector<int> dp(t.size(),1);
		rep(i,dp.size()){
			for(int j=i+1;j<dp.size();j++){
				long long v = t[i] * t[j];
				if(l<=v && v<=r)dp[j] = max(dp[j],dp[i]+1);
				
			}
		}
		ans = max(ans,*max_element(dp.begin(),dp.end()));
		
	}
	
	vector<long long> x,y;
	rep(i,n){
		if(a[i]<=0)x.push_back(a[i]);
		else y.push_back(a[i]);
	}
	if(x.size()>0 && y.size()>0){
		vector<int> dp0(x.size(),1),dp1(y.size(),1);
		for(int i=x.size()-1;i>=0;i--){
			for(int j=i-1;j>=0;j--){
				long long v = x[i] * x[j];
				if(l<=v && v<=r)dp0[j] = max(dp0[j],dp0[i]+1);
			}
		}
		rep(i,y.size()){
			for(int j=i+1;j<y.size();j++){
				long long v = y[i]*y[j];
				if(l<=v&&v<=r)dp1[j] = max(dp1[j],dp1[i]+1);
			}
		}
		rep(i,x.size()){
			rep(j,y.size()){
				long long v = x[i] * y[j];
				if(l<=v&&v<=r)ans = max(ans,dp0[i] + dp1[j]);
			}
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
0