From 1130014c886ebaa3e43df668a96077264091550b Mon Sep 17 00:00:00 2001 From: Alexander Du Date: Fri, 12 Dec 2025 00:29:07 -0800 Subject: [PATCH 1/2] Added some more problems --- algorithmic/problems/111/chk.cc | 142 +++++ algorithmic/problems/111/config.yaml | 10 + algorithmic/problems/111/statement.txt | 29 + algorithmic/problems/111/testdata/1.ans | 2 + algorithmic/problems/111/testdata/1.in | 1 + algorithmic/problems/27/chk.cc | 183 ++++++ algorithmic/problems/27/config.yaml | 9 + algorithmic/problems/27/statement.txt | 49 ++ algorithmic/problems/27/testdata/1.ans | 0 algorithmic/problems/27/testdata/1.in | 1 + algorithmic/problems/50/chk.cc | 55 ++ algorithmic/problems/50/config.yaml | 9 + algorithmic/problems/50/statement.txt | 17 + algorithmic/problems/50/testdata/1.ans | 1 + algorithmic/problems/50/testdata/1.in | 713 ++++++++++++++++++++++++ 15 files changed, 1221 insertions(+) create mode 100644 algorithmic/problems/111/chk.cc create mode 100644 algorithmic/problems/111/config.yaml create mode 100644 algorithmic/problems/111/statement.txt create mode 100644 algorithmic/problems/111/testdata/1.ans create mode 100644 algorithmic/problems/111/testdata/1.in create mode 100644 algorithmic/problems/27/chk.cc create mode 100644 algorithmic/problems/27/config.yaml create mode 100644 algorithmic/problems/27/statement.txt create mode 100644 algorithmic/problems/27/testdata/1.ans create mode 100644 algorithmic/problems/27/testdata/1.in create mode 100644 algorithmic/problems/50/chk.cc create mode 100644 algorithmic/problems/50/config.yaml create mode 100644 algorithmic/problems/50/statement.txt create mode 100644 algorithmic/problems/50/testdata/1.ans create mode 100644 algorithmic/problems/50/testdata/1.in diff --git a/algorithmic/problems/111/chk.cc b/algorithmic/problems/111/chk.cc new file mode 100644 index 000000000..f8df62efc --- /dev/null +++ b/algorithmic/problems/111/chk.cc @@ -0,0 +1,142 @@ +// chk.cc — Checker for "Distinct Pairwise XOR Set" +// Style: modeled after the knight-path checker; prints +// quitp(ratio, "Valid XOR set. Your=%d Best=%lld Ratio: %.8f", ...) +// Ratio = (size of participant set) / (size of best set from ans.txt) + +#include "testlib.h" +#include +using namespace std; + +static bool readMaybeLong(InStream& S, long long &x){ + try { x = S.readLong(); return true; } + catch(...) { return false; } +} +static bool readMaybeInt(InStream& S, int &x){ + try { x = S.readInt(); return true; } + catch(...) { return false; } +} + +// Compute K = ceil(log2(n+1)) so that all XORs of numbers in [1..n] fit in [0..2^K-1] +static int xorBitWidth(long long n){ + unsigned long long nu = (unsigned long long)max(1LL, n); + int k = 64 - __builtin_clzll(nu); // ceil(log2(nu+?)), good for n>=1 + if ((1ULL << k) <= (unsigned long long)n) ++k; // ensure 2^k > n when n is exact power-1 edge + return max(1, k); +} + +struct ReadResult { + vector a; + long long m = 0; +}; + +// Read "length-first" set: +// m +// v1 v2 ... vm +// who = "participant" or "answer" +static ReadResult readSetLenOnly(InStream& S, long long n, const char* who, bool allowZero){ + ReadResult R; + long long m; + if (!readMaybeLong(S, m)){ + if (string(who)=="participant") quitp(0.0, "Empty output (no m). Score=0.0"); + quitf(_fail, "Answer file is empty (no m)."); + } + if (m < 0 || m > n){ + if (string(who)=="participant") quitp(0.0, "Invalid m=%lld. Score=0.0", m); + quitf(_fail, "Answer file: invalid m=%lld.", m); + } + if (m == 0 && !allowZero){ + if (string(who)=="participant") quitp(0.0, "m=0 not allowed here. Score=0.0"); + quitf(_fail, "Answer file: m=0 not allowed."); + } + + R.m = m; + R.a.reserve((size_t)m); + vector used((size_t)n + 1, 0); + + for (long long i = 0; i < m; ++i){ + int x; + if (!readMaybeInt(S, x)){ + if (string(who)=="participant") quitp(0.0, "Output ended before %lld numbers. Score=0.0", m); + quitf(_fail, "Answer file: ended before %lld numbers.", m); + } + if (x < 1 || x > n){ + if (string(who)=="participant") quitp(0.0, "Number out of range at pos %lld: %d (need 1..%lld). Score=0.0", i+1, x, n); + quitf(_fail, "Answer file: number out of range at pos %lld: %d (need 1..%lld).", i+1, x, n); + } + if (used[x]){ + if (string(who)=="participant") quitp(0.0, "Duplicate number: %d. Score=0.0", x); + quitf(_fail, "Answer file: duplicate number: %d.", x); + } + used[x] = 1; + R.a.push_back(x); + } + // Ignore any extra tokens after m numbers. + return R; +} + +static void checkXorDistinct(const vector& a, long long n, const char* who){ + long long m = (long long)a.size(); + if (m <= 1) return; // vacuously distinct + + int K = xorBitWidth(n); + long long cap = 1LL << K; // number of distinct XOR values available [0..2^K-1] + long long pairs = m * (m - 1) / 2; + + // Quick impossibility check + if (pairs > cap){ + if (string(who)=="participant") + quitp(0.0, "Impossible: m=%lld yields %lld pairs > %lld available XORs. Score=0.0", m, pairs, cap); + quitf(_fail, "Answer file: m=%lld yields %lld pairs > %lld available XORs.", m, pairs, cap); + } + + vector seen((size_t)cap, 0); + for (long long i = 0; i < m; ++i){ + for (long long j = i + 1; j < m; ++j){ + int v = a[i] ^ a[j]; + if (seen[(size_t)v]){ + if (string(who)=="participant") + quitp(0.0, "XOR collision: a[%lld]=%d XOR a[%lld]=%d = %d already seen. Score=0.0", + i+1, a[i], j+1, a[j], v); + quitf(_fail, "Answer file: XOR collision between indices %lld and %lld (value %d).", i+1, j+1, v); + } + seen[(size_t)v] = 1; + } + } +} + +int main(int argc, char* argv[]){ + registerTestlibCmd(argc, argv); + if (argc < 4) { + quitf(_fail, "Usage: %s in.txt out.txt ans.txt", argv[0]); + } + + // Optional: ensure ans.txt exists and is not 0 bytes + { + ifstream f(argv[3], ios::binary); + if (!f) quitf(_fail, "Cannot open %s", argv[3]); + f.seekg(0, ios::end); + if (f.tellg() == 0) quitf(_fail, "ans.txt is empty (0 bytes)."); + } + + // Read input: n + long long n; + try { n = inf.readLong(1LL, 10000000LL, "n"); } + catch(...) { quitf(_fail, "Failed to read valid n from input."); } + + // Read best (answer) and your (participant) sets + auto best = readSetLenOnly(ans, n, "answer", /*allowZero=*/false); + auto yours = readSetLenOnly(ouf, n, "participant", /*allowZero=*/true); + + // Validate XOR-distinctness for both + checkXorDistinct(best.a, n, "answer"); + checkXorDistinct(yours.a, n, "participant"); + + long long Best = best.m; + int Your = (int)yours.m; + + double ratio = (Best == 0) ? 0.0 : (double)Your / (double)Best; + if (ratio < 0) ratio = 0; + if (ratio > 1) ratio = 1; + + quitp(ratio, "Valid XOR set. Your=%d Best=%lld Ratio: %.8f", Your, Best, ratio); +} diff --git a/algorithmic/problems/111/config.yaml b/algorithmic/problems/111/config.yaml new file mode 100644 index 000000000..5660c0218 --- /dev/null +++ b/algorithmic/problems/111/config.yaml @@ -0,0 +1,10 @@ +type: default +time: 1s +memory: 128m + +checker: chk.cc + +subtasks: + - score: 100 + n_cases: 1 # auto-picks 1.in…10.in and (logically) 1.out…10.out, + # but your JudgeEngine first tries "X.ans" before "X.out". diff --git a/algorithmic/problems/111/statement.txt b/algorithmic/problems/111/statement.txt new file mode 100644 index 000000000..bfce31729 --- /dev/null +++ b/algorithmic/problems/111/statement.txt @@ -0,0 +1,29 @@ +Problem: Distinct Pairwise XOR Set + +Time Limit: 1 second +Memory Limit: 512 MB + +Description +Given an integer n, find a subset S ⊆ {1, 2, ..., n} such that: +1) For all pairs (a, b) with a, b ∈ S and a < b, the values (a XOR b) are all distinct (i.e., no two different unordered pairs produce the same XOR). +2) |S| ≥ floor(sqrt(n / 2)). + +Input +A single integer n (1 ≤ n ≤ 10^7). + +Output +- First line: an integer m — the size of the set S. +- Second line: m distinct integers in the range [1, n] — the elements of S, in any order. + +Notes +- Any valid S is accepted. You do NOT need to maximize m; you only need m ≥ floor(sqrt(n/2)). +- The pairwise XOR distinctness means the set {a_i XOR a_j | 1 ≤ i < j ≤ m} has size m*(m-1)/2. +- Multiple correct outputs may exist for the same n. +- Print out the sequence with the longest length. + +Sample +Input +49 +Output +4 +1 2 3 4 diff --git a/algorithmic/problems/111/testdata/1.ans b/algorithmic/problems/111/testdata/1.ans new file mode 100644 index 000000000..10016e433 --- /dev/null +++ b/algorithmic/problems/111/testdata/1.ans @@ -0,0 +1,2 @@ +2048 +1 2048 4105 6158 8257 10324 12409 14442 16897 19016 21161 23270 25537 27548 29529 31490 33364 35653 36892 39179 42772 44561 46444 48239 49767 52030 53391 55760 59047 61418 62591 64820 65788 68829 71239 72288 73961 77020 79458 80465 82021 85004 87678 88593 90608 93581 96219 97184 98660 101461 103839 104616 107633 108884 110778 114073 115662 118455 120725 121578 124763 125494 127792 130651 133097 134653 135755 137305 140494 143054 143708 146266 149313 150813 152131 153625 157158 159662 159956 162458 164641 165925 169155 171969 173318 175638 176852 178626 180666 183030 186104 187826 189981 191813 192879 195121 197914 199470 202251 202809 206440 206920 210249 211823 214827 215383 218266 219872 222681 224177 226904 227382 229919 232763 234318 236652 238701 240477 242956 244282 246301 249201 250860 253062 255471 256663 259118 260944 264077 264299 267640 268952 270340 274422 275137 277813 279251 281981 282758 286510 287962 289632 292543 293123 295629 298043 299640 302216 303172 306854 307393 310821 312736 314142 316853 318221 321193 321539 325260 325664 329063 331425 332065 334561 336571 338281 341709 343321 344736 346414 349766 351694 353532 356198 356394 359350 361450 362812 366060 368444 368950 371700 374528 376260 378398 380032 381112 383520 386370 389064 390100 391512 393792 397235 398623 399594 403118 404297 405953 408608 411062 411661 414281 417780 418008 421239 423703 424638 426397 429438 431234 432231 434291 437380 439644 440749 443480 444659 446951 449866 451638 452745 455097 457984 459428 461687 463688 465565 468511 471000 473027 474626 477131 478800 480903 483098 484080 486271 488332 489989 492212 494199 495896 498141 500495 502744 503955 505922 509416 511331 513764 515689 517587 519500 521967 523894 525485 527446 529233 531372 532816 534975 538268 540277 540713 542874 546677 548800 549972 552179 553784 555929 558276 560431 561528 563349 566329 568774 569781 571468 574067 576464 579439 581322 582414 584377 587298 589715 590900 592111 595323 596390 598428 601427 602339 605226 606761 609978 611270 614227 615937 617094 620510 621407 624528 625243 627871 629074 632632 633575 635911 637406 639934 642621 643089 646548 647830 651009 651529 654488 655784 658246 660478 661782 665394 667080 669012 671656 673668 675106 677234 679890 680094 682540 684632 686316 690012 691362 694090 695474 697542 700204 701664 704268 705347 706805 709621 710725 713049 715515 717279 719483 721727 724465 727002 727314 730608 731946 733477 737273 739210 739596 742351 744783 745669 749143 750768 752164 755206 756184 757923 761723 763337 764419 766812 769168 770176 773910 775813 776469 778959 781645 783610 785278 786524 790336 791901 793159 795240 798048 800601 800855 803718 806098 808487 809333 811058 814962 816547 817893 821024 821548 823393 826987 827412 830988 833381 833915 837321 837773 839976 843626 843901 847405 849836 850426 852690 854510 856416 858714 860339 863131 865073 866335 869265 870629 872579 875505 876656 879376 881490 882740 886371 887887 890769 892347 893186 895802 897216 899838 902419 905079 906305 908835 910322 911746 914064 915686 919420 920181 923607 924376 927279 928562 931508 932783 935438 936783 939525 940866 943837 945032 947942 949173 951965 952964 955510 956521 959182 962243 962581 965662 968156 969101 972695 973760 974863 977994 979572 982583 985084 986837 987620 989387 993018 995271 995538 997865 1000471 1002870 1004207 1006536 1008785 1011172 1012249 1014634 1017296 1019369 1020296 1022391 1024470 1026555 1029566 1031573 1033224 1035385 1036528 1038471 1040782 1042923 1045830 1047845 1049035 1051682 1054227 1055740 1058535 1059610 1061135 1064180 1066170 1067291 1070018 1072741 1073686 1077155 1078622 1079533 1081665 1084856 1086681 1087526 1090413 1093504 1095365 1096238 1099267 1100466 1102651 1105804 1107375 1108234 1110183 1113092 1114755 1117002 1119208 1120807 1123834 1125415 1127585 1129850 1131883 1133802 1135776 1137959 1139602 1141255 1143401 1145850 1147332 1149213 1151727 1153584 1156029 1158000 1159334 1161325 1164319 1166478 1169300 1171203 1173478 1175395 1176669 1178846 1180931 1182463 1185649 1185931 1188168 1191584 1192714 1195236 1196762 1199470 1200136 1204154 1206033 1206449 1209843 1210965 1213204 1215992 1217318 1220044 1221215 1223847 1225309 1227939 1230590 1230938 1234540 1235150 1238581 1239173 1242775 1243169 1246277 1249177 1249412 1252190 1253467 1256339 1258666 1261412 1261829 1264273 1267044 1269494 1270939 1273627 1274058 1276748 1278367 1280851 1283870 1285588 1286273 1288793 1291824 1293550 1296108 1297512 1298637 1301071 1304178 1305826 1306723 1309429 1311610 1313140 1316447 1317975 1319839 1321349 1324682 1326230 1327445 1329939 1332432 1334928 1335344 1337954 1340805 1343441 1344741 1347579 1348480 1349784 1351936 1354250 1357397 1359193 1361145 1363887 1364796 1366124 1368220 1371102 1374057 1375277 1376805 1379339 1380787 1384347 1385109 1387695 1388851 1392399 1393299 1395957 1397157 1400773 1401763 1404369 1405093 1408721 1410679 1411401 1415073 1415321 1418183 1420525 1421857 1424653 1426674 1428356 1430916 1432308 1433794 1437600 1438084 1441504 1443223 1445260 1447192 1449221 1451541 1453594 1455786 1457827 1459472 1461571 1463615 1465706 1468178 1470293 1472269 1474380 1475733 1478046 1480282 1482583 1483287 1485576 1487080 1489393 1492513 1494882 1496142 1498379 1499427 1501300 1504124 1505837 1509062 1510141 1511674 1514695 1516817 1517886 1520413 1523508 1524952 1525931 1528388 1531441 1533583 1534696 1536035 1539138 1541129 1542434 1544309 1547608 1549022 1552353 1554066 1555371 1557540 1558855 1560824 1564061 1565555 1568260 1570719 1571566 1573609 1576954 1577669 1581008 1581176 1584511 1585252 1588581 1589532 1592391 1593744 1596621 1597965 1601346 1602225 1605624 1605727 1608796 1610291 1613366 1615822 1616857 1619346 1620355 1622425 1625554 1626965 1629976 1632136 1633239 1635700 1636653 1638853 1640694 1644378 1646191 1647361 1649190 1652142 1653903 1654953 1657298 1660566 1662955 1663981 1665666 1668578 1670283 1671358 1673373 1676385 1678404 1681274 1683277 1684373 1686436 1688545 1690506 1693598 1695731 1697189 1699290 1700330 1702291 1705164 1706954 1708362 1711690 1713466 1714728 1716364 1720216 1721745 1723103 1724599 1728511 1730023 1731261 1732849 1736621 1736935 1740529 1742625 1743153 1745937 1747475 1749991 1752547 1753993 1756631 1758447 1759927 1763071 1763509 1765801 1769445 1770990 1773256 1775323 1777147 1778765 1781631 1783624 1784956 1787434 1789252 1791423 1793751 1795593 1797491 1799596 1801936 1802760 1804350 1807229 1808717 1812139 1813641 1816558 1818058 1819647 1821057 1823274 1824850 1828572 1830070 1832761 1834325 1835813 1837521 1839604 1841926 1844861 1846429 1848476 1851002 1853326 1854770 1857023 1859397 1860438 1862142 1863959 1866681 1869446 1871202 1873431 1875445 1877726 1879342 1881727 1883529 1884190 1887154 1888303 1891205 1892806 1895038 1896903 1899129 1901086 1903818 1906300 1906862 1910547 1911251 1913665 1916295 1917996 1919664 1921262 1924724 1925281 1928745 1930323 1931997 1934448 1936308 1938002 1940880 1942653 1944493 1946223 1949113 1949809 1953789 1955571 1956217 1958396 1961572 1963854 1964240 1967909 1970116 1970270 1972409 1974554 1976815 1979985 1982114 1982758 1984911 1988349 1990226 1992345 1994276 1995122 1997257 1999899 2002410 2003232 2005207 2008868 2010817 2011695 2014156 2015275 2017682 2020784 2022415 2024084 2026297 2029375 2031252 2032656 2033873 2037208 2038047 2040442 2043567 2044802 2047825 2048138 2051075 2052578 2055533 2058080 2059261 2061880 2063011 2065635 2066738 2070379 2071228 2074505 2075212 2077745 2079218 2081354 2084819 2085218 2088189 2089120 2092333 2094008 2096691 2097250 2101157 2102707 2103922 2106990 2107837 2110351 2112602 2113998 2117185 2118847 2120502 2123330 2124249 2126595 2129054 2130291 2133924 2135778 2136115 2138751 2141372 2143710 2145051 2147052 2149491 2151901 2153284 2154592 2158315 2160481 2161132 2163762 2166741 2168656 2170033 2171499 2173336 2175289 2177740 2180871 2182312 2184389 2187116 2187486 2190181 2192172 2193553 2197230 2198553 2201548 2202941 2205111 2207572 2208933 2211392 2213864 2215255 2217578 2219219 2221361 2224026 2225283 2227758 2229828 2231190 2233919 2235371 2237231 2240233 2241380 2244260 2245952 2246874 2250139 2250759 2253227 2255909 2257216 2260168 2261448 2264330 2266099 2268983 2269603 2272629 2274216 2277240 2277631 2280565 2282084 2285288 2285844 2289034 2290623 2293543 2293786 2296296 2299602 2301734 2303268 2305218 2307036 2308668 2310535 2312253 2316271 2317907 2319673 2321559 2323297 2325193 2327643 2329785 2330835 2332727 2335845 2337939 2339037 2340909 2344949 2346847 2347997 2349937 2352715 2354933 2355795 2357995 2359944 2362024 2364836 2366850 2368333 2370425 2372689 2374755 2376826 2378770 2380790 2382744 2384959 2387011 2388867 2391033 2393228 2395580 2396640 2398422 2400329 2402669 2405653 2407479 2408525 2410805 2413953 2415871 2417928 2419812 2420980 2423198 2426063 2427087 2430288 2431318 2434399 2435403 2438384 2439394 2441380 2444524 2445723 2448853 2449588 2452712 2453947 2457057 2457862 2460694 2462425 2465743 2467222 2467986 2471545 2472827 2475870 2476550 2479137 2480511 2482766 2486018 2486529 2489419 2492043 2493630 2495501 2498110 2499625 2502152 2504351 2505912 2507473 2508972 2511095 2513548 2515443 2517914 2520037 2521482 2524690 2526519 2528980 2530807 2531760 2534017 2535750 2538097 2539643 2542358 2543645 2546550 2549337 2551072 2553359 2555248 2556610 2559191 2561783 2562276 2564149 2567732 2569264 2570807 2573313 2574940 2576532 2580175 2582390 2582847 2585555 2588060 2589078 2592403 2594787 2595040 2598497 2599280 2600996 2604851 2606438 2607659 2610099 2612472 2614033 2616392 2618868 2620075 2623423 2623618 2626970 2628257 2630670 2632487 2635291 2636084 2637975 2641890 2642450 2645345 2646694 2649543 2650131 2654068 2655378 2656959 2659575 2661084 2662947 2665498 2667126 2669641 2670985 2674668 2675020 2678575 2680504 2681033 2684493 2684986 2687883 2689174 2692893 2694150 2695279 2698086 2700489 2703302 2704954 2706799 2707980 2709855 2712670 2715423 2715736 2718495 2720619 2722150 2725309 2727862 2729359 2731926 2732905 2734454 2737385 2739884 2740895 2742492 2745229 2746844 2749899 2752412 2753396 2756188 2757883 2759125 2761634 2764446 2765853 2767143 2770676 2771860 2773467 2776253 2779042 2779862 2781373 2784719 2787012 2788092 2790155 2793269 2794258 2797374 2799341 2800327 2802039 2804999 2806808 2807918 2811169 2812229 2814078 2817052 2819406 2821190 2823282 2825596 2827725 2829521 2831553 2833883 2835031 2837271 2839499 2841229 2843476 2845184 2847480 2849706 2851635 2853675 2854991 2857041 2860720 2862780 2864636 2866678 2868761 2870857 2872773 2874771 2875930 2878046 2879990 2881972 2885160 2887410 2889456 2891308 2892368 2894494 2896568 2898544 2901598 2903756 2905638 2907826 2909094 2911008 2913262 2915182 2916880 2919386 2920584 2922820 2925416 2927286 2929088 2930712 2932821 2935255 2937453 2939881 2941101 2943291 2945701 2947893 2949131 2952433 2954848 2955932 2958374 2959560 2962045 2965141 2966244 2969174 2970671 2971803 2975561 2976751 2978226 2981138 2983934 2984468 2986965 2989625 2991827 2992941 2994888 2998064 3000098 3000960 3003305 3005965 3008399 3009081 3011380 3014276 3014854 3017225 3020212 3022717 3024857 3026178 3027611 3029062 3031576 3033247 3037130 3038539 3040391 3042836 3043685 3046384 3048035 3049916 3052881 3055240 3055740 3058615 3061630 3062963 3064462 3066137 3069212 3071629 3072273 3074706 3077811 3079478 3081451 3082756 3086122 3086787 3089313 3091802 3092560 3096237 3097772 3099147 3102669 3103084 3105382 3108053 3109175 3112834 3114371 3115644 3118082 3120123 3123145 3123234 3126904 3127701 3131383 3131456 3135190 3135847 3138621 3140510 3142956 3144329 3147028 3149627 3151637 3153212 3155060 3157583 3159621 3161208 3163081 3164590 3166568 3169033 3171113 3172698 3174840 3177421 3180250 3182053 3184283 3186082 3187386 3189137 3191499 3193318 3195444 3197251 3199701 3201444 3205076 3206327 3208965 3210336 3212017 3214590 3216963 3217482 3220420 3223007 3225414 3225947 3229365 3229938 3232423 3235046 3237376 3237971 3240482 3243127 3244786 3247597 3249152 3250969 3253959 3254732 3256325 3260168 3261573 3263442 3265239 3267974 3268912 3272307 3274578 3274775 3276818 3278888 3282873 3284869 3285525 3287611 3290510 3292582 3294311 3296277 3298156 3300120 3303392 3305350 3305691 3307707 3310913 3312747 3313834 3316102 3318342 3320696 3323805 3325605 3326727 3328613 3331660 3333928 3335552 3337462 3338491 3340683 3343865 3344867 3347681 3348733 3352491 3353509 3356291 3357323 3359509 3362631 3363501 3366649 3367111 3370113 3371343 3374351 3375975 3378797 3379263 3382579 3384373 3385643 3389277 3390021 3393464 3394298 3396672 3397892 3400042 3402812 3404450 3407858 3408579 3411723 3412543 3416049 3417194 3418550 3421350 3422588 3425088 3428032 3429148 3432090 3433577 3435005 3437573 3438999 3442200 3443392 3445924 3446906 3450289 3451261 3454781 3455991 3458472 3459384 3463092 3463970 3467137 3468037 3470765 3471663 3475249 3477209 3477886 3479696 3482061 3483697 3487666 3489352 3490859 3493259 3494596 3496802 3498839 3500771 3503496 3505210 3506215 3508447 3511336 3513558 3515355 3517239 3520484 3522318 3522830 3525054 3528097 3530007 3531634 3533782 3536877 3538767 3540448 3541565 3543222 3546989 3547182 3551207 3552584 3553927 3557067 3557726 3560253 3562670 3564165 3566852 3569475 3569860 3573670 3574123 3575984 3579515 3581800 3582385 3584078 3587729 3589822 3590203 3592456 3596171 3598320 3598689 3600502 3604193 3605020 3607009 3609081 3611138 3614599 3615854 3617874 3620797 3621806 3622939 3625195 3627864 3631029 3632148 3634368 3637095 3638167 3639674 3641906 3643609 3646220 3647989 3650201 3651686 3653654 3656371 3658003 3660720 3662093 3664828 3665976 3668623 3671367 3674002 3674290 3676769 3678618 3681115 3683423 3686040 3687710 3690371 3690571 3693264 3694659 3697354 3700006 3702697 3703989 3706736 3707648 3709123 3712360 3714745 3715821 3717434 3720927 3722578 3723722 3725889 3729026 3730715 3731879 3734072 3736262 3738675 3740032 3743603 3745358 3745967 3749176 3750879 3751942 3755707 3757024 3759451 3761422 3763111 3765976 3766391 3768569 3772188 3772927 3776028 3776881 3780224 3780679 3784624 3784714 3788711 3789228 3792391 3792898 3796923 3797396 3800619 3801772 3803756 3805939 3807797 3810582 3812802 3814777 3816875 3817565 3819733 3821730 3823660 3827303 3829499 3831464 3833394 3835331 3836947 3839964 3841546 3843961 3845821 3847510 3849364 3851521 3853465 3856318 3857952 3860027 3862455 3863732 3865918 3868451 3869635 3871183 3874089 3875020 3877944 3880464 3881698 3884875 3886051 3887367 3890601 3891492 3894680 3897176 3898338 3900289 3903089 3905325 3906267 3907950 3910794 3913202 3913744 3916250 3918946 3921366 3922024 3924661 3927833 3929737 3930915 3932653 3935455 3938021 3939281 3941113 3944415 3945921 3946721 3950314 3951504 3952962 3955774 3957886 3959056 3961830 3964558 3966730 3967784 3969602 3972710 3973406 3976488 3978342 3979350 3981886 3984980 3987414 3988410 3990954 3992020 3993714 3996682 3998843 4001129 4003264 4005076 4007738 4009532 4011697 4014001 4014565 4016319 4018430 4020642 4023076 4024938 4026895 4029255 4030801 4032851 4035242 4037294 4040464 4042502 4043995 4046027 4048636 4050614 4052391 4054507 4055357 4057443 4059734 4061710 4064291 4066052 4068993 4069792 4072528 4074339 4077250 4078071 4080012 4083427 4084622 4087015 4087935 4091652 4092493 4095280 4097113 4098670 4101307 4102794 4104490 4108041 4108792 4112349 4113349 4115898 4117383 4120062 4122422 4122973 4126532 4127017 4129723 4131004 4134826 4136107 4137885 4139150 4143036 4144297 4146317 4149186 4149308 4152181 4154667 4157040 4157866 4160247 4161548 4164123 4167261 4168780 4171050 4173609 4174667 4176206 4179209 4181846 4183032 4184481 4186543 4189156 4192110 4193571 \ No newline at end of file diff --git a/algorithmic/problems/111/testdata/1.in b/algorithmic/problems/111/testdata/1.in new file mode 100644 index 000000000..a51423c2c --- /dev/null +++ b/algorithmic/problems/111/testdata/1.in @@ -0,0 +1 @@ +4194304 \ No newline at end of file diff --git a/algorithmic/problems/27/chk.cc b/algorithmic/problems/27/chk.cc new file mode 100644 index 000000000..105a472d3 --- /dev/null +++ b/algorithmic/problems/27/chk.cc @@ -0,0 +1,183 @@ +#include "testlib.h" +#include +using namespace std; + +typedef long long LL; + +// Global data for check() convenience +static long long N, M; +static int K; +static vector> pts; +static string reason; + +bool check() { + reason.clear(); + + // Basic bounds + if (K < 0 || (long long)K > N * M) { + reason = "k out of valid range."; + return false; + } + + // Range check and duplicates of points + vector enc; + enc.reserve(K); + for (int i = 0; i < K; i++) { + int r = pts[i].first; + int c = pts[i].second; + if (r < 1 || r > N || c < 1 || c > M) { + reason = "Coordinate out of range."; + return false; + } + unsigned long long id = (unsigned long long)(r - 1) * (unsigned long long)M + (unsigned long long)(c - 1); + enc.push_back(id); + } + sort(enc.begin(), enc.end()); + for (int i = 1; i < K; i++) { + if (enc[i] == enc[i - 1]) { + reason = "Duplicate coordinates."; + return false; + } + } + + if (K == 0) return true; // empty set is valid + + // If only one row or one column, rectangles are impossible + if (N == 1 || M == 1) return true; + + // Build adjacency: rows -> columns, cols -> rows + vector> rows((size_t)N + 1), cols((size_t)M + 1); + rows.shrink_to_fit(); + cols.shrink_to_fit(); + for (auto &p : pts) { + rows[p.first].push_back(p.second); + cols[p.second].push_back(p.first); + } + + // Sort row column lists for consistent pair keys (light rows) + for (int r = 1; r <= N; r++) { + if (!rows[r].empty()) { + sort(rows[r].begin(), rows[r].end()); + } + } + + // Heavy-light threshold + const int B = 300; + + // Heavy rows detection (degree > B) + vector heavyRows; + heavyRows.reserve(N); + for (int r = 1; r <= N; r++) { + if ((int)rows[r].size() > B) heavyRows.push_back(r); + } + + // Heavy rows check: for each heavy row, count intersections + if (!heavyRows.empty()) { + vector cnt((size_t)N + 1, 0); + vector touched; + touched.reserve(N); + + for (int r : heavyRows) { + // Count how many common columns with each other row + for (int c : rows[r]) { + for (int rr : cols[c]) { + if (rr == r) continue; + if (cnt[rr] == 0) touched.push_back(rr); + cnt[rr]++; + if (cnt[rr] >= 2) { + reason = "Rectangle found (two rows share at least two columns)."; + return false; + } + } + } + // reset + for (int rr : touched) cnt[rr] = 0; + touched.clear(); + } + } + + // Light rows: enumerate column pairs and detect duplicates across rows + // Only rows with degree >= 2 are relevant + long long pairEstimate = 0; + vector lightRows; + lightRows.reserve(N); + for (int r = 1; r <= N; r++) { + int d = (int)rows[r].size(); + if (d >= 2 && d <= B) { + lightRows.push_back(r); + pairEstimate += 1LL * d * (d - 1) / 2; + } + } + if (pairEstimate > 0) { + unordered_map seen; + for (int r : lightRows) { + auto &v = rows[r]; + int d = (int)v.size(); + for (int i = 0; i < d; i++) { + for (int j = i + 1; j < d; j++) { + uint64_t c1 = (uint64_t)v[i]; + uint64_t c2 = (uint64_t)v[j]; + uint64_t key = (c1 << 32) | c2; // c1 < c2 due to sorting + if (seen.find(key) != seen.end()) { + reason = "Rectangle found (a column pair appears in two rows)."; + return false; + } else seen[key] = true; + } + } + } + } + + return true; +} + +int main(int argc, char** argv) { + registerTestlibCmd(argc, argv); + + // Read input: n, m + N = inf.readLong(1, (long long)1e9); // bounds here are loose; product constraint is in statement + M = inf.readLong(1, (long long)1e9); + // We won't rely on product constraint here; checker tolerates any within memory/time. + + // Read contestant output + K = ouf.readInt(0, (N > 0 && M > 0 ? (int)min(N * M, 1000000000LL) : 0)); + pts.resize(K); + for (int i = 0; i < K; i++) { + int r = ouf.readInt(1, (int)N); + int c = ouf.readInt(1, (int)M); + pts[i] = {r, c}; + } + // ouf.readEof(); + + // Validate + bool ok = check(); + if (!ok) { + quitp(0.0, "Invalid output"); + } + + // Compute score ratio = min(k / U(n, m), 1) + auto computeU = [&](long long n, long long m) -> long long { + long double sn = sqrt((long double)n); + long double sm = sqrt((long double)m); + long double v1 = floor((long double)n * sm + (long double)m); + long double v2 = floor((long double)m * sn + (long double)n); + long double v3 = (long double)n * (long double)m; + long double U = min(v1, min(v2, v3)); + if (U < 0) U = 0; + long long res = (long long)U; + return res; + }; + + long long U = computeU(N, M); + if (U <= 0) { + // Degenerate, but to be safe + quitp(K > 0 ? 1.0 : 0.0, "Degenerate U; fallback scoring."); + } + + long double ratioLD = (long double)K / ((long double) U * 1.5); + if (ratioLD > 1.0L) ratioLD = 1.0L; + if (ratioLD < 0.0L) ratioLD = 0.0L; + double ratio = (double)ratioLD; + + quitp(ratio, "Ratio: %.3f", ratio); + return 0; +} \ No newline at end of file diff --git a/algorithmic/problems/27/config.yaml b/algorithmic/problems/27/config.yaml new file mode 100644 index 000000000..b80290022 --- /dev/null +++ b/algorithmic/problems/27/config.yaml @@ -0,0 +1,9 @@ +type: default +# The time limit is now 1 second. +time: 1s +memory: 512m +# A custom checker is required for the special scoring. +checker: chk.cc +subtasks: + - score: 100 + n_cases: 1 \ No newline at end of file diff --git a/algorithmic/problems/27/statement.txt b/algorithmic/problems/27/statement.txt new file mode 100644 index 000000000..2ae93945c --- /dev/null +++ b/algorithmic/problems/27/statement.txt @@ -0,0 +1,49 @@ +# Problem + +You are given an n by m grid. You want to place as many black points (cells) as possible so that no four of them form the four corners of an axis-parallel rectangle. + +Formally, if you place black points at positions (r, c) with 1 ≤ r ≤ n and 1 ≤ c ≤ m, your set S of chosen positions must not contain four distinct pairs (r1, c1), (r1, c2), (r2, c1), (r2, c2) with r1 ≠ r2 and c1 ≠ c2. + +## Input +A single line with two integers n and m (1 ≤ n, m and n · m ≤ 100000). + +## Output +Print: +- The first line: an integer k — the number of black points you place (0 ≤ k ≤ n · m). +- The next k lines: two integers ri and ci each (1 ≤ ri ≤ n, 1 ≤ ci ≤ m), denoting the coordinates of the i-th black point. + +All listed pairs must be distinct. You may print the points in any order. + +## Goal +Maximize k subject to the validity constraint (no axis-parallel rectangle formed by four chosen points). + +## Scoring +Let k be the number of points you output, and let U(n, m) be the theoretical upper bound we use for this problem: +U(n, m) = floor(min(n · sqrt(m) + m, m · sqrt(n) + n, n · m)). + +Your score for a test is: +score = 100 × min(k / U(n, m), 1). + +- Achieving the upper bound U(n, m) yields a score of 100. +- Outputting 0 points yields a score of 0. +- Invalid outputs (out-of-range coordinates, duplicates, or violating the rectangle constraint) receive a score of 0 for that test. +Your final score is the average over all tests. + +## Time limit +1 second + +## Memory limit +512 MB + +## Sample +Input +2 2 + +Output +3 +1 1 +1 2 +2 1 + +(The sample illustrates the format and a valid solution; for a 2×2 grid, 3 is optimal under the given constraint.) + diff --git a/algorithmic/problems/27/testdata/1.ans b/algorithmic/problems/27/testdata/1.ans new file mode 100644 index 000000000..e69de29bb diff --git a/algorithmic/problems/27/testdata/1.in b/algorithmic/problems/27/testdata/1.in new file mode 100644 index 000000000..9732b5545 --- /dev/null +++ b/algorithmic/problems/27/testdata/1.in @@ -0,0 +1 @@ +100 100 diff --git a/algorithmic/problems/50/chk.cc b/algorithmic/problems/50/chk.cc new file mode 100644 index 000000000..88721966f --- /dev/null +++ b/algorithmic/problems/50/chk.cc @@ -0,0 +1,55 @@ +#include "testlib.h" +#include +#include +#include + +using namespace std; + +int cost[5010]; + +vectorv[5010]; + +int vis[1010]; + +int main(int argc, char *argv[]) { + /* + * inf:输入 + * ouf:选手输出 + * ans:标准输出 + */ + registerTestlibCmd(argc, argv); + + int n = inf.readInt(1, 400), m = inf.readInt(1, 4000); + for(int i = 1; i <= m; i++){ + cost[i] = inf.readInt(); + } + for(int i = 1; i <= n; i++){ + int k = inf.readInt(1, m); + for(int j = 1; j <= k; j++){ + int sid = inf.readInt(1, m); + v[sid].push_back(i); + } + } + + int cnt = ouf.readInt(1, m); + int totcost = 0; + for(int i = 1; i <= cnt; i++){ + int sid = ouf.readInt(1, m); + totcost += cost[sid]; + for(int j = 0; j < v[sid].size(); j++){ + vis[v[sid][j]] = 1; + } + } + + for(int i = 1; i <= n; i++){ + if(!vis[i])quitf(_wa, "Invalid answer"); + } + + // quitf(_ok, "cost is %d", totcost); + + int ref = ans.readInt(); + double score = (2.0*ref-1.0*totcost)/(1.0*ref); + score = max(score, 0.0); + score = min(score, 1.0); + quitp(score, "Ratio: %.3lf", score); +} \ No newline at end of file diff --git a/algorithmic/problems/50/config.yaml b/algorithmic/problems/50/config.yaml new file mode 100644 index 000000000..cf14d2102 --- /dev/null +++ b/algorithmic/problems/50/config.yaml @@ -0,0 +1,9 @@ +type: default +time: 10s +memory: 1024m +subtasks: + - score: 100 + n_cases: 1 +checker: chk.cc +checker_type: testlib +filename: std.cc \ No newline at end of file diff --git a/algorithmic/problems/50/statement.txt b/algorithmic/problems/50/statement.txt new file mode 100644 index 000000000..b9ba62e3b --- /dev/null +++ b/algorithmic/problems/50/statement.txt @@ -0,0 +1,17 @@ +Time Limit: 10s +Memory Limit: 1024M + +Firstly, you are given two integers n (1 <= n <= 400) and m (1 <= m <= 4000), which means that you have n elements and m sets. + +After that, there are m integers, the i-th integer is the cost of choosing the i-th set. + +After that, for the i-th element, firstly input an integer k_i, which means the number of sets that contain the element. After that, there + +are k_i integers, the j-th integer a_j means that the set with id a_j contains the element i. + +Find some sets so that each element belongs to at least one of these sets. You need to minimize the total cost of these sets. This value will determine your final score. + +Output: + +Firstly output an integer |S|, which means the number of sets you choose. After that, output |S| ids of the sets you choose in another line. + diff --git a/algorithmic/problems/50/testdata/1.ans b/algorithmic/problems/50/testdata/1.ans new file mode 100644 index 000000000..6b3ed8d68 --- /dev/null +++ b/algorithmic/problems/50/testdata/1.ans @@ -0,0 +1 @@ +400 \ No newline at end of file diff --git a/algorithmic/problems/50/testdata/1.in b/algorithmic/problems/50/testdata/1.in new file mode 100644 index 000000000..283e120b6 --- /dev/null +++ b/algorithmic/problems/50/testdata/1.in @@ -0,0 +1,713 @@ + 200 1000 + 1 1 1 1 1 1 1 1 1 1 1 1 + 2 2 2 2 2 2 2 2 2 2 2 2 + 2 2 2 3 3 3 3 3 3 3 3 3 + 3 3 3 3 3 3 4 4 4 4 4 4 + 4 4 4 4 4 4 4 4 5 5 5 5 + 5 5 5 5 5 6 6 6 6 6 6 6 + 6 6 6 6 7 7 7 7 7 7 7 7 + 7 7 7 8 8 8 8 8 8 8 8 8 + 8 9 9 9 9 9 9 9 9 10 10 10 + 10 10 10 10 10 10 11 11 11 11 11 11 + 11 12 12 12 12 12 12 12 12 12 12 12 + 12 12 12 13 13 13 13 13 13 13 13 14 + 14 14 14 14 14 14 14 14 14 14 14 14 + 14 15 15 15 15 15 15 15 15 15 15 15 + 15 15 15 15 15 16 16 16 16 16 16 17 + 17 17 17 17 18 18 18 18 18 18 18 18 + 18 18 18 18 18 19 19 19 19 19 19 19 + 20 20 20 20 20 20 20 20 20 20 20 20 + 20 21 21 21 21 21 21 21 21 22 22 22 + 22 22 22 22 22 22 22 23 23 23 23 23 + 23 23 23 23 23 23 24 24 24 24 24 24 + 24 24 24 24 24 25 25 25 25 25 25 25 + 25 26 26 26 26 26 26 26 26 27 27 27 + 27 27 27 27 27 27 27 27 27 27 28 28 + 28 28 28 28 28 29 29 29 29 29 29 29 + 29 30 30 30 30 30 31 31 31 31 31 31 + 31 31 31 31 32 32 32 32 32 32 32 32 + 32 32 32 33 33 33 33 33 33 33 33 33 + 33 34 34 34 34 34 34 34 35 35 35 35 + 35 35 35 35 36 36 36 36 36 36 36 36 + 36 36 36 37 37 37 37 37 37 37 37 37 + 37 37 38 38 38 38 38 38 38 38 38 38 + 38 38 38 39 39 39 39 39 39 39 39 39 + 39 40 40 40 40 40 40 40 40 40 40 40 + 40 40 41 41 41 41 41 41 41 41 41 42 + 42 42 42 42 42 42 42 42 42 42 42 42 + 43 43 43 43 43 43 43 43 43 43 44 44 + 44 44 44 44 44 44 45 45 45 45 45 45 + 45 45 46 46 46 46 46 46 46 46 46 46 + 46 47 47 47 47 47 47 47 47 47 47 47 + 47 47 47 48 48 48 48 48 48 49 49 49 + 49 49 49 49 49 49 49 50 50 50 50 50 + 50 50 50 50 51 51 51 51 51 52 52 52 + 52 52 52 52 52 52 52 53 53 53 53 53 + 53 53 53 53 53 53 54 54 54 54 54 54 + 54 54 54 54 54 55 55 55 55 55 55 55 + 55 55 56 56 56 56 56 56 56 56 56 57 + 57 57 57 57 57 57 57 57 57 57 58 58 + 58 58 58 58 58 58 58 59 59 59 59 59 + 59 59 59 59 59 59 59 59 60 60 60 60 + 60 60 61 61 61 61 61 61 61 61 61 62 + 62 62 62 62 62 63 63 63 63 63 63 63 + 63 63 64 64 64 64 64 64 64 64 64 64 + 64 64 64 65 65 65 65 65 65 65 66 66 + 66 66 66 66 66 66 66 66 66 66 67 67 + 67 67 67 67 67 67 67 67 67 67 68 68 + 68 68 68 68 68 68 68 69 69 69 69 70 + 70 70 70 70 70 70 70 70 70 70 70 70 + 70 70 71 71 71 71 71 71 71 71 72 72 + 72 72 72 72 72 72 72 72 72 72 72 73 + 73 73 73 73 73 73 73 73 73 73 73 73 + 73 73 74 74 74 74 74 74 74 75 75 75 + 75 75 75 75 75 75 76 76 76 76 76 76 + 76 76 76 76 76 76 76 76 76 76 76 77 + 77 77 77 77 77 77 77 78 78 78 78 78 + 78 78 78 79 79 79 79 79 79 79 79 79 + 79 79 79 79 79 80 80 80 80 80 80 80 + 80 80 81 81 81 81 81 81 81 81 81 81 + 82 82 83 83 83 83 83 83 83 83 84 84 + 84 84 84 84 84 84 85 85 85 85 85 85 + 85 85 85 86 86 86 86 86 86 86 86 86 + 86 87 87 87 87 87 87 87 87 87 88 88 + 88 88 88 88 89 89 89 89 89 89 89 89 + 89 89 89 90 90 90 90 90 90 90 90 91 + 91 91 91 91 91 91 91 91 91 91 91 91 + 91 91 92 92 92 92 92 92 93 93 93 93 + 93 93 93 93 93 93 93 94 94 94 94 94 + 94 94 95 95 95 95 95 95 95 95 96 96 + 96 96 96 96 96 96 96 96 96 96 97 97 + 97 97 97 97 97 97 97 97 97 98 98 98 + 98 98 98 98 98 99 99 99 99 99 99 99 + 99 99 99 99 99 99 99 99 99 100 100 100 + 100 100 100 100 100 100 100 100 100 100 100 100 + 100 100 100 100 + 17 + 91 214 230 289 351 416 488 491 518 567 720 721 + 735 753 768 928 990 + 18 + 22 47 99 192 299 322 340 500 619 628 640 663 + 709 736 796 844 930 970 + 26 + 2 37 56 115 151 160 178 182 218 228 345 388 + 587 588 607 614 629 635 636 673 757 793 800 849 + 873 929 + 15 + 2 93 125 328 334 337 391 402 559 697 703 733 + 781 790 909 + 23 + 18 81 85 116 165 261 277 280 290 331 338 353 + 400 506 540 557 590 653 712 715 802 884 978 + 17 + 14 51 78 200 236 317 332 469 495 578 701 712 + 790 822 830 839 988 + 19 + 78 129 435 459 491 512 548 551 576 640 643 648 + 652 813 916 948 954 983 999 + 17 + 120 150 276 278 379 389 437 493 507 537 568 608 + 621 710 770 908 935 + 19 + 53 59 136 139 178 214 258 288 307 328 476 632 + 655 735 758 793 880 886 949 + 18 + 3 6 64 101 104 144 180 276 402 422 538 600 + 635 638 694 731 889 942 + 16 + 66 118 255 278 434 463 480 555 576 634 669 674 + 688 751 883 964 + 22 + 3 24 29 45 60 74 117 136 162 232 318 371 + 400 421 433 460 612 659 660 779 800 835 + 11 + 14 136 385 389 426 546 702 778 789 831 970 + 15 + 68 99 205 275 364 423 543 559 569 609 638 642 + 693 836 858 + 24 + 49 127 149 181 185 228 332 375 426 436 437 486 + 514 570 594 601 808 814 818 827 874 903 960 972 + 18 + 86 242 354 365 405 418 428 449 547 565 598 652 + 682 684 780 829 852 865 + 25 + 6 17 33 115 172 180 202 225 297 298 317 390 + 451 526 528 547 595 654 680 709 743 801 804 891 + 930 + 19 + 1 80 98 122 146 162 328 394 414 445 460 501 + 589 622 681 691 807 841 845 + 14 + 15 97 112 175 253 324 421 454 605 715 746 785 + 843 989 + 17 + 36 125 144 185 195 219 273 303 371 399 400 583 + 622 625 681 726 969 + 11 + 44 109 125 149 187 456 580 673 678 804 897 + 19 + 57 80 116 158 172 267 287 294 313 338 390 401 + 455 476 492 560 629 682 753 + 20 + 16 19 63 67 82 85 305 371 429 439 452 560 + 620 630 631 647 681 752 847 931 + 30 + 106 110 129 141 180 198 213 227 244 370 396 397 + 410 472 487 500 598 629 636 641 690 725 777 832 + 852 915 956 983 991 993 + 25 + 73 118 122 148 159 164 183 209 322 365 377 470 + 471 517 660 667 707 747 855 880 883 931 936 937 + 984 + 17 + 28 52 147 165 177 188 317 323 325 330 468 531 + 695 736 782 808 973 + 18 + 35 138 194 294 312 315 339 352 510 556 585 627 + 671 680 724 784 839 951 + 15 + 12 279 302 307 450 478 551 603 625 644 687 757 + 821 871 992 + 20 + 32 34 67 70 99 106 160 450 460 479 533 585 + 612 618 674 713 756 861 909 935 + 21 + 71 111 115 258 268 276 366 518 523 608 636 668 + 728 768 854 859 916 921 924 928 986 + 18 + 11 48 121 131 141 197 266 279 376 447 568 571 + 694 702 865 874 904 937 + 29 + 1 17 20 37 84 132 163 184 302 322 358 390 + 419 535 553 557 566 569 585 645 730 732 746 771 + 776 786 904 905 982 + 17 + 11 96 155 181 246 398 412 446 470 556 606 623 + 707 714 814 889 914 + 12 + 135 275 278 335 402 499 500 542 603 666 736 869 + 25 + 39 43 198 205 238 345 365 405 421 474 536 620 + 640 647 651 672 722 831 865 899 954 959 961 968 + 989 + 21 + 16 35 115 210 224 279 311 324 353 442 447 481 + 485 555 612 664 673 700 867 952 990 + 25 + 91 155 198 251 296 310 372 462 463 543 580 597 + 600 610 708 748 751 761 768 776 819 846 863 871 + 924 + 24 + 63 67 98 228 242 245 248 281 301 336 374 388 + 443 470 484 606 619 685 742 839 869 948 958 966 + 30 + 8 83 137 199 234 238 239 252 295 331 345 370 + 459 527 559 652 735 753 776 777 820 844 871 882 + 883 885 918 936 947 956 + 29 + 44 80 145 195 206 216 291 320 334 377 414 530 + 557 623 629 637 648 657 664 742 800 811 868 880 + 926 942 952 967 984 + 23 + 38 46 72 95 145 276 307 317 342 364 399 502 + 645 652 691 700 762 773 800 808 940 962 977 + 15 + 121 222 258 344 358 467 484 558 652 692 699 799 + 837 898 962 + 22 + 77 124 185 325 332 346 381 453 477 513 578 590 + 592 627 653 691 774 820 821 837 921 986 + 19 + 35 44 66 107 198 199 250 342 355 398 413 456 + 535 632 755 841 863 873 935 + 24 + 18 161 170 296 330 378 406 466 577 586 633 651 + 655 681 687 706 709 712 759 821 875 925 939 949 + 20 + 19 122 163 206 248 313 342 411 445 454 530 575 + 579 612 629 728 823 836 864 985 + 23 + 14 29 125 186 236 240 367 455 494 603 621 627 + 667 733 743 749 770 809 840 844 862 867 968 + 13 + 77 226 315 321 345 389 619 777 786 838 937 958 + 961 + 21 + 13 66 201 235 297 347 355 404 409 495 597 607 + 656 683 721 726 734 892 949 968 990 + 21 + 46 176 228 291 299 318 339 357 359 502 584 654 + 740 777 835 869 870 877 921 967 997 + 21 + 21 83 123 158 191 194 199 200 220 247 404 415 + 419 531 618 699 717 746 795 833 858 + 22 + 78 131 167 178 212 219 252 259 319 341 382 429 + 440 512 535 536 558 670 753 855 966 982 + 20 + 20 30 105 116 154 209 220 223 294 379 388 483 + 524 687 748 768 827 927 987 992 + 19 + 120 122 125 154 158 263 296 319 339 457 496 568 + 597 700 702 739 778 822 991 + 15 + 61 122 320 323 362 379 392 662 687 723 877 903 + 911 961 1000 + 24 + 78 89 108 130 163 171 227 233 266 390 411 417 + 501 641 649 714 794 828 830 854 872 914 968 973 + 19 + 116 199 247 329 387 408 414 431 564 573 598 650 + 742 744 810 836 881 910 927 + 18 + 127 144 208 250 271 442 470 490 536 541 546 650 + 659 675 682 776 780 785 + 18 + 85 151 208 271 343 351 546 589 591 604 651 710 + 718 722 770 787 958 982 + 27 + 26 100 231 254 274 296 399 425 449 502 558 572 + 597 601 659 701 718 726 742 749 753 766 792 825 + 958 967 981 + 23 + 13 14 19 21 179 229 262 364 365 381 389 444 + 451 475 509 558 585 606 627 633 653 800 870 + 19 + 90 101 140 153 257 312 335 370 425 454 470 509 + 538 560 576 686 740 823 931 + 26 + 47 82 137 180 210 211 241 349 381 427 470 551 + 561 579 584 627 644 648 720 798 828 895 973 976 + 982 996 + 17 + 30 72 128 138 147 148 163 202 318 437 514 639 + 760 934 950 955 964 + 29 + 8 14 53 67 90 96 188 234 354 369 374 424 + 488 524 576 692 695 774 799 849 851 854 876 938 + 951 963 986 987 988 + 25 + 17 36 80 186 285 336 340 439 463 500 503 541 + 581 624 628 720 788 815 848 871 890 920 942 966 + 984 + 15 + 28 158 213 259 308 382 422 571 588 707 793 850 + 892 929 947 + 30 + 28 60 78 127 221 249 353 364 436 454 500 517 + 528 559 579 599 619 647 649 740 783 796 819 849 + 866 895 958 966 971 983 + 16 + 103 200 243 287 313 345 490 505 546 565 693 696 + 790 802 923 992 + 17 + 55 66 163 168 207 363 388 416 531 641 712 737 + 816 830 864 920 969 + 21 + 43 126 152 185 226 279 297 307 333 401 447 542 + 561 595 649 686 699 787 851 891 920 + 13 + 13 98 115 308 402 433 466 468 473 525 562 648 + 922 + 14 + 21 259 278 330 338 395 476 534 562 619 661 814 + 927 947 + 14 + 52 249 274 360 576 673 680 710 725 846 853 866 + 872 961 + 18 + 1 30 79 123 269 300 391 412 503 506 549 613 + 660 705 782 893 903 929 + 25 + 1 4 18 29 50 51 114 148 160 261 274 326 + 448 509 603 711 721 723 727 828 835 869 903 958 + 972 + 24 + 18 115 207 302 317 328 331 332 345 356 383 384 + 386 492 524 569 662 720 771 798 810 859 910 991 + 17 + 7 32 45 122 282 357 359 444 455 708 749 756 + 810 820 831 872 909 + 20 + 13 40 92 167 174 255 393 427 452 461 494 539 + 555 582 607 669 703 809 835 882 + 25 + 62 109 110 267 270 289 330 350 359 368 378 435 + 467 473 487 504 584 587 673 685 691 745 747 838 + 968 + 22 + 24 25 72 204 293 320 417 475 492 541 563 582 + 587 666 677 701 756 759 840 864 994 998 + 21 + 9 24 79 147 266 268 295 385 501 530 532 556 + 604 643 672 744 768 880 902 987 988 + 15 + 89 122 209 269 422 443 605 673 767 807 850 921 + 925 944 995 + 18 + 13 47 73 185 252 258 266 547 563 597 605 698 + 704 719 739 753 846 922 + 26 + 61 92 94 216 248 296 362 364 377 421 427 446 + 490 599 628 661 709 724 729 740 755 761 845 878 + 975 988 + 23 + 5 31 124 149 220 263 267 305 350 403 420 516 + 564 585 593 623 631 642 654 727 809 893 936 + 20 + 193 275 353 355 396 402 436 528 535 564 685 711 + 801 835 836 841 876 924 937 951 + 27 + 42 58 79 98 131 143 209 242 251 295 349 391 + 491 494 510 524 525 538 586 598 670 788 810 811 + 820 850 912 + 18 + 20 30 87 122 179 270 274 360 420 424 425 434 + 484 659 682 754 856 866 + 20 + 45 58 148 193 239 259 322 464 540 543 548 570 + 697 713 752 775 794 927 982 990 + 16 + 54 74 177 247 328 360 403 472 497 661 722 747 + 793 913 923 927 + 15 + 7 28 152 192 238 256 314 380 577 771 772 836 + 857 918 976 + 18 + 66 108 129 189 240 277 290 411 452 489 507 552 + 620 632 685 773 856 894 + 19 + 10 43 82 93 219 267 368 434 450 458 549 581 + 672 707 761 789 792 928 945 + 19 + 6 41 84 161 312 341 401 406 443 490 559 778 + 834 854 869 870 937 945 980 + 23 + 6 44 86 158 159 176 227 237 274 411 537 542 + 586 676 786 877 888 911 921 932 936 977 995 + 20 + 13 63 82 93 207 219 284 288 355 375 403 408 + 482 558 647 834 859 872 875 888 + 17 + 3 248 514 519 521 529 549 569 606 618 674 786 + 813 917 982 993 998 + 24 + 99 108 115 295 335 345 368 388 392 433 444 448 + 465 493 511 571 656 729 888 903 940 948 950 966 + 25 + 19 75 98 150 191 266 286 400 476 495 561 599 + 628 630 634 684 720 724 755 765 896 902 906 930 + 933 + 23 + 50 183 222 236 306 388 452 485 516 535 620 686 + 754 771 812 821 832 844 865 899 935 941 942 + 29 + 4 91 127 161 189 211 239 242 350 388 390 425 + 463 471 509 539 577 590 597 610 618 674 719 723 + 778 798 912 944 996 + 13 + 81 142 190 203 301 415 435 451 477 737 779 889 + 960 + 18 + 29 111 218 245 293 304 306 406 411 502 557 594 + 618 721 751 906 907 920 + 20 + 79 106 124 148 179 203 231 439 456 593 653 768 + 799 824 860 879 929 947 959 971 + 20 + 5 80 82 139 181 287 303 324 414 462 498 510 + 640 671 801 837 864 900 959 975 + 29 + 1 79 103 116 182 191 273 311 347 413 428 474 + 501 550 627 635 679 687 688 728 769 799 802 842 + 844 850 857 905 955 + 19 + 2 71 90 113 118 140 309 428 457 490 496 516 + 557 689 780 782 855 909 919 + 23 + 9 96 184 186 260 297 333 381 420 459 473 555 + 580 602 624 638 640 689 785 788 803 939 991 + 23 + 2 3 76 81 136 149 202 203 347 354 369 393 + 413 440 578 686 707 708 772 801 891 894 948 + 20 + 62 84 120 149 260 262 356 620 650 668 687 699 + 743 809 811 845 876 882 969 997 + 14 + 48 51 159 166 175 204 232 241 377 510 597 751 + 845 891 + 17 + 89 142 164 281 295 297 320 341 407 516 519 589 + 641 769 803 839 976 + 15 + 66 67 78 88 90 132 275 461 604 648 654 693 + 784 836 972 + 20 + 91 137 161 276 311 319 359 465 485 561 567 671 + 714 726 738 798 827 862 910 911 + 19 + 57 123 139 153 196 280 330 361 393 495 566 608 + 634 680 689 692 791 806 969 + 26 + 32 153 155 162 205 213 229 243 395 404 407 412 + 438 472 601 641 650 693 704 798 820 846 928 959 + 968 971 + 18 + 4 29 95 107 226 237 375 562 570 607 608 648 + 791 811 815 822 848 856 + 18 + 69 186 218 221 262 441 447 500 509 565 585 588 + 750 769 807 870 903 936 + 16 + 20 169 188 215 226 254 302 310 366 413 540 659 + 688 774 919 993 + 19 + 16 33 52 88 137 146 152 187 247 266 277 312 + 342 347 366 412 790 802 967 + 25 + 17 35 76 133 260 283 320 339 424 511 553 566 + 598 612 622 711 776 842 875 901 913 928 943 944 + 970 + 16 + 102 144 196 237 248 343 367 458 556 584 604 705 + 754 760 880 920 + 20 + 107 123 249 287 298 403 411 525 577 624 640 700 + 736 758 768 802 805 827 856 888 + 22 + 34 65 83 104 146 197 218 239 286 287 318 367 + 603 637 744 752 794 829 881 926 986 989 + 21 + 106 182 234 280 430 433 460 575 584 620 622 684 + 754 799 873 879 885 933 950 954 983 + 20 + 28 151 160 212 233 249 323 356 459 484 579 633 + 646 677 805 854 857 892 916 940 + 27 + 3 30 34 38 56 160 180 205 277 282 340 344 + 376 399 406 412 422 451 505 514 547 556 592 672 + 722 841 993 + 21 + 11 57 136 147 236 280 303 316 390 464 552 567 + 568 690 727 760 787 822 914 917 946 + 21 + 59 136 140 156 174 191 206 269 290 418 420 504 + 581 630 710 711 765 788 890 974 985 + 25 + 75 183 195 317 331 339 356 361 405 407 472 474 + 512 545 739 741 747 788 819 829 853 865 933 934 + 943 + 15 + 47 69 241 260 360 367 389 465 497 570 589 684 + 707 709 907 + 20 + 10 27 171 277 329 340 376 453 499 527 582 603 + 605 649 676 683 694 737 745 988 + 15 + 77 237 377 388 449 498 584 616 699 715 730 832 + 906 959 978 + 20 + 61 77 85 250 395 401 403 453 477 526 613 689 + 743 750 762 835 863 864 938 950 + 22 + 32 43 79 117 122 123 137 150 302 324 346 398 + 414 491 541 664 686 752 880 901 941 983 + 18 + 94 112 187 193 517 536 567 572 642 692 762 812 + 840 843 863 913 914 983 + 21 + 2 119 212 236 303 308 354 366 404 509 565 597 + 634 642 647 690 695 844 909 953 965 + 15 + 77 117 321 369 380 453 507 515 520 527 665 680 + 684 748 777 + 16 + 31 49 81 82 124 201 274 319 338 437 478 565 + 583 772 854 873 + 29 + 33 59 123 141 159 187 240 250 255 268 289 363 + 391 438 445 489 511 592 605 661 679 710 776 779 + 811 909 915 927 947 + 20 + 9 150 164 300 346 396 420 424 639 665 666 699 + 739 792 872 884 929 951 953 969 + 23 + 48 49 57 123 126 128 137 256 261 329 404 462 + 473 475 524 640 668 692 707 792 819 882 984 + 17 + 60 92 415 433 505 514 650 651 663 684 685 745 + 786 803 905 935 959 + 17 + 26 80 100 126 146 181 346 434 441 621 660 671 + 697 751 935 974 985 + 26 + 15 59 205 218 221 272 282 318 349 353 358 379 + 464 490 518 526 540 575 591 671 713 746 759 786 + 889 930 + 24 + 59 106 119 158 247 275 292 294 298 354 373 375 + 382 401 445 552 584 618 627 708 750 764 813 964 + 11 + 46 218 221 394 410 553 576 677 680 858 966 + 17 + 50 68 186 190 208 261 266 314 339 344 375 702 + 769 839 893 922 952 + 19 + 57 146 147 156 241 348 400 474 515 629 798 812 + 884 922 923 924 966 971 979 + 24 + 28 58 88 125 128 145 237 265 270 274 289 310 + 352 375 513 539 575 633 645 671 691 702 720 838 + 21 + 39 94 308 323 346 430 433 434 480 517 628 636 + 658 724 738 761 776 789 847 945 972 + 25 + 27 107 126 150 168 188 189 205 243 244 264 285 + 357 368 574 584 597 635 655 665 729 757 807 833 + 985 + 22 + 3 88 119 170 192 226 274 294 309 446 500 520 + 526 535 621 626 637 840 843 857 906 912 + 22 + 86 133 174 288 307 367 422 423 435 479 493 525 + 586 615 686 737 791 854 886 905 926 966 + 20 + 83 129 142 152 232 389 398 472 490 511 623 631 + 643 703 769 845 860 894 960 987 + 18 + 46 117 167 173 177 328 373 392 503 587 647 669 + 798 881 941 983 987 994 + 17 + 116 145 246 295 380 386 405 493 513 575 663 701 + 722 747 795 908 984 + 22 + 33 110 159 162 211 244 268 275 378 461 477 508 + 542 575 688 744 755 785 809 823 920 939 + 24 + 2 5 45 118 134 138 223 233 248 280 304 580 + 615 721 748 771 789 812 826 837 889 911 947 994 + 18 + 81 154 166 185 272 397 455 510 550 612 649 661 + 678 763 791 903 932 973 + 14 + 124 215 229 471 573 575 653 672 757 829 845 895 + 936 989 + 22 + 54 71 80 189 279 307 448 491 510 529 609 703 + 708 716 784 803 805 806 842 890 962 985 + 23 + 7 14 70 180 226 338 348 365 408 480 505 567 + 664 676 745 749 804 817 858 904 959 973 985 + 19 + 58 62 69 77 136 180 236 309 368 384 479 619 + 662 688 757 828 854 885 931 + 18 + 13 49 77 122 164 236 343 398 399 443 487 535 + 546 675 696 716 963 967 + 23 + 16 23 47 95 190 253 327 341 348 372 378 416 + 555 604 663 685 689 695 751 754 825 897 960 + 22 + 138 165 276 394 492 494 532 547 548 665 694 742 + 744 745 752 824 838 844 881 938 952 974 + 18 + 23 126 231 236 284 353 364 471 535 616 659 699 + 735 751 819 856 923 935 + 13 + 22 34 497 509 519 804 869 871 888 892 909 939 + 962 + 19 + 58 60 130 159 310 321 348 398 412 459 544 555 + 600 631 927 937 958 986 989 + 17 + 68 70 87 180 207 220 247 309 334 364 587 630 + 684 725 827 873 877 + 19 + 128 146 157 161 263 277 329 338 466 496 537 564 + 604 826 837 849 961 979 995 + 12 + 340 426 433 509 576 700 743 752 790 846 949 975 + 25 + 4 25 58 68 70 87 122 160 165 169 461 462 + 536 538 539 708 735 807 821 847 898 904 905 972 + 979 + 22 + 44 208 224 288 521 554 556 566 586 597 621 647 + 651 688 766 781 866 882 904 925 940 971 + 15 + 44 123 145 162 206 230 249 756 768 794 836 854 + 889 915 920 + 19 + 61 97 109 153 206 239 240 267 443 506 555 659 + 844 852 941 946 957 982 984 + 24 + 143 145 169 174 238 251 268 317 400 417 485 486 + 515 548 564 709 721 758 764 784 810 874 903 960 + 28 + 5 45 83 168 187 199 228 291 309 343 444 457 + 486 662 690 704 711 743 773 808 833 845 848 855 + 863 867 904 936 + 16 + 2 46 101 227 283 313 399 503 504 550 667 846 + 851 912 958 965 + 14 + 48 253 349 409 423 475 515 518 613 649 671 763 + 799 817 + 20 + 22 81 124 378 389 470 537 545 602 603 628 701 + 725 742 760 762 784 785 938 1000 + 22 + 124 144 190 321 326 471 575 590 632 707 717 746 + 754 764 785 842 953 963 974 980 996 997 + 18 + 26 31 84 144 154 258 304 342 438 504 544 656 + 660 674 806 807 880 978 + 14 + 10 139 376 394 556 588 698 735 738 758 763 789 + 935 955 + 18 + 89 158 269 294 393 451 461 525 529 533 560 770 + 784 787 886 888 922 928 + 28 + 8 130 180 217 235 251 259 271 316 333 341 355 + 390 398 429 444 501 527 549 572 659 690 827 840 + 878 890 896 970 + 17 + 43 237 380 383 434 502 522 577 593 614 659 666 + 681 693 743 768 838 + 17 + 1 227 237 314 366 399 407 596 611 630 640 672 + 731 784 824 870 911 + 21 + 23 55 77 108 201 260 311 357 364 365 416 492 + 603 609 631 657 696 759 818 883 913 + 20 + 25 45 127 158 294 299 376 392 421 557 564 585 + 613 618 808 837 847 881 938 967 + 21 + 151 176 226 230 275 288 347 383 415 446 537 650 + 660 671 738 742 755 801 864 876 982 + 19 + 64 136 138 192 198 238 264 319 338 578 586 598 + 675 685 750 756 808 875 986 + 19 + 43 119 123 175 358 369 413 436 487 515 566 591 + 716 722 770 851 927 932 975 + 28 + 1 57 107 159 222 266 270 278 281 296 329 345 + 452 470 509 538 596 609 708 735 767 781 787 835 + 847 861 865 910 + 16 + 15 31 69 100 117 229 361 384 501 606 853 863 + 887 966 970 999 + 16 + 194 254 265 292 308 356 388 423 460 486 617 713 + 723 768 874 977 + 27 + 1 15 40 78 79 88 100 102 210 329 432 510 + 558 568 644 732 744 751 752 800 848 855 910 943 + 948 984 992 + 17 + 36 89 123 166 236 272 328 417 459 478 484 723 + 797 860 900 939 957 From 441f77e5202f23e430f71e6c068a9e15db41cdff Mon Sep 17 00:00:00 2001 From: Alexander Du Date: Sat, 13 Dec 2025 02:23:48 -0800 Subject: [PATCH 2/2] Added problems --- algorithmic/problems/7/chk.cc | 73 ++++++++++++++++++ algorithmic/problems/7/config.yaml | 9 +++ algorithmic/problems/7/statement.txt | 43 +++++++++++ algorithmic/problems/7/testdata/1.ans | 1 + algorithmic/problems/7/testdata/1.in | 1 + algorithmic/problems/75/chk.cc | 101 +++++++++++++++++++++++++ algorithmic/problems/75/config.yaml | 14 ++++ algorithmic/problems/75/statement.txt | 50 ++++++++++++ algorithmic/problems/75/testdata/1.ans | 0 algorithmic/problems/75/testdata/1.in | 1 + algorithmic/problems/80/config.yaml | 14 ++++ algorithmic/problems/80/interactor.cpp | 56 ++++++++++++++ algorithmic/problems/80/statement.txt | 79 +++++++++++++++++++ algorithmic/problems/80/testdata/1.ans | 0 algorithmic/problems/80/testdata/1.in | 13 ++++ algorithmic/problems/85/config.yaml | 8 ++ algorithmic/problems/85/interactor.cc | 78 +++++++++++++++++++ algorithmic/problems/85/statement.txt | 49 ++++++++++++ algorithmic/problems/85/testdata/1.ans | 1 + algorithmic/problems/85/testdata/1.in | 1 + 20 files changed, 592 insertions(+) create mode 100644 algorithmic/problems/7/chk.cc create mode 100644 algorithmic/problems/7/config.yaml create mode 100644 algorithmic/problems/7/statement.txt create mode 100644 algorithmic/problems/7/testdata/1.ans create mode 100644 algorithmic/problems/7/testdata/1.in create mode 100644 algorithmic/problems/75/chk.cc create mode 100644 algorithmic/problems/75/config.yaml create mode 100644 algorithmic/problems/75/statement.txt create mode 100644 algorithmic/problems/75/testdata/1.ans create mode 100644 algorithmic/problems/75/testdata/1.in create mode 100644 algorithmic/problems/80/config.yaml create mode 100644 algorithmic/problems/80/interactor.cpp create mode 100644 algorithmic/problems/80/statement.txt create mode 100644 algorithmic/problems/80/testdata/1.ans create mode 100644 algorithmic/problems/80/testdata/1.in create mode 100644 algorithmic/problems/85/config.yaml create mode 100644 algorithmic/problems/85/interactor.cc create mode 100644 algorithmic/problems/85/statement.txt create mode 100644 algorithmic/problems/85/testdata/1.ans create mode 100644 algorithmic/problems/85/testdata/1.in diff --git a/algorithmic/problems/7/chk.cc b/algorithmic/problems/7/chk.cc new file mode 100644 index 000000000..789b8e9d2 --- /dev/null +++ b/algorithmic/problems/7/chk.cc @@ -0,0 +1,73 @@ +#include "testlib.h" +#include +#include +#include + +using namespace std; + +vector >v[150]; +int l, r; +int in[150], out[150]; +int cnt = 0; +int vis[1000010]; + +void dfs(int x, int val){ + if(out[x] == 0){ + cnt++; + if(cnt > 1e6)quitf(_wa, "too many roads"); + if(val < l || val > r) quitf(_wa, "number outside interval"); + vis[val]++; + if(vis[val] > 1)quitf(_wa, "repeated roads"); + return; + } + for(int i = 0; i < out[x]; i++){ + dfs(v[x][i].first, val*2+v[x][i].second); + } +} + +int main(int argc, char *argv[]) { + /* + * inf:输入 + * ouf:选手输出 + * ans:标准输出 + */ + registerTestlibCmd(argc, argv); + + l = inf.readInt(), r = inf.readInt(); + + int n = ouf.readInt(1, 100); + for(int i = 1; i <= n; i++){ + out[i] = ouf.readInt(0, 200); + for(int j = 1; j <= out[i]; j++){ + int a = ouf.readInt(1, n), val = ouf.readInt(0, 1); + if(a == i)quitf(_wa, "self-loop"); + v[i].push_back(make_pair(a, val)); + in[a]++; + } + } + + // 1 in 0 and 1 out 0, no leading 0 + int cnt1 = 0, cnt2 = 0; + for(int i = 1; i <= n; i++){ + if(in[i] == 0)cnt1++; + if(out[i] == 0)cnt2++; + if(in[i] == 0){ + for(int j = 0; j < out[i]; j++){ + if(v[i][j].second == 0)quitf(_wa, "leading 0"); + } + } + } + if(cnt1 != 1 || cnt2 != 1)quitf(_wa, "more than one indegree or outdegree 0"); + + for(int i = 1; i <= n; i++){ + if(in[i] == 0)dfs(i, 0); + } + for(int i = l; i <= r; i++){ + if(vis[i] == 0)quitf(_wa, "number not represented"); + } + + double score = (100.0-1.0*n)/(100.0-50.0); + score = max(score, 0.0); + score = min(score, 1.0); + quitp(score, "Ratio: %.3lf", score); +} \ No newline at end of file diff --git a/algorithmic/problems/7/config.yaml b/algorithmic/problems/7/config.yaml new file mode 100644 index 000000000..79a11d097 --- /dev/null +++ b/algorithmic/problems/7/config.yaml @@ -0,0 +1,9 @@ +type: default +time: 1s +memory: 1024m +subtasks: + - score: 100 + n_cases: 1 +checker: chk.cc +checker_type: testlib +filename: std.cc \ No newline at end of file diff --git a/algorithmic/problems/7/statement.txt b/algorithmic/problems/7/statement.txt new file mode 100644 index 000000000..ced7a4b30 --- /dev/null +++ b/algorithmic/problems/7/statement.txt @@ -0,0 +1,43 @@ +Build a Computer +Input file: standard input +Output file: standard output +Time limit: 1 second +Memory limit: 1024 megabytes +You want to build a computer to achieve a specific functionality: Given an integerx, determine whether +x lies within the interval[L, R]. To accomplish this, you designed a directed acyclic graph (DAG) with +edge weights of0 and 1, which contains a starting node with an indegree of0 and an ending node with an +outdegree of0. By starting from the starting node and following a path to the ending node, the sequence +of the traversed edge weights forms a binary representation of an integer within the range[L, R] without +leading zeros. Every integer within the range[L, R] must correspond to exactly one unique path in this +graph. In this way, you can determine whether an integer lies within the range[L, R] by checking if its +binary representation can be constructed by traversing this DAG. +Clearly, you could separate the corresponding path for each integer into individual chains. However, you +realized that for a large range, such a DAG would require too many nodes, and the computer you built with +only 256 MiB of memory cannot store it. Therefore, you need to compress this DAG, allowing different +paths to share nodes, in order to reduce the number of nodes and edges. Formally, you need to construct +a DAG with no more than100 nodes, where each node has an outdegree of at most200. The DAG must +have edge weights of0 and 1, with exactly one starting node with an in-degree of0 and one ending node +with an out-degree of0. Every integer in the range[L, R] must correspond toexactly one unique path +from the start to the end in this DAG, and no path should represent any integer outside the range[L, R]. +Note that none of the binary sequences formed by any path in the graph should have leading zeros. There +may be two edges with different weights between two nodes. +Input +A single line containing two positive integersL, R(1 ≤L ≤R ≤106). +Output +The first line should output the number of nodesn (1 ≤n ≤100). You need to make n as small as possible and your score will be determined by the value of n. +For the nextn lines, thei-th line should start with an integerk (0 ≤k ≤200), representing the number +of outgoing edges from nodei. Then output2 ·k integers ai,k, vi,k (1 ≤ai,k ≤n, ai,k ̸= i, vi,k ∈{0, 1}), +which means that nodei has a directed edge with weightvi,k to node ai,k. You must ensure that the +output represents a directed acyclic graph that satisfies the requirements. +Example +standard input standard output +5 7 8 +3 2 1 3 1 4 1 +1 5 0 +1 6 1 +1 7 1 +1 8 1 +1 8 0 +1 8 1 +0 +Page 1 of 1 \ No newline at end of file diff --git a/algorithmic/problems/7/testdata/1.ans b/algorithmic/problems/7/testdata/1.ans new file mode 100644 index 000000000..4963d7992 --- /dev/null +++ b/algorithmic/problems/7/testdata/1.ans @@ -0,0 +1 @@ +577837 979141 diff --git a/algorithmic/problems/7/testdata/1.in b/algorithmic/problems/7/testdata/1.in new file mode 100644 index 000000000..4963d7992 --- /dev/null +++ b/algorithmic/problems/7/testdata/1.in @@ -0,0 +1 @@ +577837 979141 diff --git a/algorithmic/problems/75/chk.cc b/algorithmic/problems/75/chk.cc new file mode 100644 index 000000000..70fb5de42 --- /dev/null +++ b/algorithmic/problems/75/chk.cc @@ -0,0 +1,101 @@ +#include "testlib.h" +#include + +struct DSU { + std::vector f, siz; + + DSU() {} + DSU(int n) { + init(n); + } + + void init(int n) { + f.resize(n); + std::iota(f.begin(), f.end(), 0); + siz.assign(n, 1); + } + + int find(int x) { + while (x != f[x]) { + x = f[x] = f[f[x]]; + } + return x; + } + + bool same(int x, int y) { + return find(x) == find(y); + } + + bool merge(int x, int y) { + x = find(x), y = find(y); + if (x == y) { + return false; + } + f[y] = x; + siz[x] += siz[y]; + return true; + } + + int size(int x) { + return siz[find(x)]; + } +}; + +int main(int argc, char* argv[]) { + registerTestlibCmd(argc, argv); + + int b = inf.readInt(), w = inf.readInt(), x = inf.readInt(), y = inf.readInt(); + + int n = ouf.readInt(); + if (n < 1 || n > 100000) { + quitf(_wa, "Invalid: element %d is out of range [1, 100000]", n); + } + int m = ouf.readInt(); + if (m < 1 || m > 100000) { + quitf(_wa, "Invalid: element %d is out of range [1, 100000]", m); + } + if (n * m >= 100000) { + quitf(_wa, "Invalid: grid is too big."); + } + + std::vector s(n); + for (int i = 0; i < n; i++) { + s[i] = ouf.readWord(); + if (int(s[i].length()) != m || std::count(s[i].begin(), s[i].end(), '@') + std::count(s[i].begin(), s[i].end(), '.') != m) { + quitf(_wa, "Invalid: wrong format."); + } + } + + DSU dsu(n * m); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if (i + 1 < n && s[i][j] == s[i + 1][j]) { + dsu.merge(i * m + j, (i + 1) * m + j); + } + if (j + 1 < m && s[i][j] == s[i][j + 1]) { + dsu.merge(i * m + j, i * m + j + 1); + } + } + } + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + (s[i][j] == '@' ? b : w) -= dsu.find(i * m + j) == i * m + j; + } + } + if (b || w) { + quitp(0., "Incorrect Solution. Ratio: 0.0000"); + } + + int sum = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + sum += s[i][j] == '@' ? x : y; + } + } + + double ratio = std::max(1. * (8000 * (x + y) - sum) / (8000 * (x + y)), 0.); + quitp(ratio, "Correct Solution. Ratio: %.4f", ratio); + + return 0; +} \ No newline at end of file diff --git a/algorithmic/problems/75/config.yaml b/algorithmic/problems/75/config.yaml new file mode 100644 index 000000000..ad2a766e3 --- /dev/null +++ b/algorithmic/problems/75/config.yaml @@ -0,0 +1,14 @@ +# Set the problem type to interactive +type: default + +# Specify the interactor source file +interactor: chk.cc + +# Time and memory limits still apply to the contestant's solution +time: 2s +memory: 256m + +# The subtasks section works the same way +subtasks: + - score: 100 + n_cases: 1 # Looks for 1.in, 2.in, ... 5.in \ No newline at end of file diff --git a/algorithmic/problems/75/statement.txt b/algorithmic/problems/75/statement.txt new file mode 100644 index 000000000..0e7da95ac --- /dev/null +++ b/algorithmic/problems/75/statement.txt @@ -0,0 +1,50 @@ +Black and White + +Time limit: 2 seconds +Memory limit: 256 megabytes + +------------------------------------------------------------ +The jury has a great artistic idea — to create a rectangular +panel out of a huge pile of black and white squares of the +same size. The panel should have exactly b 4-connected areas +made of black tiles, and w 4-connected areas made of white tiles. + +A 4-connected area of some color is a maximal set of the +panel tiles such that: +• any two tiles of the area share the same color; +• for any two tiles of the area there is a tile sequence + connecting them, such that any two consecutive tiles of + the sequence share a common side. + +You will also be given two integers x, y. Try to minimize x * (the number of black tiles in your grid) + y * (the number of white tiles in your grid). + +------------------------------------------------------------ +Input +------------------------------------------------------------ +The only line of the input file contains four integers b, w — +number of black and white areas (1 ≤ b, w ≤ 1000) and x, y - grading coefficients (1 ≤ x, y ≤ 1000). + +------------------------------------------------------------ +Output +------------------------------------------------------------ +The first line of the output file should contain the picture sizes +r and c — the number of rows and columns (1 ≤ r, c ≤ 100 000). +This line should be followed by r lines of c symbols each. +Each symbol should be either '@' (for black tile) or '.' (for +white one). There should be no more than 100 000 tiles in +the panel. + +------------------------------------------------------------ +Example +------------------------------------------------------------ +Input: +2 3 5 6 + +Output: +6 7 +@@@@@@@ +@.@@@@@ +@@...@@ +@@@@@@@ +....... +@@@@@@@ diff --git a/algorithmic/problems/75/testdata/1.ans b/algorithmic/problems/75/testdata/1.ans new file mode 100644 index 000000000..e69de29bb diff --git a/algorithmic/problems/75/testdata/1.in b/algorithmic/problems/75/testdata/1.in new file mode 100644 index 000000000..960b83eae --- /dev/null +++ b/algorithmic/problems/75/testdata/1.in @@ -0,0 +1 @@ +992 754 327 86 diff --git a/algorithmic/problems/80/config.yaml b/algorithmic/problems/80/config.yaml new file mode 100644 index 000000000..572e6ff24 --- /dev/null +++ b/algorithmic/problems/80/config.yaml @@ -0,0 +1,14 @@ +# Set the problem type to interactive +type: interactive + +# Specify the interactor source file +interactor: interactor.cpp + +# Time and memory limits still apply to the contestant's solution +time: 2s +memory: 512m + +# The subtasks section works the same way +subtasks: + - score: 100 + n_cases: 1 # Looks for 1.in, 2.in, ... 5.in \ No newline at end of file diff --git a/algorithmic/problems/80/interactor.cpp b/algorithmic/problems/80/interactor.cpp new file mode 100644 index 000000000..bbf9c90c4 --- /dev/null +++ b/algorithmic/problems/80/interactor.cpp @@ -0,0 +1,56 @@ +#include "testlib.h" +#include + +int main(int argc, char* argv[]) { + registerInteraction(argc, argv); + + int n = inf.readInt(), m = inf.readInt(); + println(m); + + std::vector adj(n, std::vector(m)); + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + adj[i][j] = inf.readInt(); + } + } + + std::vector type(n, std::string("center")); + std::vector pos(n, 0); + int x = 0, cnt = 0; + std::vector vis(n, std::vector(m, false)); + + for (int q = 0; q <= 50000; q++) { + if (cnt == n * m) { + println("treasure"); + + double ratio = 1. * (50000 - q) / 50000; + quitp(ratio, "Ratio: %.4f", ratio); + } + println(type[x]); + + int c = ouf.readInt(); + if (c < 0 || c >= m) { + quitf(_wa, "Invalid query: element %d is out of range [0, %d]", c, m - 1); + } + std::string s = ouf.readWord(); + if (s != "left" && s != "right") { + quitf(_wa, "Invalid query: %s should be left or right.", s.c_str()); + } + int t = ouf.readInt(); + if (t < 0 || t >= m) { + quitf(_wa, "Invalid query: element %d is out of range [0, %d]", t, m - 1); + } + + int y = adj[x][(pos[x] + t) % m]; + if (!vis[x][(pos[x] + t) % m]) { + vis[x][(pos[x] + t) % m] = true; + cnt++; + } + type[x] = s; + pos[x] = (pos[x] + c) % m; + x = y; + } + quitp(0., "Too many queries. Ratio: 0.0000"); + + return 0; +} \ No newline at end of file diff --git a/algorithmic/problems/80/statement.txt b/algorithmic/problems/80/statement.txt new file mode 100644 index 000000000..f40eddf8a --- /dev/null +++ b/algorithmic/problems/80/statement.txt @@ -0,0 +1,79 @@ +Indiana Jones and the Uniform Cave + +This is an I/O interactive problem. I/O interaction refers to interactive problems, where the program communicates with a special judge during execution instead of producing all output at once. In these problems, the program sends queries (output) to the judge and must immediately read responses (input) before continuing. The solution must strictly follow the input-output protocol defined in the problem statement, because any extra output, missing flush, or incorrect format can cause a wrong answer. Unlike standard problems, interactive problems require careful handling of I/O, synchronization, and flushing to ensure smooth communication between the contestant’s code and the judge. + +Indiana Jones has stuck in the Uniform Cave. +There are many round chambers in the cave, and all of them are indistinguishable from each other. +Each chamber has the same number of one-way passages evenly distributed along the chamber’s wall. +Passages are indistinguishable from each other, too. + +The Cave is magical. All passages lead to other chambers or to the same one. +However, the last passage, after all passages are visited, leads to the treasure. +Even the exact number of chambers is a mystery. +It is known that each chamber is reachable from each other chamber using the passages. + +Dr. Jones noticed that each chamber has a stone in the center. +He decided to use these stones to mark chambers and passages. +A stone can be placed to the left or to the right of one of the passages. +When Indiana Jones enters the chamber all that he can observe is the location of the stone in the chamber. +He can move the stone to the desired location and take any passage leading out of the chamber. + +Your task is to help Indiana Jones to visit every passage in the Uniform Cave and find the treasure. + +Interaction Protocol + +First, the testing system writes the integer m — the number of passages in each chamber (2 ≤ m ≤ 20). + +Dr. Jones enters the chamber and sees, in the next line, where the stone is placed: +either in the “center” of the chamber or to the “left”, or to the “right” of some passage. +On the first visit to the chamber, the stone is in the center. + +Your solution shall output his actions: +the number and the side of the passage to place the stone to, +and the number of the passage to take. +Both numbers are relative to the passage marked by the stone, counting clockwise from 0 to m−1. +If the stone is in the center of the chamber, the origin is random. + +For example, +3 left 1 +tells that Dr. Jones moves the stone three passages clockwise and places it to the left of the passage, +then he takes the passage to the right of the initial stone position. + +After each move, the testing system tells either the location of the stone in the next chamber +or “treasure”, if Indiana Jones had found it. +The testing system writes “treasure” when all the passages are visited. + +If Dr. Jones does not find the treasure room after 50 000 passages are taken, he starves to death, +and your solution receives the “Wrong Answer” outcome. +You also receive this outcome if your solution terminates before all passages are taken. Let q be the number of passages you have taken, your score will be (50000 - q) / 50000. + +The total number of chambers in the cave is unknown, +but you may assume that it does not exceed 20, +and that each chamber is reachable from every other chamber. + +Example + +Standard Input +2 +center +left +center +left +right +treasure + +Standart Output +0 left 0 +1 left 1 +1 right 0 +0 left 0 +1 right 0 + +Dr. Jones enters the example cave and sees that the stone in the first chamber is in the center. +He marks the chamber by placing the stone to the left of some passage and takes it. +He sees the chamber where the stone is to the left of the passage, so he is in the first chamber again. +He moves the stone clockwise and takes the passage marked by it. +This passage leads to the second chamber. +He marks it by placing the stone to the right of some passage and takes another one. +He is in the first chamber again, so he returns to the second chamber and takes the remaining passage. +This passage leads to the treasure. \ No newline at end of file diff --git a/algorithmic/problems/80/testdata/1.ans b/algorithmic/problems/80/testdata/1.ans new file mode 100644 index 000000000..e69de29bb diff --git a/algorithmic/problems/80/testdata/1.in b/algorithmic/problems/80/testdata/1.in new file mode 100644 index 000000000..000d6fc82 --- /dev/null +++ b/algorithmic/problems/80/testdata/1.in @@ -0,0 +1,13 @@ +12 19 +9 8 5 10 9 2 10 4 10 1 0 3 4 1 11 11 0 4 11 +8 6 8 8 8 1 9 6 7 8 9 4 5 10 11 9 8 4 10 +1 5 8 5 3 10 9 3 10 3 8 7 4 6 1 4 11 2 0 +5 11 5 0 1 2 10 3 7 3 7 7 10 4 7 8 3 9 9 +9 10 9 10 5 5 0 0 1 7 4 9 10 9 4 0 8 11 8 +9 9 6 1 4 5 7 7 3 5 2 10 10 6 3 0 10 8 7 +7 6 3 6 3 3 7 6 1 6 10 7 4 4 3 1 9 6 5 +4 5 2 1 6 9 4 5 3 4 10 2 7 6 2 3 0 2 1 +3 7 4 2 6 1 7 3 5 9 8 4 1 1 7 1 3 0 11 +0 3 1 10 3 5 4 8 4 4 4 7 6 10 1 5 10 5 3 +5 7 5 11 4 9 1 11 9 8 2 10 8 8 5 8 8 4 8 +11 0 1 6 10 11 11 3 10 5 3 7 0 7 2 0 5 8 4 diff --git a/algorithmic/problems/85/config.yaml b/algorithmic/problems/85/config.yaml new file mode 100644 index 000000000..25195097c --- /dev/null +++ b/algorithmic/problems/85/config.yaml @@ -0,0 +1,8 @@ +type: interactive +time: 2s +memory: 512m +subtasks: + - score: 100 + n_cases: 1 +interactor: interactor.cc +checker_type: testlib \ No newline at end of file diff --git a/algorithmic/problems/85/interactor.cc b/algorithmic/problems/85/interactor.cc new file mode 100644 index 000000000..cb84afe46 --- /dev/null +++ b/algorithmic/problems/85/interactor.cc @@ -0,0 +1,78 @@ +#include "testlib.h" +#include +#include +#include +#include +#include + +using namespace std; + +int movecnt = 0, querycnt = 0; +int f[1100010]; + +int main(int argc, char *argv[]) { + /* + * inf:输入 + * ouf:选手输出 + * ans:标准输出 + */ + registerInteraction(argc, argv); + + int deep = inf.readInt(), seed = inf.readInt(); + memset(f, -1, sizeof(f)); + for(int i = 1; i <= deep; i++){ + int cur = -1; + while(true){ + seed = (seed*998244353ll+97)%1000000009; + cur = seed%3; + if(cur != f[i-1])break; + } + f[i] = cur; + } + cout.flush(); + cout< 100000){ + quitf(_wa, "Too many moves"); + } + if(c == f[deep]){ + deep--; + if(deep == 0){ + cout<<1< 100000){ + quitf(_wa, "Too many queries"); + } + cout<