QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#530023#9220. Bus Analysisucup-team4435#TL 1ms3652kbC++208.2kb2024-08-24 14:40:302024-08-24 14:40:30

Judging History

你现在查看的是最新测评结果

  • [2024-08-24 14:40:30]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3652kb
  • [2024-08-24 14:40:30]
  • 提交

answer

#pragma GCC optimize("Ofast")

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)

using namespace std;


using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

template<class T>
bool ckmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool ckmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}

template<typename T>
int normalize(T value, int mod) {
    if (value < -mod || value >= 2 * mod) value %= mod;
    if (value < 0) value += mod;
    if (value >= mod) value -= mod;
    return value;
}

template<int mod>
struct static_modular_int {
    using mint = static_modular_int<mod>;

    int value;

    static_modular_int() : value(0) {}

    static_modular_int(const mint &x) : value(x.value) {}

    template<typename T, typename U = std::enable_if_t<std::is_integral<T>::value>>
    static_modular_int(T value) : value(normalize(value, mod)) {}

    template<typename T>
    mint power(T degree) const {
        degree = normalize(degree, mod - 1);
        mint prod = 1, a = *this;
        for (; degree > 0; degree >>= 1, a *= a)
            if (degree & 1)
                prod *= a;

        return prod;
    }

    mint inv() const {
        return power(-1);
    }

    mint &operator=(const mint &x) {
        value = x.value;
        return *this;
    }

    mint &operator+=(const mint &x) {
        value += x.value;
        if (value >= mod) value -= mod;
        return *this;
    }

    mint &operator-=(const mint &x) {
        value -= x.value;
        if (value < 0) value += mod;
        return *this;
    }

    mint &operator*=(const mint &x) {
        value = int64_t(value) * x.value % mod;
        return *this;
    }

    mint &operator/=(const mint &x) {
        return *this *= x.inv();
    }

    friend mint operator+(const mint &x, const mint &y) {
        return mint(x) += y;
    }

    friend mint operator-(const mint &x, const mint &y) {
        return mint(x) -= y;
    }

    friend mint operator*(const mint &x, const mint &y) {
        return mint(x) *= y;
    }

    friend mint operator/(const mint &x, const mint &y) {
        return mint(x) /= y;
    }

    mint &operator++() {
        ++value;
        if (value == mod) value = 0;
        return *this;
    }

    mint &operator--() {
        --value;
        if (value == -1) value = mod - 1;
        return *this;
    }

    mint operator++(int) {
        mint prev = *this;
        value++;
        if (value == mod) value = 0;
        return prev;
    }

    mint operator--(int) {
        mint prev = *this;
        value--;
        if (value == -1) value = mod - 1;
        return prev;
    }

    mint operator-() const {
        return mint(0) - *this;
    }

    bool operator==(const mint &x) const {
        return value == x.value;
    }

    bool operator!=(const mint &x) const {
        return value != x.value;
    }

    bool operator<(const mint &x) const {
        return value < x.value;
    }

    template<typename T>
    explicit operator T() {
        return value;
    }

    friend std::istream &operator>>(std::istream &in, mint &x) {
        std::string s;
        in >> s;
        x = 0;
        for (const auto c: s)
            x = x * 10 + (c - '0');

        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &x) {
        return out << x.value;
    }

    static int primitive_root() {
        if constexpr (mod == 1'000'000'007) return 5;
        if constexpr (mod == 998'244'353) return 3;
        if constexpr (mod == 786433) return 10;

        static int root = -1;
        if (root != -1)
            return root;

        std::vector<int> primes;
        int value = mod - 1;
        for (int i = 2; i * i <= value; i++)
            if (value % i == 0) {
                primes.push_back(i);
                while (value % i == 0)
                    value /= i;
            }

        if (value != 1) primes.push_back(value);
        for (int r = 2;; r++) {
            bool ok = true;
            for (auto p: primes) {
                if ((mint(r).power((mod - 1) / p)).value == 1) {
                    ok = false;
                    break;
                }
            }
            if (ok) return root = r;
        }
    }
};

constexpr int MOD = 1'000'000'007;
// constexpr int MOD = 998'244'353;
using mint = static_modular_int<MOD>;


const int INFi = 2e9;
const ll INF = 2e18;
const int LG = 31;
const int N = 1e4;

int n;
vi t;

int jump[N][2];
int tmp[N];

int pos;
const int SZ = 76;
struct State {
    ar<int, SZ> dp;

    int MakeGood() {
        ckmin(dp[jump[pos][0] - 1], 1);
        ckmin(dp[jump[pos][1] - 1], 3);
        for(int i = 0; i < SZ; ++i) {
            rep(q, 2) {
                int j = i + jump[pos + i + 1][q];
                int cost = q * 2 + 1;
                if (j < SZ) {
                    dp[j] = min(dp[j], dp[i] + cost);
                }
            }
        }
        for(int i = SZ - 1; i >= 1; --i) dp[i - 1] = min(dp[i - 1], dp[i]);

        int x = dp[0];
        for(int i = 1; i < SZ; ++i) dp[i - 1] = dp[i] - x;
        dp[SZ - 1] = INFi;
        return x;
    }
};

bool operator<(const State &a, const State &b) {
    return a.dp < b.dp;
}

bool operator==(const State &a, const State &b) {
    return a.dp == b.dp;
}


void solve() {
    cin >> n;
    t.resize(n);
    rep(i, n) cin >> t[i];
    jump[n][0] = jump[n][1] = n;
    for (int i = n - 1; i >= 0; --i) {
        rep(j, 2) jump[i][j] = jump[i + 1][j];
        while (t[jump[i][0] - 1] >= t[i] + 20) jump[i][0]--;
        while (t[jump[i][1] - 1] >= t[i] + 75) jump[i][1]--;
    }
    for(int i = n; i >= 0; --i) {
        rep(j, 2) jump[i][j] -= i;
    }
    map<State, pair<mint, mint>> dp;
    auto Add = [&](State s, mint ways, mint sum) {
        int value = s.MakeGood();
        sum += mint(value) * ways;
        if (dp.contains(s)) {
            dp[s].first += ways;
            dp[s].second += sum;
        } else {
            dp[s] = {ways, sum};
        }
    };
    pos = 0;
    {
        State s;
        rep(i, SZ) s.dp[i] = INFi;
        s.dp[0] = 0;
        Add(s, 1, 0);
    }
    for(int i = 0; i < n; ++i) {
        pos = i;
        map<State, pair<mint, mint>> dp_was;
        swap(dp, dp_was);

        for(auto &[s, ways_sum] : dp_was) {
            auto [ways, sum] = ways_sum;

            {
                auto s2 = s;
                ckmin(s2.dp[0], 0);
                Add(s2, ways, sum);
            }

            {
                Add(s, ways, sum);
            }
        }
    }

    mint ans = 0;
    for(auto &[s, ways_sum] : dp) {
        ans += ways_sum.second;
    }
    cout << ans * 2 << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(12) << fixed;
    int t = 1;
//    cin >> t;
    rep(i, t) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

input:

3
1 8 20

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3652kb

input:

5
25 45 65 85 1000000000

output:

156

result:

ok 1 number(s): "156"

Test #3:

score: -100
Time Limit Exceeded

input:

1000
2 7 9 12 14 17 18 21 22 28 29 33 34 35 37 38 44 45 46 50 58 59 63 66 71 72 75 76 77 78 80 81 83 84 87 92 100 101 107 108 109 112 114 116 118 123 124 131 142 143 144 145 148 150 151 152 153 155 157 158 165 167 168 169 171 176 182 185 190 192 198 202 204 205 212 213 223 224 225 226 229 231 240 24...

output:


result: