QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377369#7990. 广播plutosAC ✓15ms19664kbC++171.4kb2024-04-05 12:55:312024-04-05 12:55:32

Judging History

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

  • [2024-04-05 12:55:32]
  • 评测
  • 测评结果:AC
  • 用时:15ms
  • 内存:19664kb
  • [2024-04-05 12:55:31]
  • 提交

answer

#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
template <class T> constexpr auto NL(T) -> T {return std::numeric_limits<T>::max();}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
constexpr int maxn = 2010;
int dp[maxn][maxn];
void solve(void) {
    ll n, m;
    cin >> n >> m;
    memset(dp, 0x3f3f3f3f, sizeof dp);
    std::vector<ll> a1(n + 2);
    for (int i = 1; i <= n; i++) {
        cin >> a1[i];
    }
    std::vector<ll> b1(m + 2);
    for (int i = 1; i <= m; i++) {
        cin >> b1[i];
    }
    dp[n + 1][m + 1] = 0;
    for (int i = n + 1; i >= 1; i--) {
        for (int j = m + 1; j >= 1; j--) {
            if (a1[i] == b1[j] or a1[i] == 1 or b1[j] == 1) {
                dp[i][j] = min(dp[i][j], dp[i + 1][j + 1]);
            }
            dp[i][j] = min(dp[i][j], dp[i][j + 1] + 1);
            dp[i][j] = min(dp[i][j], dp[i + 1][j] + 1);
        }
    }
    int ans = NL(ans);
    for (int i = 1; i <= n + 1; i++) {
        ans = min(ans, dp[i][1]);
    }
    for (int i = 1; i <= m + 1; i++) {
        ans = min(ans, dp[1][i]);
    }
    cout << ans;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int t = 1;
    // cin>>t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2
2 1 3 2
4 2

output:

1

result:

ok single line: '1'

Test #2:

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

input:

1 1
2
3

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 13ms
memory: 19644kb

input:

1997 1970
1235 1225 1169 368 1 1 1444 1 1189 775 788 114 1609 1169 821 1708 821 1370 1444 1356 775 1747 1661 775 1692 1960 788 1866 382 1444 1356 1868 309 788 1609 211 1160 1225 1370 1609 1692 1064 1356 788 1707 775 1707 1064 1356 1160 1692 368 129 1235 1868 1370 1160 775 368 129 1747 334 1503 1444 ...

output:

1813

result:

ok single line: '1813'

Test #4:

score: 0
Accepted
time: 14ms
memory: 19632kb

input:

2000 1999
251 690 1357 1183 815 1939 1665 251 1070 354 783 1901 386 521 69 960 1 295 295 632 215 920 1763 69 1575 1246 1 1720 743 1192 959 830 595 1073 655 1763 301 632 518 319 1371 1844 768 501 400 1362 1533 1776 1319 241 178 1447 9 1339 1192 603 1 461 1113 396 1532 738 955 1005 835 690 430 495 119...

output:

1951

result:

ok single line: '1951'

Test #5:

score: 0
Accepted
time: 9ms
memory: 19384kb

input:

1953 1948
1468 1492 655 1311 777 954 579 1290 1778 630 1048 1026 1605 1522 1919 552 1813 1074 64 1586 30 1319 1612 1808 518 141 251 254 503 202 484 699 1518 290 856 1199 852 1421 1322 618 264 1921 1744 261 418 581 291 871 523 1783 410 1316 1040 599 1298 490 1738 1951 3 435 572 1465 566 167 182 1694 ...

output:

1920

result:

ok single line: '1920'

Test #6:

score: 0
Accepted
time: 8ms
memory: 19384kb

input:

1953 1944
615 1448 206 615 206 615 1941 1448 206 206 1316 1448 1448 1 1941 1448 615 615 1448 615 206 1448 615 206 1448 206 1941 1448 206 1941 206 1316 1316 1316 1316 1316 1941 615 615 615 1941 1316 1941 615 1941 1448 1316 1941 615 1448 1316 206 1316 615 1941 206 615 1941 206 615 206 1448 1448 615 13...

output:

1224

result:

ok single line: '1224'

Test #7:

score: 0
Accepted
time: 11ms
memory: 19340kb

input:

1996 1974
1538 421 1833 464 1912 925 1538 647 483 713 421 647 1912 1818 1547 451 925 713 173 647 1235 1269 1818 421 1818 616 1577 1833 26 1273 416 290 483 713 290 1818 1093 713 1 26 1912 1616 1912 416 1235 421 421 1063 290 1873 1063 1577 1563 26 1063 1 925 1235 616 464 1912 1833 1833 1251 483 483 12...

output:

1738

result:

ok single line: '1738'

Test #8:

score: 0
Accepted
time: 14ms
memory: 19628kb

input:

1993 1973
187 634 1429 792 1765 1464 303 1545 1318 1673 1960 203 175 106 290 1484 710 857 175 1438 5 143 1475 1967 1842 1476 1 947 842 1967 868 1 1736 1727 1 608 1934 1825 750 1864 518 336 1765 184 323 1913 262 141 1270 719 470 854 1474 1932 571 568 1484 1545 256 685 1565 601 1154 1082 1687 1 1393 1...

output:

1866

result:

ok single line: '1866'

Test #9:

score: 0
Accepted
time: 7ms
memory: 19392kb

input:

1982 1987
553 461 320 85 1753 1329 1836 1036 861 1972 621 1377 265 564 387 229 340 1841 158 702 743 1020 1213 700 1196 159 713 396 1657 1356 529 826 1689 1739 1 998 1516 1597 879 1167 1 1385 299 315 1220 1279 315 1240 112 1194 1293 488 513 1596 1270 26 997 2000 1565 726 559 823 751 1132 564 287 1356...

output:

1863

result:

ok single line: '1863'

Test #10:

score: 0
Accepted
time: 15ms
memory: 19384kb

input:

1988 2000
1530 76 1231 1530 1 1530 1530 290 1530 290 290 290 1231 1274 1274 1530 1530 690 1231 1231 1231 1231 76 76 1274 290 1 1 76 1530 1530 76 1231 76 76 1 290 1231 290 290 1231 1231 1 290 1530 290 290 22 186 1 1530 76 1530 1231 1274 1530 1530 1530 76 1274 1274 1274 1 76 1231 1274 76 1 1 290 1530 ...

output:

787

result:

ok single line: '787'

Test #11:

score: 0
Accepted
time: 11ms
memory: 19336kb

input:

1937 1985
1763 1 1227 1909 900 1212 1502 895 1314 181 181 1704 1 376 794 1374 1909 507 1936 1354 1354 1075 1 507 1 1 376 1 544 70 895 1314 376 1 1961 592 181 1354 1 1 1961 507 1374 1227 1212 166 1201 1 1 794 1 124 1502 1801 923 1 592 544 181 1801 923 592 1 794 376 166 1 124 592 1354 544 1212 1909 16...

output:

898

result:

ok single line: '898'

Test #12:

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

input:

1986 1989
251 344 1086 1001 1177 846 184 858 115 1684 1145 659 1186 1076 54 622 954 1783 253 1026 1404 472 355 1281 394 1602 1624 305 1939 1080 386 1966 1862 1006 1508 1 1730 1342 834 1508 1994 1296 1 1693 1076 1378 1096 377 363 834 858 1912 1 594 1836 1319 1 1250 466 129 1 1225 1939 1944 1056 1 574...

output:

917

result:

ok single line: '917'

Test #13:

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

input:

1 1
1
1

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 7ms
memory: 19420kb

input:

1950 1932
459 1890 1 1 1 1469 1566 1156 1 480 1349 1641 1220 572 41 1465 579 1417 642 640 1151 1440 944 1670 1151 438 103 1267 1269 944 1128 1864 770 832 657 1604 1300 413 497 1 384 104 344 350 499 168 874 590 219 143 1561 534 1431 291 1530 590 1 1270 1079 1 103 1178 1487 1452 544 320 1491 1934 1380...

output:

836

result:

ok single line: '836'

Test #15:

score: 0
Accepted
time: 15ms
memory: 19396kb

input:

1993 1999
339 1 729 745 1 339 115 339 1 729 115 729 339 729 1 1562 1562 745 729 1 115 1 1 339 115 339 1562 729 339 1562 1 1 729 1 115 745 1 115 745 1 745 1 745 1 729 115 115 1 745 1562 729 339 729 115 339 745 729 729 1562 1 729 1562 729 729 1562 115 745 1 1562 1 745 115 339 1 729 1 1 745 115 745 745...

output:

136

result:

ok single line: '136'

Test #16:

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

input:

1960 1947
351 507 1792 1580 120 1792 1792 1715 584 1129 66 1030 351 1 507 1254 1 1548 525 497 1580 1 962 507 1792 1925 1580 21 1397 1397 1 21 1730 682 1598 1 1955 459 1 1 1079 1792 295 1079 1792 1365 1948 1086 1 1955 1730 584 1967 1151 1715 1 1727 1 1397 1598 507 1955 1955 1548 1 1 1 1150 507 1 1730...

output:

121

result:

ok single line: '121'

Test #17:

score: 0
Accepted
time: 11ms
memory: 19352kb

input:

2000 1997
1566 1 788 52 646 542 1705 855 786 1989 1 186 855 1 1 234 1 1263 823 1758 820 1006 1437 1151 995 1956 1516 823 70 1553 1167 461 1 1064 902 1067 493 1519 676 149 827 372 493 1159 391 950 67 369 1036 1756 1941 1 1 377 1 1 178 1442 76 1782 1 1 1 1341 1 512 1737 584 1328 1591 1680 611 340 1006...

output:

209

result:

ok single line: '209'

Test #18:

score: 0
Accepted
time: 9ms
memory: 19388kb

input:

1964 1953
1 1810 433 1257 1 1499 1 1325 796 980 1123 1 1885 1 1 1182 1398 667 115 334 1762 1259 1 1740 937 1847 1688 177 1054 256 160 1486 1391 576 1408 648 437 1 677 684 1590 1288 1126 1049 1 128 1 452 587 1469 257 1 411 438 1 1922 1030 1120 1416 111 425 1 1184 1773 1 405 1 1 477 13 174 954 593 1 1...

output:

151

result:

ok single line: '151'

Test #19:

score: 0
Accepted
time: 6ms
memory: 19648kb

input:

2000 1759
1853 1716 1865 1828 491 1276 590 97 893 1128 384 1949 1360 1334 1162 639 657 1299 1122 1562 1212 189 1857 844 1718 438 1 463 1032 113 1427 1240 130 269 80 1844 1517 787 1828 1984 26 970 1859 189 1 1046 1400 395 787 1060 1246 1733 564 1996 1277 539 304 1766 1733 269 1 1877 688 844 1781 1614...

output:

481

result:

ok single line: '481'

Test #20:

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

input:

1 1
2
2

output:

0

result:

ok single line: '0'

Test #21:

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

input:

1 1
1
2

output:

0

result:

ok single line: '0'

Test #22:

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

input:

1999 1999
299 399 710 710 948 399 710 399 948 710 399 299 299 1542 299 948 299 1542 299 399 399 1542 948 399 399 710 710 710 710 299 299 710 948 399 399 1542 710 299 710 948 1542 399 710 710 948 948 299 1542 299 710 1542 399 299 948 399 948 710 299 710 399 948 948 1542 1542 299 1542 399 948 710 710 ...

output:

1359

result:

ok single line: '1359'

Test #23:

score: 0
Accepted
time: 8ms
memory: 19664kb

input:

1958 1915
1947 801 1181 899 1922 1947 265 270 1947 1181 1969 1967 1969 1967 1007 265 646 1967 646 1947 550 1969 899 1969 1677 1055 1824 1947 1235 1963 1922 1677 197 1055 550 1824 1969 1356 899 1969 1055 1748 1107 1699 1969 1055 1699 801 1967 1038 899 801 1922 197 1495 197 1969 270 1696 1824 1936 197...

output:

1805

result:

ok single line: '1805'

Test #24:

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

input:

1966 1964
83 1729 1569 1810 639 1369 1634 1291 1217 1548 1322 253 558 370 1802 15 594 739 1216 1186 1689 199 1701 1209 607 1930 736 1085 409 1541 1250 688 1010 1689 792 1701 1236 1177 1434 1835 253 1216 1596 1279 1431 409 1676 1930 1231 437 1741 1825 1754 1943 1596 298 972 1690 406 1404 1912 1073 74...

output:

1944

result:

ok single line: '1944'

Test #25:

score: 0
Accepted
time: 9ms
memory: 19300kb

input:

1985 2000
864 1885 213 905 1741 1312 112 1527 1356 1411 31 1368 413 1804 559 1636 1731 1135 1609 274 1658 396 28 1542 1724 1289 1884 213 1112 1130 697 1326 745 710 1422 556 1243 1746 1455 262 1584 1358 1459 1666 1182 1997 1085 1877 1441 1147 800 663 1650 227 644 1114 765 762 325 1889 1155 473 1885 6...

output:

1979

result:

ok single line: '1979'

Test #26:

score: 0
Accepted
time: 13ms
memory: 19392kb

input:

1977 1995
900 144 144 296 144 296 900 900 1308 144 543 1308 144 543 1308 1308 144 543 1308 296 217 144 1308 543 900 296 296 543 296 900 900 900 296 1308 900 1308 296 1308 296 144 1308 900 296 144 543 543 900 144 144 1308 296 543 543 144 1308 1308 1308 543 543 1308 144 1308 900 144 440 1308 296 1308 ...

output:

1332

result:

ok single line: '1332'