QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#377662 | #5552. Skyscraper | hos_lyric | 100 ✓ | 38ms | 4536kb | C++14 | 5.5kb | 2024-04-05 16:31:31 | 2024-04-05 16:31:31 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
static constexpr unsigned M = M_;
unsigned x;
constexpr ModInt() : x(0U) {}
constexpr ModInt(unsigned x_) : x(x_ % M) {}
constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
ModInt pow(long long e) const {
if (e < 0) return inv().pow(-e);
ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
}
ModInt inv() const {
unsigned a = M, b = x; int y = 0, z = 1;
for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
assert(a == 1U); return ModInt(y);
}
ModInt operator+() const { return *this; }
ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
explicit operator bool() const { return x; }
bool operator==(const ModInt &a) const { return (x == a.x); }
bool operator!=(const ModInt &a) const { return (x != a.x); }
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 1000000007;
using Mint = ModInt<MO>;
int N, L;
vector<int> A;
/*
k: building k segments
s: # ends closed
c: cost
incur cost (2k - s)
use k ==> need cost 2+4+...+(2k-2)+...+4+2 = 2(k-1)^2
*/
constexpr int K = 24;
Mint dp[2][K + 1][3][1010];
int main() {
for (; ~scanf("%d%d", &N, &L); ) {
A.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%d", &A[i]);
}
sort(A.begin(), A.end());
Mint ans = 0;
if (N == 1) {
ans = 1;
} else {
memset(dp, 0, sizeof(dp));
dp[0][0][0][0] += 1;
for (int i = 0; i < N; ++i) {
if (i) {
for (int k = 0; k < K; ++k) for (int s = 0; s <= 2; ++s) if (2 * k - s >= 0) {
const int dc = (2 * k - s) * (A[i] - A[i - 1]);
for (int c = 0; c < dc; ++c) dp[0][k][s][c] = 0;
for (int c = dc; c <= L; ++c) dp[0][k][s][c] = dp[1][k][s][c - dc];
for (int c = 0; c <= L; ++c) dp[1][k][s][c] = 0;
}
}
// for(int k=0;k<K;++k)for(int s=0;s<=2;++s)for(int c=0;c<=L;++c)if(dp[0][k][s][c])cerr<<i<<" "<<k<<" "<<s<<" "<<c<<": "<<dp[0][k][s][c]<<endl;
for (int k = 0; k < K; ++k) for (int s = 0; s <= 2; ++s) if (2 * k - s >= 0) {
auto go = [&](int kk, int ss, Mint wt) -> void {
if (wt) {
for (int c = 0; c <= L; ++c) {
dp[1][kk][ss][c] += dp[0][k][s][c] * wt;
}
}
};
go(k + 1, s, k + 1 - s);
go(k + 1, s + 1, 2 - s);
go(k, s, 2 * k - s);
go(k, s + 1, 2 - s);
if (k) go(k - 1, s, k - 1);
}
}
// pv(dp[1][1][2],dp[1][1][2]+(L+1));
for (int c = 0; c <= L; ++c) {
ans += dp[1][1][2][c];
}
}
printf("%u\n", ans.x);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3948kb
input:
1 1 8
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4452kb
input:
2 6 10 4
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 4388kb
input:
3 11 9 1 3
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4444kb
input:
6 94 45 79 24 10 41 66
output:
12
result:
ok single line: '12'
Test #5:
score: 0
Accepted
time: 3ms
memory: 4344kb
input:
8 945 493 43 988 504 328 730 841 613
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 3ms
memory: 4380kb
input:
8 846 304 170 710 158 561 934 100 279
output:
2
result:
ok single line: '2'
Test #7:
score: 0
Accepted
time: 1ms
memory: 4392kb
input:
8 160 136 98 27 113 68 11 34 180
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4456kb
input:
8 77 20 10 22 8 3 14 7 6
output:
39672
result:
ok single line: '39672'
Test #9:
score: 0
Accepted
time: 3ms
memory: 4316kb
input:
8 904 746 229 92 195 358 2 154 709
output:
30
result:
ok single line: '30'
Test #10:
score: 0
Accepted
time: 1ms
memory: 4500kb
input:
8 121 19 41 25 47 31 4 23 17
output:
24760
result:
ok single line: '24760'
Subtask #2:
score: 15
Accepted
Test #11:
score: 15
Accepted
time: 1ms
memory: 4460kb
input:
12 63 8 2 6 3 11 9 1 12 4 5 10 7
output:
472261248
result:
ok single line: '472261248'
Test #12:
score: 0
Accepted
time: 0ms
memory: 4384kb
input:
14 96 17 36 98 27 13 68 11 34 80 50 22 73 94 37
output:
44
result:
ok single line: '44'
Test #13:
score: 0
Accepted
time: 0ms
memory: 4460kb
input:
14 45 6 9 12 15 18 2 14 5 11 17 4 3 7 10
output:
183056086
result:
ok single line: '183056086'
Test #14:
score: 0
Accepted
time: 1ms
memory: 4448kb
input:
14 97 25 2 54 78 9 29 34 99 82 36 14 66 15 64
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 1ms
memory: 4392kb
input:
14 98 26 70 16 95 30 2 18 96 6 5 52 99 89 24
output:
2
result:
ok single line: '2'
Test #16:
score: 0
Accepted
time: 1ms
memory: 4480kb
input:
14 92 33 3 17 38 39 45 2 48 22 29 9 28 5 10
output:
1235526
result:
ok single line: '1235526'
Test #17:
score: 0
Accepted
time: 1ms
memory: 4380kb
input:
14 29 12 6 16 9 23 20 3 1 8 25 29 26 19 24
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 0ms
memory: 4536kb
input:
14 43 17 11 7 8 5 2 10 16 12 9 15 3 14 18
output:
110733412
result:
ok single line: '110733412'
Test #19:
score: 0
Accepted
time: 1ms
memory: 4464kb
input:
14 72 7 13 19 16 20 15 4 10 1 6 14 11 5 8
output:
347124497
result:
ok single line: '347124497'
Test #20:
score: 0
Accepted
time: 0ms
memory: 4392kb
input:
14 83 18 73 40 48 86 97 24 21 45 69 36 16 26 35
output:
6
result:
ok single line: '6'
Subtask #3:
score: 80
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #21:
score: 80
Accepted
time: 1ms
memory: 4344kb
input:
40 39 14 4 18 1 31 32 21 19 37 15 40 33 30 23 10 12 24 11 39 27 20 22 17 5 25 2 6 35 26 13 29 38 9 36 34 28 8 3 7 16
output:
2
result:
ok single line: '2'
Test #22:
score: 0
Accepted
time: 21ms
memory: 4472kb
input:
78 822 11 17 6 74 82 21 92 70 66 28 37 29 26 85 68 50 77 47 67 59 12 45 19 35 90 15 30 41 55 97 36 84 49 53 65 38 76 46 16 93 48 100 94 80 2 34 1 71 18 39 44 22 20 89 60 88 13 62 32 4 99 40 5 8 25 7 51 33 42 78 23 63 9 58 56 31 95 57
output:
519066706
result:
ok single line: '519066706'
Test #23:
score: 0
Accepted
time: 37ms
memory: 4448kb
input:
100 982 571 304 440 915 800 767 836 922 44 753 87 720 151 411 624 670 606 944 312 432 993 817 700 972 640 371 837 892 858 834 329 178 684 177 490 92 435 712 905 27 791 523 365 891 885 814 442 128 180 785 538 871 562 582 166 803 733 333 855 760 848 378 463 11 820 942 721 300 113 957 391 153 49 15 45 ...
output:
2
result:
ok single line: '2'
Test #24:
score: 0
Accepted
time: 28ms
memory: 4384kb
input:
100 742 251 236 416 365 495 464 259 153 93 317 215 421 61 451 369 242 348 197 288 2 235 129 72 449 376 254 372 330 294 220 472 321 265 80 131 411 81 114 343 139 383 45 329 394 76 481 1 97 448 371 88 44 234 353 262 325 401 381 279 358 424 499 15 346 163 10 111 350 219 291 56 244 386 35 276 322 152 22...
output:
44225906
result:
ok single line: '44225906'
Test #25:
score: 0
Accepted
time: 38ms
memory: 4452kb
input:
100 994 314 762 11 841 979 1 395 508 657 552 787 432 545 740 777 585 253 109 515 455 20 29 672 371 664 948 25 544 855 9 982 553 289 164 360 380 357 462 488 354 900 789 245 881 467 284 275 237 910 568 835 940 685 652 550 267 468 111 590 328 774 582 296 937 875 436 232 973 799 71 588 298 90 647 91 112...
output:
20
result:
ok single line: '20'
Test #26:
score: 0
Accepted
time: 33ms
memory: 4452kb
input:
100 845 122 357 219 392 501 197 521 305 800 730 745 776 71 17 600 681 289 253 129 1 463 41 750 786 184 516 260 479 360 162 383 49 55 641 182 371 429 252 345 270 796 470 311 173 324 126 220 451 632 44 647 271 595 211 793 665 725 320 21 763 462 526 235 350 491 523 661 94 729 323 382 767 69 624 723 240...
output:
964691650
result:
ok single line: '964691650'
Test #27:
score: 0
Accepted
time: 10ms
memory: 4476kb
input:
100 244 54 13 26 41 58 34 96 40 52 59 95 61 39 30 76 99 93 63 77 37 47 74 65 85 20 43 29 60 46 17 28 73 49 1 71 44 64 84 2 10 22 87 14 70 32 57 55 15 16 38 67 98 78 92 75 25 51 100 45 80 35 8 11 97 62 21 69 88 27 42 5 18 72 36 89 79 24 9 7 56 19 33 66 94 48 31 68 83 6 53 86 4 3 90 23 12 50 82 81 91
output:
806509145
result:
ok single line: '806509145'
Test #28:
score: 0
Accepted
time: 12ms
memory: 4472kb
input:
100 300 20 11 12 16 79 43 46 71 63 9 84 100 10 14 51 52 66 3 18 54 17 85 70 4 30 58 83 65 53 55 27 28 56 60 87 23 50 80 99 91 44 86 88 32 77 62 64 15 33 92 72 34 31 81 5 82 59 41 37 39 13 96 22 78 42 21 98 38 6 8 40 25 47 94 97 24 45 36 2 49 95 76 90 68 26 74 67 19 75 35 93 48 7 57 69 61 73 29 1 89
output:
426165212
result:
ok single line: '426165212'
Test #29:
score: 0
Accepted
time: 22ms
memory: 4468kb
input:
100 572 133 160 57 146 103 124 90 20 95 87 108 193 101 147 2 166 145 157 75 118 176 96 67 65 92 192 141 60 98 110 164 23 86 100 120 121 149 54 177 77 34 198 194 104 9 175 167 31 182 187 126 70 26 159 186 200 22 115 61 73 156 163 49 53 71 32 1 64 148 171 183 180 197 30 102 131 21 152 46 55 158 94 16 ...
output:
608022944
result:
ok single line: '608022944'
Test #30:
score: 0
Accepted
time: 38ms
memory: 4344kb
input:
100 999 195 528 657 37 217 348 814 585 258 861 558 601 237 514 534 476 911 163 267 807 109 508 174 538 897 56 225 467 409 834 562 572 577 115 915 290 736 860 639 695 461 928 344 843 456 122 712 581 613 810 691 484 546 439 435 939 765 482 841 551 119 176 599 275 688 589 821 783 806 735 221 47 904 621...
output:
218730
result:
ok single line: '218730'
Extra Test:
score: 0
Extra Test Passed