QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#344874 | #3809. Wooden Signs | KhNURE_KIVI# | AC ✓ | 15ms | 35100kb | C++14 | 2.1kb | 2024-03-05 16:58:20 | 2024-03-05 16:58:20 |
Judging History
answer
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef KIVI
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template <class ...Ts> auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif
const int max_n = 2000+10, inf = 1000111222;
const ll mod = 2147483647;
ll dp[max_n][max_n];
void inc(ll& a,ll b)
{
a+=b;
if (a>=mod){
a-=mod;
}
}
int a[max_n];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
for (int i=0;i<=n;i++){
cin>>a[i];
}
dp[1][a[0]]=1;
for (int i=1;i<n;i++){
for (int j=1;j<=n+1;j++){
int L=j;
int R=a[i];
if (L>R){
swap(L,R);
}
if (L<=a[i+1] && a[i+1]<=R){
inc(dp[i+1][j],dp[i][j]);
inc(dp[i+1][a[i]],dp[i][j]);
}
else if (a[i+1]<L){
inc(dp[i+1][R],dp[i][j]);
}
else if (a[i+1]>R){
inc(dp[i+1][L],dp[i][j]);
}
else{
assert(0);
}
}
}
ll ans=0;
for (int i=1;i<=n+1;i++){
inc(ans,dp[n][i]);
}
cout<<ans<<"\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
5 2 6 5 1 4 3
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
17 7 16 14 9 11 4 6 3 8 5 12 10 18 15 1 2 17 13
output:
468
result:
ok single line: '468'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3872kb
input:
50 13 31 46 33 50 9 25 40 32 23 38 2 37 4 16 7 5 22 39 44 15 3 29 43 14 45 8 12 51 11 10 28 26 21 24 17 6 20 36 48 30 35 42 41 1 27 47 34 49 18 19
output:
6183172
result:
ok single line: '6183172'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
45 10 38 6 14 44 20 13 12 2 37 5 41 19 40 31 33 23 29 27 45 24 46 9 3 42 18 43 39 35 15 1 32 25 36 16 30 26 22 17 28 8 11 7 4 21 34
output:
623448
result:
ok single line: '623448'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3992kb
input:
79 2 9 22 10 44 34 45 32 58 31 78 64 5 79 63 57 52 80 75 60 38 35 68 73 3 13 7 65 48 24 70 40 16 21 37 17 30 28 41 53 59 14 46 43 72 11 62 33 18 67 51 69 23 66 12 56 27 4 71 61 19 42 20 77 47 25 6 54 29 74 8 15 39 1 76 49 55 36 50 26
output:
343336771
result:
ok single line: '343336771'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4344kb
input:
131 14 109 100 4 75 121 89 117 88 18 54 37 13 72 34 24 78 116 58 120 2 130 49 77 93 124 15 113 48 108 123 43 3 84 6 70 47 57 5 52 105 40 122 61 64 79 41 16 132 46 129 10 22 31 103 12 107 30 1 32 68 131 81 66 60 97 45 38 115 90 73 127 74 29 128 71 23 65 59 56 33 94 17 27 101 102 36 83 86 118 114 91 9...
output:
749976819
result:
ok single line: '749976819'
Test #7:
score: 0
Accepted
time: 4ms
memory: 8252kb
input:
551 81 85 34 395 443 520 513 170 31 315 75 164 510 104 408 481 374 305 110 303 152 362 214 538 5 155 232 55 262 37 182 338 125 432 457 431 256 84 309 62 21 174 163 403 489 184 20 66 547 530 300 485 503 181 401 26 498 43 79 77 157 158 146 269 398 385 383 279 377 274 219 210 328 389 255 447 528 537 74...
output:
166961433
result:
ok single line: '166961433'
Test #8:
score: 0
Accepted
time: 8ms
memory: 35100kb
input:
1999 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:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 4ms
memory: 34908kb
input:
1999 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:
930888
result:
ok single line: '930888'
Test #10:
score: 0
Accepted
time: 3ms
memory: 30872kb
input:
1998 123 1061 505 404 1401 1019 188 1139 1134 584 516 1774 702 502 986 498 1307 941 1094 461 916 1886 830 1993 878 1695 802 1309 320 803 213 683 678 1870 385 909 866 1535 989 1303 1885 473 1668 1163 1444 1129 1560 524 336 1437 715 268 1468 1661 99 1938 1818 1489 660 75 1070 442 543 282 1563 1296 146...
output:
358116858
result:
ok single line: '358116858'
Test #11:
score: 0
Accepted
time: 15ms
memory: 30588kb
input:
1999 1329 1556 906 428 394 989 1070 1562 1948 1847 1250 1907 757 848 1746 713 741 613 1242 942 1128 336 1774 154 1450 1225 1766 513 1129 160 1233 1771 800 1100 923 534 56 1108 629 415 1795 1559 111 177 151 1591 1144 1111 1951 886 1757 735 1474 456 1850 1730 30 1468 1018 117 1472 192 1794 1217 1578 1...
output:
1126786552
result:
ok single line: '1126786552'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
2 2 3 1
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 13ms
memory: 26396kb
input:
1999 1 2000 2 1999 3 1998 4 1997 5 1996 6 1995 7 1994 8 1993 9 1992 10 1991 11 1990 12 1989 13 1988 14 1987 15 1986 16 1985 17 1984 18 1983 19 1982 20 1981 21 1980 22 1979 23 1978 24 1977 25 1976 26 1975 27 1974 28 1973 29 1972 30 1971 31 1970 32 1969 33 1968 34 1967 35 1966 36 1965 37 1964 38 1963 ...
output:
1474051619
result:
ok single line: '1474051619'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
20 3 21 10 15 6 9 2 5 20 13 17 19 14 7 11 18 16 12 1 8 4
output:
1887
result:
ok single line: '1887'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
1 1 2
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
7 4 6 2 8 3 7 1 5
output:
6
result:
ok single line: '6'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
7 4 6 2 8 3 7 5 1
output:
5
result:
ok single line: '5'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
7 1 4 6 2 8 3 7 5
output:
10
result:
ok single line: '10'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
9 9 10 8 7 6 5 4 3 2 1
output:
1
result:
ok single line: '1'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
9 9 10 6 5 4 7 8 3 2 1
output:
3
result:
ok single line: '3'