QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#130206#5035. foo~pandapythoner#20 109ms34992kbC++202.7kb2023-07-23 17:50:552024-07-04 00:54:49

Judging History

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

  • [2024-07-04 00:54:49]
  • 评测
  • 测评结果:20
  • 用时:109ms
  • 内存:34992kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-23 17:50:55]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

int n, k;
vector<int> a;

ll solve_slow(vector<int> b) {
    if (k == 1) {
        int rs = 0;
        int mx = -1;
        int cnt = 0;
        vector<int> stck;
        for (int i = 0; i < n; i += 1) {
            if (b[i] >= mx) {
                cnt += 1;
                mx = b[i];
            }
            rs = max(rs, cnt);
            while(!stck.empty() && stck.back() < b[i]){
                stck.pop_back();
                stck.push_back(b[i]);
            }
            rs = max(rs, (int)stck.size());
        }
        return rs;
    }
    vector<vector<int>> d(n + 1, vector<int>(n + 1, 0));
    for (int l = 0; l <= n; l += 1) {
        int mx = -1;
        int cnt = 0;
        for (int r = l + 1; r <= n; r += 1) {
            if (b[r - 1] >= mx) {
                mx = b[r - 1];
                cnt += 1;
            }
            d[l][r] = max(d[l][r], cnt);
        }
    }
    for (int r = n; r >= 0; r -= 1) {
        int mx = -1;
        int cnt = 0;
        for (int l = r - 1; l >= 0; l -= 1) {
            if (b[l] >= mx) {
                mx = b[l];
                cnt += 1;
            }
            d[l][r] = max(d[l][r], cnt);
        }
    }
    vector<vector<int>> dp(n + 1, vector<int>(k + 1, -n));
    dp[0][0] = 0;
    int rs = 0;
    for (int i = 1; i <= n; i += 1) {
        for (int j = 0; j < i; j += 1) {
            for (int c = 0; c < k; c += 1) {
                dp[i][c + 1] = max(dp[i][c + 1], dp[j][c] + d[j][i]);
            }
        }
        rs = max(rs, dp[i][k]);
    }
    return rs;
}

ll solve_slow() {
    if (n == 1) {
        return 1;
    }
    auto b = a;
    int mx_i = 0;
    for (int i = 1; i < n; i += 1) {
        if (b[i] > b[mx_i]) {
            mx_i = i;
        }
    }
    rotate(b.begin(), b.begin() + mx_i, b.end());
    ll rs = solve_slow(b);
    rotate(b.begin(), b.begin() + 1, b.end());
    reverse(all(b));
    rs = max(rs, solve_slow(b));
    /*
    for(int itr = 0; itr < n; itr += 1){
        rotate(b.begin(), b.begin() + 1, b.end());
        rs = max(rs, solve_slow(b));
    }
    */
    return rs;
}

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i += 1) {
        cin >> a[i];
        --a[i];
    }
    ll rs = solve_slow();
    cout << rs << "\n";
    return 0;
}

/*
16 2
15 12 14 9 11 13 1 3 10 8 5 2 16 4 6 7


*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 1ms
memory: 3544kb

input:

23 6
16 20 22 4 21 10 3 7 5 8 15 12 9 1 6 17 23 13 11 19 18 14 2

output:

20

result:

ok "20"

Test #2:

score: 10
Accepted
time: 0ms
memory: 3780kb

input:

13 6
13 9 3 4 12 6 5 1 8 10 11 7 2

output:

13

result:

ok "13"

Test #3:

score: 10
Accepted
time: 0ms
memory: 3580kb

input:

25 3
25 2 3 19 5 6 7 11 8 10 9 20 4 14 21 1 17 12 13 18 15 22 23 16 24

output:

16

result:

ok "16"

Test #4:

score: 10
Accepted
time: 0ms
memory: 3476kb

input:

25 9
1 11 10 23 9 24 7 8 19 3 5 21 18 12 15 16 17 13 2 20 14 22 4 6 25

output:

23

result:

ok "23"

Test #5:

score: 10
Accepted
time: 0ms
memory: 3560kb

input:

13 2
1 4 2 3 5 6 7 8 9 10 12 11 13

output:

12

result:

ok "12"

Test #6:

score: 10
Accepted
time: 0ms
memory: 3576kb

input:

17 5
4 2 3 6 5 1 7 8 13 16 11 12 9 14 15 10 17

output:

15

result:

ok "15"

Test #7:

score: 10
Accepted
time: 0ms
memory: 3468kb

input:

8 2
1 2 5 6 3 4 7 8

output:

8

result:

ok "8"

Test #8:

score: 10
Accepted
time: 0ms
memory: 3476kb

input:

11 5
3 11 2 10 6 5 1 4 8 7 9

output:

11

result:

ok "11"

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 3772kb

input:

10 1
5 3 4 1 10 8 9 6 7 2

output:

1

result:

wrong answer 1st words differ - expected: '6', found: '1'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 3ms
memory: 5404kb

input:

93943 1
87243 48984 50611 19218 77699 25025 85769 28141 13380 34875 42459 66419 53472 4367 48292 16894 92171 87263 42527 67085 30687 29235 27515 81053 31421 34864 83591 70491 75344 7026 50250 63402 26773 5330 36308 76399 80032 15501 16205 71750 73964 67876 68901 70548 2043 79979 89479 19784 38838 44...

output:

1

result:

wrong answer 1st words differ - expected: '25', found: '1'

Subtask #3:

score: 20
Accepted

Test #36:

score: 20
Accepted
time: 97ms
memory: 34856kb

input:

1992 25
144 612 1315 1966 1779 1773 1529 625 36 1849 1783 1441 1388 1558 1258 724 137 397 542 353 1162 1213 406 792 1317 882 994 298 1864 1969 103 449 508 1501 89 1721 195 778 657 222 1152 1780 613 743 1206 694 829 142 69 1973 1465 1343 655 1540 155 146 350 491 759 1695 1082 1357 1329 1745 232 1850 ...

output:

237

result:

ok "237"

Test #37:

score: 20
Accepted
time: 77ms
memory: 34540kb

input:

1992 17
785 891 1027 155 773 587 1829 255 1239 1893 1854 158 349 370 1134 1739 1186 11 1099 1149 481 361 1101 1359 1773 1568 157 1011 79 555 254 285 1260 1722 1684 577 1054 1932 590 1804 414 1415 376 1699 26 971 1554 1504 1987 1327 1184 610 652 1432 206 129 315 1390 1946 64 910 962 1189 326 497 1580...

output:

172

result:

ok "172"

Test #38:

score: 20
Accepted
time: 0ms
memory: 3612kb

input:

46 11
41 44 2 9 30 46 28 14 12 20 38 37 19 6 13 7 26 4 34 15 32 5 35 1 25 8 29 45 31 22 18 24 33 42 21 17 39 10 43 11 23 27 36 3 40 16

output:

38

result:

ok "38"

Test #39:

score: 20
Accepted
time: 1ms
memory: 3508kb

input:

53 18
29 23 32 11 24 27 28 16 6 9 3 20 8 38 43 49 18 26 41 53 31 19 48 34 44 52 45 5 30 17 2 13 15 40 1 50 21 14 4 22 51 35 39 7 47 25 10 12 33 42 36 46 37

output:

49

result:

ok "49"

Test #40:

score: 20
Accepted
time: 1ms
memory: 3612kb

input:

55 25
42 41 51 1 6 49 28 12 33 23 31 47 19 24 48 21 54 16 14 3 26 43 18 5 45 29 50 15 44 35 7 40 9 53 10 32 17 36 4 34 20 38 37 8 55 2 11 39 30 22 52 27 13 46 25

output:

55

result:

ok "55"

Test #41:

score: 20
Accepted
time: 1ms
memory: 3548kb

input:

78 9
44 4 68 49 20 16 67 3 70 40 25 6 46 27 65 10 77 55 12 78 2 31 22 71 74 30 41 53 34 47 32 36 57 19 18 1 26 69 11 52 72 14 8 17 56 51 42 43 62 58 35 76 66 23 54 73 63 75 39 37 28 5 9 24 21 48 64 61 29 45 38 13 59 50 15 7 33 60

output:

42

result:

ok "42"

Test #42:

score: 20
Accepted
time: 0ms
memory: 3584kb

input:

17 2
11 4 3 1 5 14 17 8 7 6 2 16 9 10 13 15 12

output:

12

result:

ok "12"

Test #43:

score: 20
Accepted
time: 89ms
memory: 34992kb

input:

1998 17
333 1769 698 1064 655 451 102 8 1306 1092 213 750 1963 1122 759 890 1170 1700 87 820 175 196 1617 370 1693 1993 1927 851 832 864 299 607 1174 1994 1584 1962 1047 1000 1829 164 209 649 942 660 118 1010 1114 1291 1418 1819 540 1861 536 1745 328 1358 1394 677 59 1842 578 257 1776 770 1850 783 9...

output:

172

result:

ok "172"

Test #44:

score: 20
Accepted
time: 73ms
memory: 34768kb

input:

1995 11
781 851 1465 1961 351 876 477 1746 14 1703 68 983 1857 87 551 1314 1877 978 1821 606 244 1269 1638 1062 952 586 735 1302 1190 1644 1554 1328 1614 257 1306 1964 1232 1005 382 335 680 1725 530 1253 903 361 979 1174 1813 1811 557 1123 1580 1445 595 1098 318 1192 1406 297 463 1837 1271 325 1990 ...

output:

126

result:

ok "126"

Test #45:

score: 20
Accepted
time: 94ms
memory: 34972kb

input:

1998 20
344 764 1060 1773 951 1962 1555 1410 1263 985 1665 1666 1010 816 1462 181 1208 1574 142 583 338 1026 1336 1323 1787 134 1397 1177 1632 1445 632 871 1180 1171 716 681 1014 478 1068 1678 620 1379 1799 1256 124 569 112 1432 499 1832 1235 492 690 485 335 1860 1976 1325 1667 1505 1723 1851 1598 9...

output:

199

result:

ok "199"

Test #46:

score: 20
Accepted
time: 70ms
memory: 34784kb

input:

1996 14
1647 582 573 13 273 1391 1373 1996 1526 191 605 1254 1943 1108 1264 1306 1120 642 832 1826 1301 557 761 1170 1117 1688 982 1153 863 1879 1433 1533 981 1570 789 561 189 1830 1075 276 1444 522 168 1595 1140 1522 1532 1314 930 161 478 468 928 1850 439 681 1781 96 1836 446 669 1545 138 1040 180 ...

output:

161

result:

ok "161"

Test #47:

score: 20
Accepted
time: 35ms
memory: 34504kb

input:

1991 5
1932 254 1190 786 1024 1473 617 1462 790 1056 928 1627 1149 1452 300 957 336 1720 1157 592 1241 1750 391 1092 1007 1710 1250 362 127 655 433 876 1776 359 559 109 1053 1267 674 776 1238 1132 1060 608 988 1411 565 1868 1290 1025 1929 1712 1120 1066 1208 1940 1011 1648 980 330 397 1646 360 118 1...

output:

65

result:

ok "65"

Test #48:

score: 20
Accepted
time: 41ms
memory: 34664kb

input:

1999 2
860 1838 1580 1476 996 1339 706 873 1880 1600 1240 1220 1243 232 1690 629 217 1944 1284 1829 1693 749 1298 1342 1045 964 1910 638 697 219 420 1343 681 880 302 1224 1621 521 1988 89 1534 1514 655 1983 1574 1091 410 1881 1842 1062 1496 1739 1194 200 386 936 16 242 1513 187 1025 949 1377 589 180...

output:

33

result:

ok "33"

Test #49:

score: 20
Accepted
time: 109ms
memory: 34784kb

input:

1993 28
1506 46 293 1509 509 379 1928 76 381 1745 1712 805 1172 1908 696 362 1927 1892 1822 534 1233 1665 1100 664 1060 1458 1381 93 119 82 43 292 1360 996 907 1586 1022 1757 1482 1545 1406 303 338 1876 1635 611 1645 1485 1862 218 1303 1002 156 1649 951 1981 1992 1349 305 978 531 1195 1693 1370 1541...

output:

269

result:

ok "269"

Test #50:

score: 20
Accepted
time: 39ms
memory: 34648kb

input:

1996 3
1104 382 1454 599 258 1354 486 1288 1375 1677 413 695 1485 1733 1962 1338 13 17 150 629 937 948 1181 698 141 966 1207 286 651 434 165 519 180 1542 1009 766 1344 1112 1178 1074 1487 1944 1722 1603 1165 648 1054 1568 997 1103 1062 874 1448 750 84 1920 1898 77 1410 388 439 1996 172 807 1647 39 1...

output:

42

result:

ok "42"

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%