結果

問題 No.2500 Products in a Range
ユーザー KKT89KKT89
提出日時 2023-10-13 21:21:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,877 bytes
コンパイル時間 2,996 ms
コンパイル使用メモリ 221,036 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-13 21:21:25
合計ジャッジ時間 6,712 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,l,r; cin >> n >> l >> r;
    int zero = 0;
    vector<int> a;
    for (int i = 0; i < n; ++i) {
        int aa; cin >> aa;
        if (aa == 0) zero += 1;
        else a.push_back(aa);
    }
    if (l > 0 or 0 > r) zero = 0;
    n = a.size();
    map<pair<int,int>,int> dp;
    dp[{-1e9, 1e9}] = 0;
    auto find_r = [&](int x, int l, int r) -> pair<int,int> {
        int ll = l/x, rr = r/x;
        if (ll > rr) swap(ll, rr);
        pair<int,int> res;
        for (int i = -2; i <= 2; ++i) {
            if (l <= (rr+i)*x and (rr+i)*x <= r) res.second = rr+i;
            if (l <= (ll-i)*x and (ll-i)*x <= r) res.first = ll-i;
        }
        return res;
    };
    int res = 0;
    for (int i = 0; i < n; ++i) {
        map<pair<int,int>,int> ndp = dp;
        auto ku = find_r(a[i], l, r);
        for (auto &p : dp) {
//            cout << i << " " << p.first.first << " " << p.first.second << " " << p.second  << endl;
            if (p.first.first <= a[i] and a[i] <= p.first.second) {
                int nl = max(p.first.first, ku.first);
                int nr = min(p.first.second, ku.second);
                res = max(res, p.second+1);
                if (nl <= nr) {
                    ndp[{nl,nr}] = max(ndp[{nl,nr}], p.second+1);
                }
            }
        }
        swap(dp, ndp);
    }
    res += zero;
    cout << max(res, 1) << endl;
}
0