QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#712341 | #2472. Counting Haybales | _8_8_# | 0 | 0ms | 0kb | C++23 | 1.8kb | 2024-11-05 15:23:09 | 2024-11-05 15:23:10 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e3 + 2, MOD = (int)1e9 + 7;
int n, h[N], k;
void add(int &x, int y) {
x += y;
if(x >= MOD) x -= MOD;
}
int dp[N];
map<int, int> pd[N][N];
void test() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> h[i];
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
pd[i][j].clear();
}
}
dp[0] = 1;
for(int i = 1; i <= n; i++) {
if(i == 1) pd[i][1][h[i]] = dp[i - 1];
else {
for(int j = h[i - 1] - 1; j <= h[i - 1] + 1; j++) {
if(j != h[i]) {
for(int f = 1; f <= i; f++) {
add(pd[i][1][h[i]], pd[i - 1][f][j]);
}
}
}
}
for(int j = 1; j <= i; j++) {
if(pd[i - 1][j].count(h[i] - 1)) pd[i][j][h[i] - 1] = pd[i - 1][j][h[i] - 1];
if(pd[i - 1][j].count(h[i] + 1)) pd[i][j][h[i] + 1] = pd[i - 1][j][h[i] + 1];
if(j > 1) {
if(pd[i - 1][j - 1].count(h[i])) pd[i][j][h[i]] = pd[i - 1][j - 1][h[i]];
}
}
int j = i - 1;
dp[i] = dp[i - 1];
for(; j >= 1 && abs(h[j] - h[i]) == 1; j--) {
add(dp[i], dp[j - 1]);
}
for(int f = 1; f <= i; f++) {
if(pd[j][f].count(h[i] - 1)) add(dp[i], f * 1ll * pd[j][f][h[i] - 1] % MOD);
if(pd[j][f].count(h[i] + 1)) add(dp[i], f * 1ll * pd[j][f][h[i] + 1] % MOD);
}
}
cout << dp[n] << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while(t--) {
test();
}
}
詳細信息
Pretests
Final Tests
Test #1:
score: 0
Memory Limit Exceeded
input:
7 4 2 2 2 3 4 3 3 1 2 4 5 3 4 2 6 3 3 1 1 2 2 6 1 3 3 4 1 2 6 4 1 2 3 5 4 10 1 5 6 6 6 4 2 3 2 5
output:
4 4 4 7 8 8 19
result:
Test #2:
score: 0
Memory Limit Exceeded
input:
10 10 447773962 773442532 122816 137572579 324627123 157577940 253498609 99147813 425825313 199995380 10 416515986 416515986 416515987 416515987 416515988 416515988 416515989 416515989 416515988 416515989 10 563229302 563229301 563229301 563229302 563229301 563229300 563229300 563229301 563229302 56...
output:
1 117 121 88 126 72 149 163 138 136
result:
Test #3:
score: 0
Memory Limit Exceeded
input:
10 10 468145963 198730372 27838076 590195590 467423861 520495379 451366491 344173378 354694313 165814381 10 219739800 219739801 219739801 219739800 219739799 219739799 219739798 219739798 219739798 219739799 10 568161994 568161995 568161994 568161994 568161994 568161994 568161993 568161994 568161995...
output:
1 147 98 68 48 102 26 102 173 132
result:
Test #4:
score: 0
Memory Limit Exceeded
input:
1 5000 2 1 3 3 1 1 2 2 3 2 3 1 1 1 1 1 1 1 2 3 1 1 2 2 2 1 1 2 3 2 2 3 1 3 2 3 1 2 2 2 1 1 3 2 2 1 1 2 2 3 3 3 1 1 1 3 2 3 3 1 3 1 3 1 3 3 3 2 2 2 1 2 2 3 2 3 2 1 1 1 2 2 2 3 1 2 1 1 2 2 3 2 2 3 1 3 1 2 2 1 1 3 1 1 2 3 1 3 2 2 2 2 3 2 3 2 3 3 3 1 2 3 3 2 2 2 2 3 1 2 2 1 1 1 1 3 3 1 1 1 3 2 2 1 3 2 2...
output:
668236156
result:
Test #5:
score: 0
Memory Limit Exceeded
input:
10 500 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 1...
output:
523068127 17102489 592112534 537895402 216241270 591655324 959469433 99813024 455699627 57240887
result:
Test #6:
score: 0
Memory Limit Exceeded
input:
10 500 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:
523068127 289091260 102117566 753979722 685160226 57498236 984395869 201086574 497564857 90405665
result:
Test #7:
score: 0
Memory Limit Exceeded
input:
1 5000 2 3 2 3 6 5 6 8 8 11 11 11 13 14 15 16 17 18 19 21 21 23 24 24 25 25 27 27 29 31 32 33 34 34 35 37 38 39 40 40 40 43 44 43 46 46 48 48 50 50 51 52 52 53 56 55 57 57 58 61 62 62 64 64 64 67 68 69 69 71 72 73 74 75 75 77 76 77 79 81 82 82 84 84 85 87 88 88 89 91 91 93 94 93 94 97 97 97 100 101 ...
output:
128804184
result:
Test #8:
score: 0
Memory Limit Exceeded
input:
10 100 1 1 4 2 2 4 3 2 4 2 3 2 3 1 1 2 2 1 2 3 3 4 4 2 2 2 1 3 2 3 4 3 1 2 2 4 4 2 1 4 3 2 4 4 1 1 3 4 4 4 1 2 3 2 4 2 3 1 2 1 1 2 2 3 2 4 2 2 2 2 4 2 4 4 2 1 3 1 2 1 2 3 2 2 3 2 2 4 2 2 3 2 2 4 4 4 1 2 3 2 100 2 3 2 3 3 3 3 2 2 2 1 3 1 2 3 4 3 3 3 3 4 2 3 4 1 1 2 3 3 3 1 4 4 1 4 2 4 3 2 3 4 4 1 3 2...
output:
770535784 8639826 668139917 312555143 286027664 718965700 261541718 279692629 648560063 882825635
result:
Test #9:
score: 0
Memory Limit Exceeded
input:
10 100 4 1 4 1 4 2 3 4 1 2 1 3 2 4 2 2 3 4 2 4 3 1 3 3 4 2 3 4 3 1 2 2 2 2 4 4 2 1 1 2 1 2 4 3 1 2 2 1 1 2 1 3 2 4 4 3 2 3 4 1 1 2 2 2 2 3 4 3 4 2 2 1 2 1 2 3 4 1 3 2 1 3 3 1 4 3 1 1 2 4 4 1 4 3 3 2 1 1 2 2 100 1 2 3 2 1 4 1 4 3 3 1 2 3 3 4 3 4 2 2 3 3 2 3 3 3 3 2 2 1 1 1 1 2 2 2 4 1 4 3 1 3 3 3 4 2...
output:
516267374 806311785 599711045 116059671 697689593 426199360 549668754 868315514 664867866 478371148
result:
Test #10:
score: 0
Memory Limit Exceeded
input:
10 100 1 2 3 2 2 1 1 2 1 1 1 4 2 1 1 1 1 2 2 2 1 2 4 2 4 3 1 4 3 3 3 1 4 1 3 4 3 3 3 4 2 3 3 3 4 3 2 4 4 2 4 4 4 1 1 1 3 1 4 2 3 1 4 4 4 4 1 3 1 3 4 4 4 1 4 3 2 1 2 1 3 2 2 3 2 1 2 4 4 4 1 4 3 2 3 2 4 2 1 4 100 3 1 3 1 2 2 1 2 1 3 1 1 4 1 1 1 1 1 2 3 2 4 3 2 4 1 2 4 4 2 1 1 2 4 1 4 2 1 2 1 2 3 2 2 1...
output:
756252443 457732568 613138682 779478365 186904726 704135227 123746526 570511537 928701614 662470294
result:
Test #11:
score: 0
Memory Limit Exceeded
input:
10 100 8 3 1 5 7 5 8 9 5 6 3 1 2 8 8 3 2 3 1 2 7 7 10 9 1 4 6 9 9 2 7 1 8 9 3 8 10 6 8 2 6 5 2 8 4 6 7 2 5 9 5 2 7 3 6 1 7 1 7 8 9 1 6 7 10 4 4 6 1 4 4 5 2 1 9 9 1 5 7 2 6 8 9 2 2 8 9 9 4 4 8 6 3 9 9 10 4 5 2 9 100 4 3 1 2 9 9 2 7 4 6 10 5 10 4 5 6 9 2 3 2 6 4 10 7 6 4 6 1 1 6 4 2 1 1 4 3 4 7 8 3 1 ...
output:
1806336 252813312 258048 18063360 408706560 64512 122425344 1045440 6355584 244021248
result:
Test #12:
score: 0
Memory Limit Exceeded
input:
10 100 193563111 193563110 193563109 193563108 193563109 193563108 193563109 193563109 193563110 193563111 193563110 193563110 193563109 193563111 193563110 193563109 193563108 193563110 193563109 193563107 193563108 193563110 193563110 193563110 193563109 193563110 193563108 193563107 193563106 193...
output:
971137206 861715675 437545959 14882745 660660617 87603105 261736261 917678019 873448891 436534075
result:
Test #13:
score: 0
Memory Limit Exceeded
input:
10 100 165531093 165531092 165531090 165531090 165531088 165531089 165531089 165531090 165531091 165531090 165531090 165531091 165531089 165531089 165531089 165531087 165531088 165531088 165531086 165531086 165531085 165531084 165531084 165531083 165531084 165531083 165531084 165531084 165531085 165...
output:
262239238 251503983 976300819 799259141 756228907 505220560 261297294 670540576 457827061 868775931
result:
Test #14:
score: 0
Memory Limit Exceeded
input:
5 1000 835051605 835051606 835051607 835051608 835051609 835051609 835051608 835051608 835051609 835051610 835051609 835051609 835051609 835051610 835051610 835051609 835051609 835051608 835051607 835051607 835051606 835051606 835051606 835051606 835051605 835051606 835051606 835051606 835051604 835...
output:
205132456 32832155 790052559 445942178 920397136
result:
Test #15:
score: 0
Memory Limit Exceeded
input:
5 1000 551842461 551842460 551842459 551842459 551842457 551842457 551842459 551842458 551842456 551842455 551842456 551842458 551842459 551842457 551842457 551842458 551842456 551842456 551842455 551842454 551842452 551842451 551842453 551842451 551842453 551842453 551842453 551842454 551842453 551...
output:
768512128 881764802 48988069 513826253 778778921
result:
Test #16:
score: 0
Memory Limit Exceeded
input:
5 1000 911411059 911411057 911411057 911411055 911411055 911411053 911411054 911411055 911411056 911411055 911411055 911411055 911411054 911411055 911411056 911411058 911411058 911411058 911411057 911411058 911411059 911411059 911411060 911411060 911411060 911411059 911411059 911411059 911411060 911...
output:
618787458 856920959 282170842 30485208 951629355
result:
Test #17:
score: 0
Memory Limit Exceeded
input:
5 1000 239756971 239756970 239756971 239756970 239756969 239756970 239756969 239756970 239756969 239756968 239756969 239756968 239756969 239756969 239756968 239756967 239756966 239756966 239756967 239756966 239756966 239756966 239756966 239756966 239756967 239756965 239756966 239756967 239756967 239...
output:
19357840 197392992 219496167 491253147 267552308
result:
Test #18:
score: 0
Memory Limit Exceeded
input:
1 5000 316394141 316394140 316394140 316394141 316394141 316394141 316394141 316394140 316394140 316394141 316394140 316394141 316394141 316394140 316394141 316394141 316394141 316394140 316394140 316394139 316394140 316394139 316394139 316394139 316394139 316394140 316394140 316394140 316394139 316...
output:
797665947
result:
Test #19:
score: 0
Memory Limit Exceeded
input:
1 5000 698334028 698334028 698334027 698334028 698334028 698334028 698334028 698334027 698334027 698334028 698334028 698334028 698334027 698334027 698334027 698334028 698334028 698334027 698334028 698334028 698334027 698334028 698334028 698334027 698334028 698334027 698334028 698334027 698334028 698...
output:
822167115
result:
Test #20:
score: 0
Memory Limit Exceeded
input:
1 5000 104725913 104725912 104725912 104725912 104725912 104725913 104725913 104725913 104725913 104725912 104725913 104725913 104725912 104725912 104725912 104725912 104725913 104725912 104725913 104725912 104725913 104725913 104725913 104725913 104725913 104725912 104725913 104725912 104725913 104...
output:
991498966
result:
Test #21:
score: 0
Memory Limit Exceeded
input:
1 5000 631500634 631500634 631500634 631500633 631500634 631500633 631500634 631500634 631500633 631500633 631500634 631500634 631500634 631500634 631500633 631500633 631500635 631500634 631500634 631500634 631500635 631500635 631500634 631500634 631500634 631500634 631500635 631500634 631500634 631...
output:
393101528