結果

問題 No.2500 Products in a Range
ユーザー k1suxuk1suxu
提出日時 2023-10-13 23:57:57
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,735 bytes
コンパイル時間 4,234 ms
コンパイル使用メモリ 259,568 KB
実行使用メモリ 11,300 KB
最終ジャッジ日時 2023-10-13 23:58:05
合計ジャッジ時間 7,061 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,300 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 41 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 188 ms
4,796 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 7 ms
4,348 KB
testcase_08 AC 6 ms
4,352 KB
testcase_09 AC 2 ms
4,348 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 target("avx")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define all(x) x.begin(),x.end()
//#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvvvi vector<vvvi>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>

template<typename T>
bool chmax(T &a, const T b) {if(a<b) {a=b; return true;} else {return false;}}
template<typename T>
bool chmin(T &a, const T b) {if(a>b) {a=b; return true;} else {return false;}}

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll INF = numeric_limits<long long>::max() / 2;
const ld pi = 3.1415926535897932384626433832795028;
const ll mod = 998244353;
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};

#define int long long

template <typename T, typename U>
T ceil(T x, U y) {
    if(x>0 && y>0) return (x+y-1)/y;
    else if(x>0) return -(x/abs(y));
    else if(y>0) return -(abs(x)/y);
    else return (abs(x)+abs(y)-1)/abs(y);
}
template <typename T, typename U>
T floor(T x, U y) {
    if(x>0 && y>0) return x/y;
    else if(x>0) return -((x+abs(y)-1)/abs(y));
    else if(y>0) return -((abs(x)+y-1)/y);
    else return abs(x)/abs(y);
}

pii merge(pii x, pii y) {
    return make_pair(max(x.first, y.first), min(x.second, y.second));
}

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    int zero = 0;
    vi a;
    FOR(n) {
        int x;
        cin >> x;
        if(x == 0) ++zero;
        else a.push_back(x);
    }
    n = (int)a.size();
    vector<map<pii, int>> dp(2);
    dp[0][{-INF, INF}] = 0;
    FOR(n) {
        int cur = i&1;
        int nxt = 1^cur;

        dp[nxt] = dp[cur];

        for(auto e : dp[cur]) if(e.first.first <= a[i] && a[i] <= e.first.second) {
            pii seg1 = e.first;
            pii seg2;
            if(a[i]>0) seg2 = {ceil(l, a[i]), floor(r, a[i])};
            else seg2 = {ceil(r, a[i]), floor(l, a[i])};

            pii seg = merge(seg1, seg2);

            if(seg.first > seg.second) continue;

            dp[nxt][seg] = max(dp[nxt][seg], e.second+1);
        }
    }

    // 0を使えるかどうか

    int ans = 0;
    for(auto e : dp[n&1]) chmax(ans, e.second);
    if(l <= 0 && 0 <= r) ans += zero;
    cout << ans << endl;

    // for(auto e : dp[n&1]) {
    //     cout << e.first.first << " " << e.first.second << " -> " << e.second << endl;
    // }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
0