QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#626647#9220. Bus Analysisucup-team1264AC ✓554ms8604kbC++205.3kb2024-10-10 11:20:012024-10-10 11:20:04

Judging History

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

  • [2024-10-10 11:20:04]
  • 评测
  • 测评结果:AC
  • 用时:554ms
  • 内存:8604kb
  • [2024-10-10 11:20:01]
  • 提交

answer

// https://www.youtube.com/watch?v=CrymicX875M
// Angel of mercy
// How did you move me
// Why am I on my feet again

#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;


namespace modint {

using i64 = int64_t;

template <int P>
struct Mint {
   private:
    constexpr Mint power(Mint x, i64 p) const {
        Mint res = 1;
        while (p > 0) {
            if (p & 1) {
                res *= x;
            }
            x *= x;
            p >>= 1;
        }
        return res;
    }

    constexpr int norm(int x) const {
        if (x < 0) {
            x += getMod();
        }
        if (x >= getMod()) {
            x -= getMod();
        }
        return x;
    }

   public:
    int x;
    constexpr Mint() : x{} {}
    constexpr Mint(i64 x) : x{norm(x % getMod())} {}
    static int mod;
    constexpr static int getMod() {
        if (P > 0) {
            return P;
        } else {
            return mod;
        }
    }
    constexpr static void setMod(int Mod_) { mod = Mod_; }

    constexpr int val() const { return x; }
    explicit constexpr operator int() const { return x; }
    constexpr Mint operator-() const {
        Mint res;
        res.x = norm(getMod() - x);
        return res;
    }
    constexpr Mint inv() const {
        assert(x != 0);
        return power(*this, getMod() - 2);
    }
    constexpr Mint pow(i64 r) const { return power(*this, r); }
    constexpr Mint &operator*=(Mint rhs) & {
        x = 1LL * x * rhs.x % getMod();
        return *this;
    }
    constexpr Mint &operator+=(Mint rhs) & {
        x = norm(x + rhs.x);
        return *this;
    }
    constexpr Mint &operator-=(Mint rhs) & {
        x = norm(x - rhs.x);
        return *this;
    }
    constexpr Mint &operator/=(Mint rhs) & { return *this *= rhs.inv(); }
    friend constexpr Mint operator*(Mint lhs, Mint rhs) {
        Mint res = lhs;
        res *= rhs;
        return res;
    }
    friend constexpr Mint operator+(Mint lhs, Mint rhs) {
        Mint res = lhs;
        res += rhs;
        return res;
    }
    friend constexpr Mint operator-(Mint lhs, Mint rhs) {
        Mint res = lhs;
        res -= rhs;
        return res;
    }
    friend constexpr Mint operator/(Mint lhs, Mint rhs) {
        Mint res = lhs;
        res /= rhs;
        return res;
    }
    friend constexpr std::istream &operator>>(std::istream &is, Mint &a) {
        i64 v;
        is >> v;
        a = Mint(v);
        return is;
    }
    friend constexpr std::ostream &operator<<(std::ostream &os, const Mint &a) {
        return os << a.val();
    }
    friend constexpr bool operator==(Mint lhs, Mint rhs) {
        return lhs.val() == rhs.val();
    }
    friend constexpr bool operator!=(Mint lhs, Mint rhs) {
        return lhs.val() != rhs.val();
    }
};

template <int P>
int Mint<P>::mod{0};

template <typename Z>
struct Comb {
    std::vector<Z> fact, inv_fact;
    Comb(int n) {
        fact.resize(n + 1, Z(1));
        inv_fact.resize(n + 1, Z(1));
        for (int i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i;
        }
        inv_fact[n] = Z{1} / fact[n];
        for (int i = n - 1; i >= 0; i--) {
            inv_fact[i] = inv_fact[i + 1] * (i + 1);
        }
    }
    Z get(int n, int m) const {
        if (n < m || m < 0) return 0;
        return fact[n] * inv_fact[m] * inv_fact[n - m];
    }
};
}  // namespace modint

// check the modulus!!!
constexpr int MOD = 1e9 + 7;

using Z = modint::Mint<MOD>;
using C = modint::Comb<Z>;

constexpr int L = 76;
array<array<array<Z, L>, L>, L> dp, ndp;

// #define int i64
void solve() {
    int n; cin >> n;
    Z ans = 0;
    vector<Z> pw2(n + 1);
    pw2[0] = 1;
    for (int i = 1; i <= n; i++) {
        pw2[i] = pw2[i - 1] * 2;
    }
    dp[0][0][0] = 1;
    int last = 0;
    for (int i = 0; i < n; i++) {
        array<array<array<Z, L>, L>, L> ndp;
        int t; cin >> t;
        int d = t - last;
        for (int x = -1; x + 1 < L; x++) {
            for (int y = -1; y + 1 < L; y++) {
                for (int z = -1; z + 1 < L; z++) {
                    if (dp[x + 1][y + 1][z + 1] == 0) continue;
                    array<int, 6> f; f.fill(-1);
                    f[0] = max(f[0], x - d), f[1] = max(f[1], y - d), f[2] = max(f[2], z - d);
                    for (int t = 1; t < 6; t++) {
                        f[t] = max(f[t], f[t - 1] + 20);
                        if (t >= 3) f[t] = max(f[t], f[t - 3] + 75);
                    }
                    ndp[f[0] + 1][f[1] + 1][f[2] + 1] += dp[x + 1][y + 1][z + 1];
                    int j = 0; while (f[j] < 0) j++;
                    ans += dp[x + 1][y + 1][z + 1] * j * pw2[n - i - 1];
                    ndp[f[j] + 1][f[j + 1] + 1][f[j + 2] + 1] += dp[x + 1][y + 1][z + 1];
                }
            }
        }
        last = t;
        dp.swap(ndp);
    }
    cout << ans * 2 << '\n';
}
#undef int

// Make bold hypotheses and verify carefully
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    };
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 8336kb

input:

3
1 8 20

output:

14

result:

ok 1 number(s): "14"

Test #2:

score: 0
Accepted
time: 5ms
memory: 8604kb

input:

5
25 45 65 85 1000000000

output:

156

result:

ok 1 number(s): "156"

Test #3:

score: 0
Accepted
time: 515ms
memory: 6988kb

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:

932594593

result:

ok 1 number(s): "932594593"

Test #4:

score: 0
Accepted
time: 108ms
memory: 7268kb

input:

200
1 2 4 9 10 11 12 15 16 17 18 19 22 24 27 28 33 36 37 39 43 44 45 47 48 49 50 51 52 56 60 61 62 63 68 70 71 72 73 74 78 80 81 84 86 92 93 98 99 100 102 105 107 108 110 111 114 115 116 122 123 125 129 132 133 135 137 138 139 141 142 143 144 149 150 151 152 153 154 155 159 160 165 171 172 174 176 1...

output:

422301620

result:

ok 1 number(s): "422301620"

Test #5:

score: 0
Accepted
time: 511ms
memory: 8244kb

input:

1000
999975020 999975030 999975050 999975056 999975085 999975118 999975207 999975213 999975240 999975307 999975332 999975344 999975356 999975384 999975405 999975468 999975499 999975558 999975559 999975571 999975631 999975664 999975680 999975689 999975731 999975738 999975765 999975831 999975838 99997...

output:

335758758

result:

ok 1 number(s): "335758758"

Test #6:

score: 0
Accepted
time: 0ms
memory: 8560kb

input:

3
1 8 20

output:

14

result:

ok 1 number(s): "14"

Test #7:

score: 0
Accepted
time: 511ms
memory: 8592kb

input:

1000
214 216 381 497 539 645 772 927 1211 1238 1239 1298 1403 1426 1437 1504 1515 1648 1800 1816 1946 2008 2038 2066 2144 2173 2236 2253 2291 2574 2632 2643 2658 2671 2689 2886 2910 2948 3002 3033 3039 3057 3077 3188 3240 3322 3331 3449 3467 3578 3730 3796 3897 3973 4152 4160 4199 4331 4386 4429 465...

output:

877690181

result:

ok 1 number(s): "877690181"

Test #8:

score: 0
Accepted
time: 0ms
memory: 6972kb

input:

1
963837006

output:

2

result:

ok 1 number(s): "2"

Test #9:

score: 0
Accepted
time: 507ms
memory: 6984kb

input:

999
17 234 337 379 449 607 646 703 716 878 887 898 901 942 964 1075 1198 1356 1432 1546 1547 1619 1668 1769 1818 1826 1881 1900 1960 2017 2088 2266 2273 2339 2376 2377 2396 2399 2438 2461 2484 2567 2620 2661 2680 2791 2881 3040 3081 3082 3094 3102 3205 3218 3225 3227 3239 3250 3331 3393 3425 3530 35...

output:

651884156

result:

ok 1 number(s): "651884156"

Test #10:

score: 0
Accepted
time: 551ms
memory: 7640kb

input:

1000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...

output:

754964156

result:

ok 1 number(s): "754964156"

Test #11:

score: 0
Accepted
time: 511ms
memory: 8120kb

input:

1000
1 2 5 12 13 16 19 21 24 40 42 50 51 54 60 61 63 65 69 72 83 100 106 117 121 122 132 133 135 144 149 154 156 157 158 159 163 172 187 190 194 195 196 200 204 221 224 225 236 237 238 239 242 248 250 251 257 258 264 269 272 279 284 286 288 294 298 301 303 322 324 326 328 347 348 358 363 367 368 376...

output:

736216287

result:

ok 1 number(s): "736216287"

Test #12:

score: 0
Accepted
time: 2ms
memory: 8520kb

input:

10
2 5 8 10 11 15 20 32 34 48

output:

3806

result:

ok 1 number(s): "3806"

Test #13:

score: 0
Accepted
time: 513ms
memory: 7292kb

input:

1000
3092896 4096697 4935574 5665657 6717242 12350017 13784643 14890236 15103239 16083201 16158442 17406219 18377269 19146618 20149007 20444388 20799716 21703919 22502750 26066931 27425220 27610093 30584293 30942406 33020849 33381138 34889813 35505301 35711460 36618608 37636454 42073851 43834284 441...

output:

423205184

result:

ok 1 number(s): "423205184"

Test #14:

score: 0
Accepted
time: 554ms
memory: 7900kb

input:

1000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 100 101 10...

output:

167925937

result:

ok 1 number(s): "167925937"

Test #15:

score: 0
Accepted
time: 506ms
memory: 7044kb

input:

1000
123123123 123123143 123123163 123123183 123123203 123123223 123123243 123123263 123123283 123123303 123123323 123123343 123123363 123123383 123123403 123123423 123123443 123123463 123123483 123123503 123123523 123123543 123123563 123123583 123123603 123123623 123123643 123123663 123123683 12312...

output:

152353232

result:

ok 1 number(s): "152353232"

Test #16:

score: 0
Accepted
time: 0ms
memory: 8116kb

input:

5
25 45 65 85 1000000000

output:

156

result:

ok 1 number(s): "156"

Test #17:

score: 0
Accepted
time: 546ms
memory: 7404kb

input:

1000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 76 77 79 80 81 82 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 103 104 105...

output:

506306982

result:

ok 1 number(s): "506306982"

Test #18:

score: 0
Accepted
time: 510ms
memory: 7912kb

input:

1000
6 15 22 23 29 36 55 56 63 75 84 98 100 107 114 119 124 126 135 150 155 156 158 159 162 168 179 180 193 196 197 202 204 214 215 218 229 242 244 248 251 253 255 265 271 273 286 288 302 306 324 334 368 380 388 409 425 473 476 489 525 526 534 540 554 556 562 566 570 573 574 592 621 636 640 645 653 ...

output:

272405461

result:

ok 1 number(s): "272405461"

Test #19:

score: 0
Accepted
time: 12ms
memory: 7036kb

input:

19
999999810 999999814 999999829 999999838 999999839 999999843 999999849 999999853 999999883 999999889 999999896 999999907 999999911 999999925 999999926 999999946 999999957 999999987 999999993

output:

5337088

result:

ok 1 number(s): "5337088"

Test #20:

score: 0
Accepted
time: 541ms
memory: 8072kb

input:

999
1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 28 29 30 31 32 33 34 35 38 39 40 41 42 43 45 46 47 49 50 51 52 54 55 56 57 59 60 61 62 64 65 66 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 85 86 88 89 90 91 92 93 94 95 96 97 99 100 101 103 105 106 107 108 109 110 111 112 11...

output:

571215215

result:

ok 1 number(s): "571215215"

Test #21:

score: 0
Accepted
time: 523ms
memory: 7584kb

input:

1000
123121000 123121001 123121002 123121005 123121012 123121013 123121018 123121020 123121021 123121024 123121028 123121029 123121031 123121034 123121035 123121036 123121037 123121038 123121043 123121044 123121045 123121046 123121047 123121048 123121050 123121051 123121052 123121055 123121057 12312...

output:

250442238

result:

ok 1 number(s): "250442238"

Extra Test:

score: 0
Extra Test Passed