結果

問題 No.2500 Products in a Range
ユーザー baluteshihbaluteshih
提出日時 2023-10-13 21:29:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,663 bytes
コンパイル時間 2,696 ms
コンパイル使用メモリ 202,764 KB
実行使用メモリ 70,520 KB
最終ジャッジ日時 2023-10-13 21:29:15
合計ジャッジ時間 10,146 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 5 ms
5,768 KB
testcase_03 AC 3 ms
4,368 KB
testcase_04 AC 3 ms
4,752 KB
testcase_05 AC 4 ms
5,000 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 34 ms
18,220 KB
testcase_08 WA -
testcase_09 AC 4 ms
5,136 KB
testcase_10 AC 118 ms
42,856 KB
testcase_11 AC 156 ms
52,468 KB
testcase_12 AC 55 ms
24,896 KB
testcase_13 AC 6 ms
6,236 KB
testcase_14 AC 243 ms
61,560 KB
testcase_15 AC 11 ms
8,852 KB
testcase_16 AC 169 ms
50,964 KB
testcase_17 AC 75 ms
27,904 KB
testcase_18 AC 84 ms
30,216 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 304 ms
70,444 KB
testcase_23 AC 265 ms
70,216 KB
testcase_24 AC 270 ms
70,260 KB
testcase_25 AC 233 ms
70,216 KB
testcase_26 AC 246 ms
70,440 KB
testcase_27 AC 232 ms
70,520 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 47 ms
22,728 KB
testcase_34 AC 132 ms
46,316 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 2 ms
4,368 KB
testcase_40 AC 2 ms
4,372 KB
testcase_41 AC 2 ms
4,372 KB
testcase_42 AC 2 ms
4,368 KB
testcase_43 AC 4 ms
4,368 KB
testcase_44 AC 23 ms
14,420 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 227 ms
70,360 KB
testcase_48 AC 3 ms
4,368 KB
testcase_49 AC 2 ms
4,368 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 3 ms
4,368 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back

const int MAXC = 1e9;
ll arr[5005];
int dp[5005][5005];
pii itv[5005];

ll floor(ll a, ll b) 
{ return a / b - (a % b && (a < 0) ^ (b < 0)); }
ll ceil(ll a, ll b)
{ return a / b + (a % b && (a < 0) ^ (b > 0)); }

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    ll l, r;
    cin >> n >> l >> r;
    for (int i = 1; i <= n; ++i)
        cin >> arr[i];
    sort(arr + 1, arr + n + 1);
    for (int i = 1; i <= n; ++i) {
        int lft, rgt;
        if (arr[i] > 0) {
            lft = ceil(l, arr[i]);
            rgt = floor(r, arr[i]);
        }
        else if (arr[i] == 0) {
            lft = -MAXC;
            rgt = MAXC;
        }
        else {
            lft = ceil(r, arr[i]);
            rgt = floor(l, arr[i]);
        }
        itv[i].X = lower_bound(arr + 1, arr + n + 1, lft) - arr;
        itv[i].Y = upper_bound(arr + 1, arr + n + 1, rgt) - arr - 1;
    }
    int ans = 1;
    for (int i = 1; i <= n; ++i)
        for (int j = i; j >= 1; --j) {
            dp[j][i] = max(dp[j + 1][i], dp[j][i - 1]);
            dp[j][i] = max(dp[j][i], dp[max(j + 1, itv[j].X)][min(i, itv[j].Y)] + 1);
            dp[j][i] = max(dp[j][i], dp[max(j, itv[i].X)][min(i - 1, itv[i].Y)] + 1);
            ans = max(ans, dp[j][i]);
        }
    for (int i = 1; i <= n; ++i)
        if (clamp(i, itv[i].X, itv[i].Y) != i)
            ans = max(ans, dp[itv[i].X][itv[i].Y] + 1);

    cout << ans << "\n";
}
0