結果

問題 No.2500 Products in a Range
ユーザー baluteshihbaluteshih
提出日時 2023-10-13 21:31:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 1,840 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 203,512 KB
実行使用メモリ 70,384 KB
最終ジャッジ日時 2023-10-13 21:31:30
合計ジャッジ時間 10,142 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 5 ms
5,752 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 3 ms
4,596 KB
testcase_05 AC 4 ms
5,004 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 35 ms
18,172 KB
testcase_08 AC 279 ms
61,844 KB
testcase_09 AC 4 ms
5,156 KB
testcase_10 AC 124 ms
42,812 KB
testcase_11 AC 163 ms
52,484 KB
testcase_12 AC 55 ms
24,716 KB
testcase_13 AC 6 ms
6,368 KB
testcase_14 AC 251 ms
61,544 KB
testcase_15 AC 11 ms
8,884 KB
testcase_16 AC 181 ms
50,636 KB
testcase_17 AC 77 ms
28,008 KB
testcase_18 AC 84 ms
30,076 KB
testcase_19 AC 234 ms
61,028 KB
testcase_20 AC 273 ms
66,508 KB
testcase_21 AC 13 ms
9,980 KB
testcase_22 AC 323 ms
70,200 KB
testcase_23 AC 286 ms
70,384 KB
testcase_24 AC 295 ms
70,244 KB
testcase_25 AC 242 ms
70,280 KB
testcase_26 AC 269 ms
70,232 KB
testcase_27 AC 245 ms
70,268 KB
testcase_28 AC 217 ms
57,404 KB
testcase_29 AC 35 ms
17,024 KB
testcase_30 AC 25 ms
14,136 KB
testcase_31 AC 4 ms
5,352 KB
testcase_32 AC 7 ms
6,984 KB
testcase_33 AC 49 ms
22,560 KB
testcase_34 AC 141 ms
46,248 KB
testcase_35 AC 1 ms
4,352 KB
testcase_36 AC 2 ms
4,352 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,352 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 1 ms
4,352 KB
testcase_42 AC 2 ms
4,352 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 23 ms
14,408 KB
testcase_45 AC 5 ms
5,404 KB
testcase_46 AC 62 ms
26,172 KB
testcase_47 AC 248 ms
70,208 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 86 ms
29,880 KB
testcase_51 AC 103 ms
33,804 KB
testcase_52 AC 230 ms
59,420 KB
testcase_53 AC 23 ms
13,632 KB
testcase_54 AC 2 ms
4,352 KB
testcase_55 AC 76 ms
29,876 KB
testcase_56 AC 120 ms
34,024 KB
testcase_57 AC 300 ms
59,508 KB
testcase_58 AC 26 ms
14,312 KB
testcase_59 AC 254 ms
63,860 KB
testcase_60 AC 10 ms
8,236 KB
権限があれば一括ダウンロードができます

ソースコード

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) {
            if (clamp(0LL, l, r) == 0) {
                lft = -MAXC;
                rgt = MAXC;
            }
            else {
                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 (itv[i].X <= itv[i].Y && clamp(i, itv[i].X, itv[i].Y) != i)
            ans = max(ans, dp[itv[i].X][itv[i].Y] + 1);

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