Update dataset
Browse files- README.md +2 -2
- data/test-00000-of-00001.json +5 -0
README.md
CHANGED
|
@@ -19,8 +19,8 @@ A benchmark dataset for evaluating AI systems on challenging computer science pr
|
|
| 19 |
|
| 20 |
## Dataset Description
|
| 21 |
|
| 22 |
-
This dataset contains
|
| 23 |
-
- **Algorithmic**:
|
| 24 |
- **Research**: 66 open-ended research problems
|
| 25 |
|
| 26 |
## Dataset Structure
|
|
|
|
| 19 |
|
| 20 |
## Dataset Description
|
| 21 |
|
| 22 |
+
This dataset contains 244 problems across two categories:
|
| 23 |
+
- **Algorithmic**: 178 competitive programming problems with automated judging
|
| 24 |
- **Research**: 66 open-ended research problems
|
| 25 |
|
| 26 |
## Dataset Structure
|
data/test-00000-of-00001.json
CHANGED
|
@@ -124,6 +124,11 @@
|
|
| 124 |
{"problem_id": "28", "category": "algorithmic", "statement": "Hacking the Project\nInput file: standard input\nOutput file: standard output\nTime limit: 1 second\nMemory limit: 512 mebibytes\nThis is an interactive problem.\nLewis is one of the developers of the new programming language called DiverC. The main feature of the\nprogram written in this language is that the code consists of pairwise distinct words. The compiler of\nDiverC developed by Lewis is, of course, written in DiverC and consists ofN pairwise distinct words.\nLewis is using the DiverC online autofill service. But Lewis has made one serious mistake: he forgot to\nswitch the “use my data for the improvement of the service database” function off. And Lewis was the\nfirst person who registered on this service, so now the service contains only the words from his compiler.\nHacker Fernando wants to know all the words Lewis used in the compiler. So he registered at the DiverC\nonline autofill service (wisely switching the dangerous function off), and now, for each prefixS and integer\nK entered by Fernando, the service returns, in lexicographic order, the firstK words from Lewis’s code\nthat begin with the prefixS. If there are onlyk < Kwords, the service gives out onlyk words (but the\nservice usage counter increases byK even in this case).\nFernando checked the scripts used for the online service and found that one user is limited with the total value ofK in all queries. He wants to determine allN words used by Lewis with several queries\nsuch as the sum ofK in those queries is as less as possible.\nCan you help him?\nInteraction Protocol\nIn the beginning, your program shall read one integerT /emdash.cyr the number of the test cases to be processed\n(1 ≤T ≤5).\nAt the beginning of each test case, the jury program tells one integerN /emdash.cyr the number of the words in\nLewis’s DiverC compiler (1 ≤N ≤1 000).\nYour program can then make two types of requests:\n• query S K /emdash.cyr getK (1 ≤ K ≤ N) lexicographically minimal words starting with prefix S\n(1 ≤|S|≤ 10). If the dictionary contains onlyk such words, where k < K, the answer to the\nquery will containk words. The response to the query will be one line of the formkS1S2 . . . Sk,\nwhere k is the number of the words (0 ≤k ≤K), and thenk words Si in lexicographic order follow.\n• answer S1 S2 ...SN /emdash.cyr tell the full Lewis’s dictionary. After the wordanswer you shall print allN\nwords in an arbitrary order separated by spaces. There will be no response from the jury program\nto this request, and your program must then continue with the next test case or exit if the current\ntest case was the last one.\nThe words in Lewis’s code are composed of lowercase English letters. The length of words is between 1\nto 10 characters. All words in Lewis’s code are pairwise distinct.\nThe sum ofK for all queries of the first type for each test should be as less as possible. Your score will be determined by the number of this value. If this value is smaller, you will get a higher score if your final answer is correct.\nIf value is greater than 4000, the solution will get 0 points. \nViolating the interaction protocol or exceeding the limits for the sum ofK cause the “Wrong answer”\nverdict.\nMake sure you print the newline character after each query and flush the output stream buffer (flush\nlanguagecommand)aftereachrequest.Otherwise,thesolutionmaygettheidlenesslimitexceededverdict.\nNote that the jury program isadaptive, i.e. the set of Lewis’s words may be generated at the runtime,\nbut the set is guaranteed to be consistent with the answers to previous queries.\nPage 1 of 2Example\nstandard input standard output\n1\n4\n1 aaa\n2 aaa aba\n1 cxyxy\n0\n1 czzzz\nquery a 1\nquery a 4\nquery c 1\nquery cy 1\nquery cz 1\nanswer aaa aba czzzz cxyxy\nPage 2 of 2", "config": "type: interactive\ntime: 1s\nmemory: 512m\nsubtasks:\n - score: 100\n n_cases: 3\ninteractor: interactor.cc\nchecker_type: testlib"}
|
| 125 |
{"problem_id": "3", "category": "algorithmic", "statement": "This is an interactive question.\n\ntime limit: 10 seconds (up to 5 seconds for interactive library)\nSpace limitations: 1GB (up to 64MB for interactive library)\n\nDescription\nHope City is a city built on a floating island. At the edge of the floating island, there are n lamp sockets evenly distributed, forming a ring shape. Each lamp holder is labeled with a number between 1 and n, and forms an arrangement of length n in a clockwise direction p1, p2,..., pn. You don't know this arrangement and hope to restore it through interaction with the system.\n\nYou can ask the system to switch the state of a set of lamp holders at a time (if it was not originally lit, it will be lit; if it was originally lit, it will be extinguished).\n\nThe system will maintain a set of currently lit lamp holders S (initially empty) internally. You cannot directly see the contents of the set, but you can obtain the following information through interaction:\n\nYou can submit a set of operations at once (i.e. a series of target IDs for wick input), and the system will process each of these operations one by one:\n\n- If a lamp holder is not in S, it will be lit up after inserting the wick (add into S);\n- If a lamp holder is already in S, it will be extinguished up after inserting the wick (remove it from S);\n- After each operation, the system will record whether there is a pair of adjacent lamp holders on the ring in the current set S, and return the records of all operations together.\nAfter you submit a set of operations at once and receive the returned records, S will not be cleared, but will continue to serve as the initial set for the next set of operations.\n\nInput\nOne line, contains two integers, subtask, n, representing the subtask ID and the length of the loop;\n\nImplementation Details\nTo ask a query, output one line. First output a number L followed by a space, then print a sequence of L integers ranging from 1 to n separated by a space. \nAfter flushing your output, your program should read a sequence of L integers, indicating whether there are adjacent pairs in S after each operation.\nSpecifically, The system will maintain a set S, which is initially the result of the previous query (i.e. not reset), and sequentially scans each element u in this query:\nIf u is not in S when scanned, perform an operation to light up u so that u is in S; if u is in S when scanned, perform an operation to extinguish u so that u is not in S. Then report an integer indicating whether there are adjacent pairs in S after this operation(0: does not exist; 1: exist).\n\nIf you want to guess the permutation, output one line. First output -1 followed by a space, then print a permutation of n separated by a space, representing the arrangement of lamp holder numbers p1~pn. Since the ring has no starting point or direction, any cyclic shift of p1~pn or p1~pn is considered correct. After flushing your output, your program should exit immediately.\n\nNote that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.\n\nTo flush your output, you can use:\nfflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.\n\nSubtask\nSubtask 1 (10 points): Ensure n=1000.\nSubtask 2 (90 points): Ensure n=10 ^ 5.\n\nFor a testcase, if your interaction process is illegal or the returned answer is incorrect, you will directly receive 0 points.\n\nOtherwise, record the total number of times you call query as t, and record the sum of the number of operations you perform each time when calling query as Q.\n\nYour score ratio lambda will be calculated according to the following formula:\nlambda=max (0, 1-0.1 (f (t/18)+f (Q/ (1.5 * 10^7)))\nWhere f (x)=min (max (log_2 (x), 0), 8)\nThen, if the subtask where this testcase is located has a maximum score of S, then you will get lambda * S.\n\nThe total number of times you call query cannot exceed 10 ^ 7, and the sum of the number of operations you perform each time when calling 'query' cannot exceed 3 * 10 ^ 8.\nTo prevent unexpected behavior caused by a large vector, you also need to ensure that the number of operations in a single query call always does not exceed 10 ^ 7.\n\nInteractive Example\nAssuming n=4 and the arrangement of lamp holder is [2,4,1,3], the following is a valid interaction process:\n\nPlayer Program | Interaction Library | Description\n- | Call solve (4, 0) | Start the interaction process\nCall query ([1, 2]) | Return [0, 0] | Found that the two lamp holders with numbers 1 and 2 are not adjacent on the ring\nCall query ([1, 2]) | Return [0, 0] | extinguish 1,2\nCall query ([1, 3]) | Return [0, 1] | Found that two lamp holders with numbers 1 and 3 are adjacent on the ring\nCall query ([1, 3]) | Return [0, 0] | extinguish 1,3\nCall query ([1, 4]) | Return [0, 1] | Found that two lamp holders with numbers 1,4 are adjacent on the ring\nCall query ([1, 4]) | Return [0, 0] | extinguish 1,4\nCall query ([2, 3]) | Return [0, 1] | Found that two lamp holders with numbers 2 and 3 are adjacent on the ring\nCall query ([2, 3]) | Return [0, 0] | extinguish 2,3\nCall query ([2, 4]) | Return [0, 1] | Found that two lamp holders with numbers 2 and 4 are adjacent on the ring\nCall query ([2, 4]) | Return [0, 0] | extinguish 2,4\nCall query ([3, 4]) | Return [0, 0] | Found that the two lamp holders with numbers 3 and 4 are not adjacent on the ring\nCall query ([3, 4]) | Return [0, 0] | extinguish 3,4\nRun ends and returns [1, 4, 2, 3] | Print interaction result to screen | Interaction ends, result is correct\n", "config": "type: interactive\ntime: 10s\nmemory: 1024m\n# A custom checker is required for the special scoring.\ninteractor: interactor.cc\nsubtasks:\n - score: 100\n n_cases: 3"}
|
| 126 |
{"problem_id": "30", "category": "algorithmic", "statement": "This is an interactive problem.\n\nYou are given a tree of n\n nodes with node 1\n as its root node.\n\nThere is a hidden mole in one of the nodes. To find its position, you can pick an integer x\n (1≤x≤n\n) to make an inquiry to the jury. Next, the jury will return 1\n when the mole is in subtree x\n. Otherwise, the judge will return 0\n. If the judge returns 0\n and the mole is not in root node 1\n, the mole will move to the parent node of the node it is currently on.\n\nUse at most 160\n operations to find the current node where the mole is located. If the number of operations is more than 160, you will get zero grade. Otherwise, your grade will be determined by the sum of the depth of the nodes in your query (the same node in two different queries will be counted twice). The depth of a node is the distance from the node to the root and the depth of the root is 0. \n\nInput\nEach test contains multiple test cases. The first line contains the number of test cases t\n (1≤t≤100\n). The description of the test cases follows.\n\nInteraction\nThe first line of each test case contains one integer n\n (2≤n≤5000\n).\n\nThe following n−1\n lines describe the edges of the tree. Each line contains two space-separated integers ui\n and vi\n (1≤ui,vi≤n\n), indicating an edge between nodes ui\n and vi\n.\n\nIt is guaranteed that the input data represents a tree.\n\nThe interactor in this task is not adaptive. In other words, the node where the mole is located at first is fixed in every test case and does not change during the interaction.\n\nTo ask a query, you need to pick a vertex x\n (1≤x≤n\n) and print the line of the following form:\n\n\"? x\"\nAfter that, you receive:\n\n0\n if the mole is not in subtree x\n;\n1\n if the mole is in subtree x\n.\nYou can make at most 500\n queries of this form for each test case. Apart from this condition, you need to try to minimize the sum of the depth of the nodes in your query.\n\nNext, if your program has found the current node where the mole is located, print the line of the following form:\n\n\"! x\"\nNote that this line is not considered a query and is not taken into account when counting the number of queries asked.\n\nAfter this, proceed to the next test case.\n\nIf you make more than 160\n queries during an interaction, your program must terminate immediately, and you will receive the Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.\n\nAfter printing a query or the answer for a test case, do not forget to output the end of line and flush the output. Otherwise, you will get the verdict Idleness Limit Exceeded. To do this, use:\n\nfflush(stdout) or cout.flush() in C++;\nSystem.out.flush() in Java;\nflush(output) in Pascal;\nstdout.flush() in Python;\nsee the documentation for other languages.\n\nExample\nInputCopy\n2\n2\n1 2\n\n1\n\n6\n1 2\n1 3\n1 4\n4 5\n5 6\n\n0\n\n0\n\n1\nOutputCopy\n\n\n\n? 2\n\n! 2\n\n\n\n\n\n\n? 2\n\n? 6\n\n? 4\n\n! 4\nNote\nIn the first test case, the mole is in node 2\n initially.\n\nFor the query \"? 2\", the jury returns 1\n because the mole is in subtree 2\n. After this query, the mole does not move.\n\nThe answer 2\n is the current node where the mole is located, so the answer is considered correct.\n\nIn the second test case, the mole is in node 6\n initially.\n\nFor the query \"? 2\", the jury returns 0\n because the mole is not in subtree 2\n. After this query, the mole moves from node 6\n to node 5\n.\n\nFor the query \"? 6\", the jury returns 0\n because the mole is not in subtree 6\n. After this query, the mole moves from node 5\n to node 4\n.\n\nFor the query \"? 4\", the jury returns 1\n because the mole is in subtree 4\n. After this query, the mole does not move.\n\nThe answer 4\n is the current node where the mole is located, so the answer is considered correct.\n\nPlease note that the example is only for understanding the statement, and the queries in the example do not guarantee to determine the unique position of the mole.\n\n\n", "config": "type: interactive\ntime: 4s\nmemory: 256m\nsubtasks:\n - score: 100\n n_cases: 3\ninteractor: interactor.cc\nchecker_type: testlib"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
{"problem_id": "33", "category": "algorithmic", "statement": "Permutation (Modified Version)\n\nTime Limit: 5 s\nMemory Limit: 1024 MB\n\nThe Pharaohs use the relative movement and gravity of planets to accelerate their spaceships. Suppose a spaceship will pass by some planets with orbital speeds in order. For each planet, the Pharaohs' scientists can choose whether to accelerate the spaceship using this planet or not. To save energy, after accelerating by a planet with orbital speed p[i], the spaceship cannot be accelerated using any planet with orbital speed p[j] < p[i]. In other words, the chosen planets form an increasing subsequence of p.\n\nThe scientists have identified that there are exactly k different ways a set of planets can be chosen to accelerate the spaceship. They have lost their record of all the orbital speeds (even the value of n). However, they remember that p is a permutation of {0, 1, …, n−1}. Your task is to find one possible permutation of sufficiently small length.\n\nInput\nThe first line contains an integer q (1 ≤ q ≤ 100), the number of spaceships.\nThe second line contains q integers k1, k2, …, kq (2 ≤ ki ≤ 10^18).\n\nOutput\nFor each ki, output two lines:\n- The first line contains an integer n (the length of the permutation).\n- The second line contains n integers: a valid permutation of {0, 1, …, n−1} having exactly ki increasing subsequences.\n\nScoring\nLet m be the maximum permutation length you used across all queries.\nYour score for the test file will be determined as follows:\n\nm ≤ 90 → 100 points\n\n90 < m < 2000 -> linear function\n\nm >= 2000 -> 0\n\nExample\nInput\n2\n3 8\n\nOutput\n2\n1 0\n3\n0 1 2\n\nExplanation\nFor k = 3, one valid permutation is [1, 0], which has exactly 3 increasing subsequences: [], [0], [1].\nFor k = 8, one valid permutation is [0, 1, 2], which has exactly 8 increasing subsequences: [], [0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2].\n", "config": "type: default\ntime: 5s\nmemory: 1024m\nsubtasks:\n - score: 100\n n_cases: 3\nchecker: checker.cpp\nchecker_type: testlib"}
|
| 128 |
{"problem_id": "35", "category": "algorithmic", "statement": "Language: C++ only\n\nTime limit per test: 5 seconds\nMemory limit per test: 1024 megabytes\n\nThis is an interactive problem.\n\nThere is a hidden array a containing all the numbers from 1 to n, and all of them appear twice except one (which only appears once).\n\nYou can ask queries in the following format, where S is a subset of {1,2,…,2n−1} and x is an integer in [1,n]:\n\n? x |S| S1 S2 ... S|S|\n\nThe answer to this query is: does there exist i ∈ S such that a_i = x ?\n\nYour task is to find the number appearing exactly once, using at most 5000 queries. You don’t need to find its position.\n\nNote that the interactor is not adaptive, which means that the hidden array does not depend on the queries you make.\n\nInput\nEach test contains multiple test cases.\nThe first line contains the number of test cases t (1 ≤ t ≤ 20).\n\nThe description of the test cases follows.\n\nThe first line of each test case contains a single integer n (n = 300) — the maximum value in the hidden array.\n\nInteraction\nFor each test case, first read a single integer. If the integer you read is -1, it means that the answer to the previous test case was wrong, and you should exit immediately.\n\nYou may ask up to 5000 queries in each test case.\n\nTo ask a query, print a line in the format described above.\nAs a response to the query, you will get:\n\n1 if the answer is yes,\n\n0 if the answer is no,\n\n-1 if you made an invalid query. In this case you should exit immediately.\n\nTo output an answer, print:\n! y\nwhere y is the number that appears exactly once.\nPrinting the answer doesn’t count as a query.\n\nIf you ask too many queries, you ask a malformed query, or your answer is wrong, you will get -1.\n\nAfter printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded.\nIn C++, you can use:\nfflush(stdout);\ncout.flush();\n\nScoring\n\nIf you solve the problem with at most 500 queries, you get 100 points.\n\nIf you solve it with 5000 queries, you get 0 points.\n\nFor values in between, the score decreases linearly.\n\nExample\nInput\n1\n300\n0\n\nExplanation\nIn the first test case, n = 300, so the hidden array has length 2n − 1 = 599.\n\nContestant prints / Interactor replies\n? 187 1 1\n0\n! 187\n\nQuery: does a1 = 187? → No.\nWe then output ! 187.\nFortunately, the answer is correct.\n\nWe have asked 1 query (printing the answer does not count as a query), which is less than the maximum allowed number of queries (5000).", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cpp\n\n# Time and memory limits still apply to the contestant's solution\ntime: 5s\nmemory: 1024m\n\n# The subtasks section works the same way\nsubtasks:\n - score: 100\n n_cases: 3 # Looks for 1.in, 2.in, ... 5.in"}
|
| 129 |
{"problem_id": "36", "category": "algorithmic", "statement": "Hack!\n\nThis 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.\n\nYou know that unordered_set uses a hash table with n buckets, which are numbered from 0 to\nn − 1. Unfortunately, you do not know the value of n and wish to recover it.\nWhen you insert an integer x into the hash table, it is inserted to the (x mod n) -th bucket. If\nthere are b elements in this bucket prior to the insertion, this will cause b hash collisions to occur.\n\nBy giving k distinct integers x[0],x[1],…,x[k − 1] to the interactor, you can find out the total\nnumber of hash collisions that had occurred while creating an unordered_set containing the\nnumbers. However, feeding this interactor k integers in one query will incur a cost of k.\nFor example, if n = 5, feeding the interactor with x = [2, 15, 7, 27, 8, 30] would cause 4 collisions in\ntotal:\n\nOperation New collisions Buckets\ninitially − [],[],[],[],[]\ninsert x[0] = 2 0 [],[],[2],[],[]\ninsert x[1] = 15 0 [15],[],[2],[],[]\ninsert x[2] = 7 1 [15],[],[2, 7],[],[]\ninsert x[3] = 27 2 [15],[],[2, 7, 27],[],[]\ninsert x[4] = 8 0 [15],[],[2, 7, 27],[8],[]\ninsert x[5] = 30 1 [15, 30],[],[2, 7, 27],[8],[]\n\nNote that the interactor creates the hash table by inserting the elements in order into an initially empty unordered_set, and a new empty unordered_set will be created for each query. In other words, all queries are independent.\n\nYour task is to find the number of buckets n (2<=n<=10^9) using total cost of at most 1 000 000. Total cost is the total length of your queries. You have to minimize total cost as much as possible. Your final score will be calculated as the average of 100 * clamp(log_50(10^6 / (your_total_cost - 9 * 10^4)), 0, 1) across all cases.\n\nInput\n\nThere is no input in this problem.\n\nInteraction\n\nTo ask a query, output one line. First output 0 followed by a space, then output an positive integer m, the number of elements in this query, then print a sequence of m integers ranging from 1 to 10^18 separated by a space. After flushing your output, your program should read a single integer x indicating the number of collisions created by inserting the elements in order to an unordered_set.\n\nIf you want to guess n, output one line. First output 1 followed by a space, then print the n you guess. After flushing your output, your program should exit immediately.\n\nNote that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.\n\nTo flush your output, you can use:\n\n fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.\n\n System.out.flush() in Java.\n\n stdout.flush() in Python.\n\nNote\n\nPlease note that if you receive a Time Limit Exceeded verdict, it is possible that your query is invalid or the number of queries exceeds the limit.\n\nConstraints \n- Time limit: 3 seconds\n- Memory Limit: 1024 MB\n- Let Q be the query cost you make.\n - If your program exceeds time limit, memory limit, or returns incorrect answer → score=0.\n - Otherwise, your score depends on Q:\n - score(Q) = 1000001 / (Q + 1)\n - In other words, a solution with Q <= 1000000 is awarded the full score.\n\nExample input (you to interactor):\n0 6 2 15 7 27 8 30\n\n0 3 1 2 3\n\n0 5 10 20 30 40 50\n\n1 5\n\nExample output (interactor to you):\n\n4\n\n0\n\n10", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cpp\n\n# Time and memory limits still apply to the contestant's solution\ntime: 3s\nmemory: 1024m\n\n# The subtasks section works the same way\nsubtasks:\n - score: 100\n n_cases: 3 # Looks for 1.in, 2.in, ... 5.in"}
|
|
|
|
| 124 |
{"problem_id": "28", "category": "algorithmic", "statement": "Hacking the Project\nInput file: standard input\nOutput file: standard output\nTime limit: 1 second\nMemory limit: 512 mebibytes\nThis is an interactive problem.\nLewis is one of the developers of the new programming language called DiverC. The main feature of the\nprogram written in this language is that the code consists of pairwise distinct words. The compiler of\nDiverC developed by Lewis is, of course, written in DiverC and consists ofN pairwise distinct words.\nLewis is using the DiverC online autofill service. But Lewis has made one serious mistake: he forgot to\nswitch the “use my data for the improvement of the service database” function off. And Lewis was the\nfirst person who registered on this service, so now the service contains only the words from his compiler.\nHacker Fernando wants to know all the words Lewis used in the compiler. So he registered at the DiverC\nonline autofill service (wisely switching the dangerous function off), and now, for each prefixS and integer\nK entered by Fernando, the service returns, in lexicographic order, the firstK words from Lewis’s code\nthat begin with the prefixS. If there are onlyk < Kwords, the service gives out onlyk words (but the\nservice usage counter increases byK even in this case).\nFernando checked the scripts used for the online service and found that one user is limited with the total value ofK in all queries. He wants to determine allN words used by Lewis with several queries\nsuch as the sum ofK in those queries is as less as possible.\nCan you help him?\nInteraction Protocol\nIn the beginning, your program shall read one integerT /emdash.cyr the number of the test cases to be processed\n(1 ≤T ≤5).\nAt the beginning of each test case, the jury program tells one integerN /emdash.cyr the number of the words in\nLewis’s DiverC compiler (1 ≤N ≤1 000).\nYour program can then make two types of requests:\n• query S K /emdash.cyr getK (1 ≤ K ≤ N) lexicographically minimal words starting with prefix S\n(1 ≤|S|≤ 10). If the dictionary contains onlyk such words, where k < K, the answer to the\nquery will containk words. The response to the query will be one line of the formkS1S2 . . . Sk,\nwhere k is the number of the words (0 ≤k ≤K), and thenk words Si in lexicographic order follow.\n• answer S1 S2 ...SN /emdash.cyr tell the full Lewis’s dictionary. After the wordanswer you shall print allN\nwords in an arbitrary order separated by spaces. There will be no response from the jury program\nto this request, and your program must then continue with the next test case or exit if the current\ntest case was the last one.\nThe words in Lewis’s code are composed of lowercase English letters. The length of words is between 1\nto 10 characters. All words in Lewis’s code are pairwise distinct.\nThe sum ofK for all queries of the first type for each test should be as less as possible. Your score will be determined by the number of this value. If this value is smaller, you will get a higher score if your final answer is correct.\nIf value is greater than 4000, the solution will get 0 points. \nViolating the interaction protocol or exceeding the limits for the sum ofK cause the “Wrong answer”\nverdict.\nMake sure you print the newline character after each query and flush the output stream buffer (flush\nlanguagecommand)aftereachrequest.Otherwise,thesolutionmaygettheidlenesslimitexceededverdict.\nNote that the jury program isadaptive, i.e. the set of Lewis’s words may be generated at the runtime,\nbut the set is guaranteed to be consistent with the answers to previous queries.\nPage 1 of 2Example\nstandard input standard output\n1\n4\n1 aaa\n2 aaa aba\n1 cxyxy\n0\n1 czzzz\nquery a 1\nquery a 4\nquery c 1\nquery cy 1\nquery cz 1\nanswer aaa aba czzzz cxyxy\nPage 2 of 2", "config": "type: interactive\ntime: 1s\nmemory: 512m\nsubtasks:\n - score: 100\n n_cases: 3\ninteractor: interactor.cc\nchecker_type: testlib"}
|
| 125 |
{"problem_id": "3", "category": "algorithmic", "statement": "This is an interactive question.\n\ntime limit: 10 seconds (up to 5 seconds for interactive library)\nSpace limitations: 1GB (up to 64MB for interactive library)\n\nDescription\nHope City is a city built on a floating island. At the edge of the floating island, there are n lamp sockets evenly distributed, forming a ring shape. Each lamp holder is labeled with a number between 1 and n, and forms an arrangement of length n in a clockwise direction p1, p2,..., pn. You don't know this arrangement and hope to restore it through interaction with the system.\n\nYou can ask the system to switch the state of a set of lamp holders at a time (if it was not originally lit, it will be lit; if it was originally lit, it will be extinguished).\n\nThe system will maintain a set of currently lit lamp holders S (initially empty) internally. You cannot directly see the contents of the set, but you can obtain the following information through interaction:\n\nYou can submit a set of operations at once (i.e. a series of target IDs for wick input), and the system will process each of these operations one by one:\n\n- If a lamp holder is not in S, it will be lit up after inserting the wick (add into S);\n- If a lamp holder is already in S, it will be extinguished up after inserting the wick (remove it from S);\n- After each operation, the system will record whether there is a pair of adjacent lamp holders on the ring in the current set S, and return the records of all operations together.\nAfter you submit a set of operations at once and receive the returned records, S will not be cleared, but will continue to serve as the initial set for the next set of operations.\n\nInput\nOne line, contains two integers, subtask, n, representing the subtask ID and the length of the loop;\n\nImplementation Details\nTo ask a query, output one line. First output a number L followed by a space, then print a sequence of L integers ranging from 1 to n separated by a space. \nAfter flushing your output, your program should read a sequence of L integers, indicating whether there are adjacent pairs in S after each operation.\nSpecifically, The system will maintain a set S, which is initially the result of the previous query (i.e. not reset), and sequentially scans each element u in this query:\nIf u is not in S when scanned, perform an operation to light up u so that u is in S; if u is in S when scanned, perform an operation to extinguish u so that u is not in S. Then report an integer indicating whether there are adjacent pairs in S after this operation(0: does not exist; 1: exist).\n\nIf you want to guess the permutation, output one line. First output -1 followed by a space, then print a permutation of n separated by a space, representing the arrangement of lamp holder numbers p1~pn. Since the ring has no starting point or direction, any cyclic shift of p1~pn or p1~pn is considered correct. After flushing your output, your program should exit immediately.\n\nNote that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.\n\nTo flush your output, you can use:\nfflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.\n\nSubtask\nSubtask 1 (10 points): Ensure n=1000.\nSubtask 2 (90 points): Ensure n=10 ^ 5.\n\nFor a testcase, if your interaction process is illegal or the returned answer is incorrect, you will directly receive 0 points.\n\nOtherwise, record the total number of times you call query as t, and record the sum of the number of operations you perform each time when calling query as Q.\n\nYour score ratio lambda will be calculated according to the following formula:\nlambda=max (0, 1-0.1 (f (t/18)+f (Q/ (1.5 * 10^7)))\nWhere f (x)=min (max (log_2 (x), 0), 8)\nThen, if the subtask where this testcase is located has a maximum score of S, then you will get lambda * S.\n\nThe total number of times you call query cannot exceed 10 ^ 7, and the sum of the number of operations you perform each time when calling 'query' cannot exceed 3 * 10 ^ 8.\nTo prevent unexpected behavior caused by a large vector, you also need to ensure that the number of operations in a single query call always does not exceed 10 ^ 7.\n\nInteractive Example\nAssuming n=4 and the arrangement of lamp holder is [2,4,1,3], the following is a valid interaction process:\n\nPlayer Program | Interaction Library | Description\n- | Call solve (4, 0) | Start the interaction process\nCall query ([1, 2]) | Return [0, 0] | Found that the two lamp holders with numbers 1 and 2 are not adjacent on the ring\nCall query ([1, 2]) | Return [0, 0] | extinguish 1,2\nCall query ([1, 3]) | Return [0, 1] | Found that two lamp holders with numbers 1 and 3 are adjacent on the ring\nCall query ([1, 3]) | Return [0, 0] | extinguish 1,3\nCall query ([1, 4]) | Return [0, 1] | Found that two lamp holders with numbers 1,4 are adjacent on the ring\nCall query ([1, 4]) | Return [0, 0] | extinguish 1,4\nCall query ([2, 3]) | Return [0, 1] | Found that two lamp holders with numbers 2 and 3 are adjacent on the ring\nCall query ([2, 3]) | Return [0, 0] | extinguish 2,3\nCall query ([2, 4]) | Return [0, 1] | Found that two lamp holders with numbers 2 and 4 are adjacent on the ring\nCall query ([2, 4]) | Return [0, 0] | extinguish 2,4\nCall query ([3, 4]) | Return [0, 0] | Found that the two lamp holders with numbers 3 and 4 are not adjacent on the ring\nCall query ([3, 4]) | Return [0, 0] | extinguish 3,4\nRun ends and returns [1, 4, 2, 3] | Print interaction result to screen | Interaction ends, result is correct\n", "config": "type: interactive\ntime: 10s\nmemory: 1024m\n# A custom checker is required for the special scoring.\ninteractor: interactor.cc\nsubtasks:\n - score: 100\n n_cases: 3"}
|
| 126 |
{"problem_id": "30", "category": "algorithmic", "statement": "This is an interactive problem.\n\nYou are given a tree of n\n nodes with node 1\n as its root node.\n\nThere is a hidden mole in one of the nodes. To find its position, you can pick an integer x\n (1≤x≤n\n) to make an inquiry to the jury. Next, the jury will return 1\n when the mole is in subtree x\n. Otherwise, the judge will return 0\n. If the judge returns 0\n and the mole is not in root node 1\n, the mole will move to the parent node of the node it is currently on.\n\nUse at most 160\n operations to find the current node where the mole is located. If the number of operations is more than 160, you will get zero grade. Otherwise, your grade will be determined by the sum of the depth of the nodes in your query (the same node in two different queries will be counted twice). The depth of a node is the distance from the node to the root and the depth of the root is 0. \n\nInput\nEach test contains multiple test cases. The first line contains the number of test cases t\n (1≤t≤100\n). The description of the test cases follows.\n\nInteraction\nThe first line of each test case contains one integer n\n (2≤n≤5000\n).\n\nThe following n−1\n lines describe the edges of the tree. Each line contains two space-separated integers ui\n and vi\n (1≤ui,vi≤n\n), indicating an edge between nodes ui\n and vi\n.\n\nIt is guaranteed that the input data represents a tree.\n\nThe interactor in this task is not adaptive. In other words, the node where the mole is located at first is fixed in every test case and does not change during the interaction.\n\nTo ask a query, you need to pick a vertex x\n (1≤x≤n\n) and print the line of the following form:\n\n\"? x\"\nAfter that, you receive:\n\n0\n if the mole is not in subtree x\n;\n1\n if the mole is in subtree x\n.\nYou can make at most 500\n queries of this form for each test case. Apart from this condition, you need to try to minimize the sum of the depth of the nodes in your query.\n\nNext, if your program has found the current node where the mole is located, print the line of the following form:\n\n\"! x\"\nNote that this line is not considered a query and is not taken into account when counting the number of queries asked.\n\nAfter this, proceed to the next test case.\n\nIf you make more than 160\n queries during an interaction, your program must terminate immediately, and you will receive the Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.\n\nAfter printing a query or the answer for a test case, do not forget to output the end of line and flush the output. Otherwise, you will get the verdict Idleness Limit Exceeded. To do this, use:\n\nfflush(stdout) or cout.flush() in C++;\nSystem.out.flush() in Java;\nflush(output) in Pascal;\nstdout.flush() in Python;\nsee the documentation for other languages.\n\nExample\nInputCopy\n2\n2\n1 2\n\n1\n\n6\n1 2\n1 3\n1 4\n4 5\n5 6\n\n0\n\n0\n\n1\nOutputCopy\n\n\n\n? 2\n\n! 2\n\n\n\n\n\n\n? 2\n\n? 6\n\n? 4\n\n! 4\nNote\nIn the first test case, the mole is in node 2\n initially.\n\nFor the query \"? 2\", the jury returns 1\n because the mole is in subtree 2\n. After this query, the mole does not move.\n\nThe answer 2\n is the current node where the mole is located, so the answer is considered correct.\n\nIn the second test case, the mole is in node 6\n initially.\n\nFor the query \"? 2\", the jury returns 0\n because the mole is not in subtree 2\n. After this query, the mole moves from node 6\n to node 5\n.\n\nFor the query \"? 6\", the jury returns 0\n because the mole is not in subtree 6\n. After this query, the mole moves from node 5\n to node 4\n.\n\nFor the query \"? 4\", the jury returns 1\n because the mole is in subtree 4\n. After this query, the mole does not move.\n\nThe answer 4\n is the current node where the mole is located, so the answer is considered correct.\n\nPlease note that the example is only for understanding the statement, and the queries in the example do not guarantee to determine the unique position of the mole.\n\n\n", "config": "type: interactive\ntime: 4s\nmemory: 256m\nsubtasks:\n - score: 100\n n_cases: 3\ninteractor: interactor.cc\nchecker_type: testlib"}
|
| 127 |
+
{"problem_id": "301", "category": "algorithmic", "statement": "```markdown\n# Rope Network for Xiaotu (Optimization)\n\n## Problem\nXiaotu is training for sprints inside a **convex polygon** playground with \\(n\\) vertices \\((0 \\ldots n-1)\\) listed in counterclockwise order.\n\nThe organizer will install **exactly \\(K\\)** “safety ropes”. Each rope is a straight segment connecting two polygon vertices (an edge or a diagonal). Because the polygon is convex, every such segment lies fully inside the playground.\n\nWhen Xiaotu is at a position \\(p\\) (uniformly random inside the polygon), he runs straight to the **nearest rope** (Euclidean distance to the segment). Your task is to choose which \\(K\\) ropes to install (from a given candidate list) to **minimize the expected running distance**.\n\nThis is an open-ended optimization task: many different valid outputs exist, and they get different scores.\n\n---\n\n## Input\n```\nn m K S seed\nx0 y0\nx1 y1\n...\nx(n-1) y(n-1)\na0 b0\na1 b1\n...\na(m-1) b(m-1)\n```\n\n- \\(n\\): number of polygon vertices.\n- \\(m\\): number of candidate ropes.\n- \\(K\\): number of ropes you must select.\n- \\(S\\): number of evaluation sample points used by the judge.\n- `seed`: 64-bit unsigned integer used to deterministically generate the \\(S\\) sample points.\n\nVertices:\n- Each of the next \\(n\\) lines gives integer coordinates \\((x_i, y_i)\\).\n\nCandidates:\n- Each of the next \\(m\\) lines gives two integers \\((a_j, b_j)\\) with \\(0 \\le a_j < b_j < n\\), specifying a candidate rope between vertices \\(a_j\\) and \\(b_j\\).\n\n### Guarantees\n- The polygon is strictly convex.\n- No three vertices are collinear.\n- Vertices are given counterclockwise.\n- \\(1 \\le K \\le m\\).\n\n---\n\n## Output\nOutput exactly \\(K\\) **distinct** integers:\n```\nid1 id2 ... idK\n```\nwhere each `id` is in \\([0, m-1]\\), identifying selected candidate ropes.\n\n### Feasibility rules\nA submission is **feasible** iff:\n- Exactly \\(K\\) integers are printed.\n- All are distinct.\n- All are in \\([0, m-1]\\).\n\nInfeasible outputs receive a score of `0` (see **Scoring**).\n\n---\n\n## Objective\nLet the selected rope set be \\(R\\) (size \\(K\\)).\n\nThe judge deterministically generates \\(S\\) points \\(p_0, \\dots, p_{S-1}\\) **uniformly at random in the polygon** (but using the fixed `seed`, so it is deterministic).\n\nFor each point \\(p\\), define its cost:\n\\[\nd(p, R) = \\min_{(u,v)\\in R} \\mathrm{dist}(p, \\overline{uv})\n\\]\nwhere \\(\\mathrm{dist}(p, \\overline{uv})\\) is the Euclidean distance from point \\(p\\) to the **segment** from vertex \\(u\\) to vertex \\(v\\).\n\nFor a feasible output, your objective value is the mean distance:\n\\[\n\\mathrm{OBJ} = \\frac{1}{S}\\sum_{t=0}^{S-1} d(p_t, R)\n\\]\nYou must **minimize** `OBJ`.\n\n---\n\n## Deterministic sampling (used by the judge)\nBecause the polygon is convex, the judge triangulates it as a fan from vertex 0:\n\\[\nT_i = (0, i, i+1), \\quad i=1 \\ldots n-2\n\\]\nLet \\(A_i\\) be the (positive) area of triangle \\(T_i\\), and \\(A=\\sum A_i\\).\n\n### PRNG\nThe judge uses this 64-bit xorshift* generator:\n\n- State is `uint64 x`, initialized to `seed`.\n- Each call:\n - `x ^= x >> 12; x ^= x << 25; x ^= x >> 27;`\n - return `x * 2685821657736338717ULL`.\n\nTo get a uniform real in \\([0,1)\\), the judge uses:\n\\[\nU = \\frac{\\text{next\\_uint64()}}{2^{64}}\n\\]\n\n### Sampling one point\nFor each sample \\(t\\):\n1. Draw \\(r = U_1 \\cdot A\\). Choose the smallest \\(i\\) with \\(\\sum_{j=1}^{i} A_j > r\\).\n2. In triangle \\((a,b,c) = (v_0, v_i, v_{i+1})\\), draw \\(u=U_2, v=U_3\\), then set:\n - \\(s=\\sqrt{u}\\)\n - \\(\\alpha = 1-s,\\ \\beta = s(1-v),\\ \\gamma = sv\\)\n - \\(p = \\alpha a + \\beta b + \\gamma c\\)\n\nThis produces points uniform over the polygon.\n\n---\n\n## Scoring\nThis is a **minimization** problem.\n\nFor each test case, the judge computes:\n- `OBJ_you`: your objective value.\n- `OBJ_base`: the objective value of a deterministic internal reference solution computed from that test case.\n\n### Per-test score\nLet:\n- \\(B = \\mathrm{OBJ\\_base}\\)\n- \\(Y = \\mathrm{OBJ\\_you}\\)\n\nIf your output is infeasible, then `score_test = 0`.\n\nOtherwise, the score for that test is:\n\\[\n\\mathrm{score\\_test} = \\mathrm{clamp}\\left(\\frac{B - Y}{\\max(B, 10^{-30})},\\ 0,\\ 1\\right)\n\\]\n\nThis means:\n- matching the baseline gets score `0`\n- improving on the baseline gives a score in `(0, 1]`\n- doing worse than the baseline is clamped to `0`\n\n### Final score\nThe checker emits one per-test ratio in `[0, 1]` for each hidden test case.\nThe final score is the sum of these per-test ratios, scaled to the total points configured for this problem.\n\n---\n\n## Constraints\n- Time limit: 2 seconds\n- Memory limit: 256 MB\n\nHidden tests satisfy:\n- \\(3 \\le n \\le 100{,}000\\)\n- \\(1 \\le m \\le 200{,}000\\)\n- \\(1 \\le K \\le 50\\)\n- \\(5{,}000 \\le S \\le 50{,}000\\)\n- \\(-10^9 \\le x_i,y_i \\le 10^9\\)\n\n---\n\n## Example\n### Sample input\n```\n5 7 2 5000 1234567\n0 0\n10 0\n12 6\n6 12\n-2 7\n0 1\n1 2\n2 3\n3 4\n0 2\n1 3\n0 3\n```\n\n### Sample output\n```\n4 5\n```\n\n### Explanation (high level)\nYou chose candidate ropes #4 \\((0,2)\\) and #5 \\((1,3)\\). The judge generates 5000 deterministic uniform sample points inside the polygon (using seed 1234567), computes for each point the distance to the nearer of these two segments, averages those distances to get `OBJ_you`, then compares that objective against the judge's deterministic reference objective to compute the normalized score.\n```\n", "config": "checker: chk.cc\nmemory: 256m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 2s\ntype: default\n"}
|
| 128 |
+
{"problem_id": "302", "category": "algorithmic", "statement": "```markdown\n# Spectrum-Friendly Beacon String (Optimization)\n\n## Problem\nA satellite sends a beacon as a string of symbols. The radio channel has two kinds of interference:\n\n1. **Transition interference**: certain consecutive symbol pairs (bigrams) are more likely to be misread, causing a penalty.\n2. **Motif interference**: certain short patterns (substrings) trigger harmonics and cause additional penalty every time they appear (overlaps count).\n\nYou are given:\n- the beacon length `n`,\n- an alphabet of the first `k` lowercase Latin letters (`a..`),\n- an **exact required usage count** for each letter,\n- a **bigram penalty matrix**,\n- and a list of **motif penalties**.\n\nYour task is to output any feasible beacon string with **minimum total penalty**.\n\nThis is an optimization task: many feasible strings exist; they are scored by how small the penalty is.\n\n## Input\n```\nn k\nc1 c2 ... ck\nk lines each with k integers: W[i][j]\nm\np1 w1\np2 w2\n...\npm wm\n```\n\nWhere:\n- `1 ≤ k ≤ 26`\n- `k ≤ n ≤ 200000`\n- `ci` are positive integers with `c1 + ... + ck = n` (each letter must appear at least once)\n- `W[i][j]` is the penalty for adjacent letters `(char i) -> (char j)`\n - indices `i,j` correspond to letters `a..` in order (so `i=1` means `a`)\n - `0 ≤ W[i][j] ≤ 10^6`\n- `m` is the number of motifs\n - `0 ≤ m ≤ 200000`\n- Each motif line contains:\n - `pt` — a non-empty string over the first `k` letters, with `2 ≤ |pt| ≤ 10`\n - `wt` — an integer penalty, `1 ≤ wt ≤ 10^6`\n- Total motif length over all motifs is at most `200000`.\n\n## Output\nPrint a single line containing a string `s` such that:\n- `|s| = n`\n- every character of `s` is among the first `k` letters (`a..`)\n- each letter appears **exactly** `ci` times\n\nAny feasible output is accepted and scored.\n\n## Objective\nLet `s` be your output string.\n\n### 1) Transition penalty\n\\[\nP_{\\text{bigram}}(s) = \\sum_{t=1}^{n-1} W[s_t][s_{t+1}]\n\\]\n\n### 2) Motif penalty\nFor each motif `pi` with weight `wi`, let `occ(pi, s)` be the number of positions `t`\nsuch that `s[t..t+|pi|-1] = pi` (overlaps are counted).\n\\[\nP_{\\text{motif}}(s) = \\sum_{i=1}^{m} w_i \\cdot occ(p_i, s)\n\\]\n\n### Total penalty (to minimize)\n\\[\nP(s) = P_{\\text{bigram}}(s) + P_{\\text{motif}}(s)\n\\]\n\n## Scoring\nThis problem is evaluated on multiple hidden test instances.\n\nFor each test instance:\n- If your output is infeasible (wrong length, characters outside the alphabet, or wrong per-letter counts), you get ratio `0`.\n- Otherwise, let `X = P(s)` be your total penalty.\n- The judge also computes a deterministic internal reference string from the same test instance.\n- Let `B` be the total penalty of that reference string.\n\nYour per-test ratio is:\n\\[\n\\mathrm{ratio} = \\mathrm{clamp}\\left(\\frac{B - X}{\\max(B, 1)},\\, 0,\\, 1\\right)\n\\]\nwhere `clamp(x,0,1)=min(1,max(0,x))`.\n\nLower penalty is strictly better, and matching or exceeding the baseline penalty gives ratio `0`.\n\nThe final score is the sum of per-test ratios, scaled to the total points configured for this problem.\n\n## Constraints\n- Time limit: 2 seconds\n- Memory limit: 256 MB\n\n## Example\n### Input\n```\n10 3\n4 3 3\n0 5 1\n2 0 4\n3 1 0\n3\nab 7\nbaa 6\ncc 5\n```\n\n### Sample Output\n```\nabcabcabca\n```\n\n### Explanation (high-level)\n- This output is just one feasible string for this instance: it uses exactly 4 `a`’s, 3 `b`’s, and 3 `c`’s. It is not claimed to be optimal or even good; any feasible string is accepted.\n- The judge computes:\n - sum of `W[s_t][s_{t+1}]` over all adjacent pairs,\n - plus 7 for each occurrence of `\"ab\"`,\n - plus 6 for each occurrence of `\"baa\"`,\n - plus 5 for each occurrence of `\"cc\"`.\n- The judge compares that total penalty against its deterministic internal reference penalty for the same test.\n```\n", "config": "checker: chk.cc\nmemory: 256m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 2s\ntype: default\n"}
|
| 129 |
+
{"problem_id": "303", "category": "algorithmic", "statement": "```markdown\n# Manhattan Compass Prospecting (Optimization)\n\n## Problem\nThere are **N** distinct pinholes on the 2D plane. The *i*-th pinhole is at integer coordinates \\((x_i, y_i)\\) and has a nonnegative integer value \\(w_i\\).\n\nYou operate a peculiar instrument, the **Manhattan Compass**, which always touches **exactly two distinct pinholes** at a time. The two legs are indistinguishable: the state “touching \\((p,q)\\)” is the same as “touching \\((q,p)\\)”.\n\nLet the Manhattan distance be:\n\\[\nd(i,j) = |x_i-x_j| + |y_i-y_j|.\n\\]\n\n### Allowed move\nSuppose the compass currently touches pinholes \\(\\{p,q\\}\\) with \\(p \\neq q\\).\n\nYou may perform one move to change the state to \\(\\{p,r\\}\\) **(keeping \\(p\\) fixed and moving the other leg)** if and only if:\n- \\(r \\neq p\\), and\n- \\(d(p,q) = d(p,r)\\).\n\nSimilarly, you may move to \\(\\{q,r\\}\\) if \\(d(p,q)=d(q,r)\\).\n\n### Collecting value and paying cost\n- You **collect** the value \\(w_i\\) of a pinhole \\(i\\) the **first time** it is touched by either leg at any time (including initially).\n- Each move has a fixed **time cost** \\(c\\) (given in input).\n- You are allowed to make at most **L** moves.\n\nYou start with the compass touching pinholes \\(\\{a,b\\}\\).\n\nYour task is to output **any valid sequence of moves** (possibly empty) to **maximize profit**.\n\n---\n\n## Input\n```\nN L a b c\nx_1 y_1 w_1\nx_2 y_2 w_2\n:\nx_N y_N w_N\n```\n\n### Constraints\n- \\(2 \\le N \\le 200000\\)\n- \\(0 \\le L \\le 200000\\)\n- \\(1 \\le a < b \\le N\\)\n- \\(1 \\le x_i, y_i \\le 10^9\\)\n- \\(0 \\le w_i \\le 10^6\\)\n- \\(0 \\le c \\le 10^6\\)\n- All \\((x_i,y_i)\\) are distinct.\n\n---\n\n## Output\nOutput a move sequence in the following format:\n```\nS\nu_1 v_1\nu_2 v_2\n:\nu_S v_S\n```\nwhere:\n- \\(S\\) is the number of moves, and must satisfy \\(0 \\le S \\le L\\).\n- Each line \\(u_t, v_t\\) denotes the **unordered** pair of pinholes touched **after** the \\(t\\)-th move.\n- Feasibility requirements:\n - \\(1 \\le u_t, v_t \\le N\\), \\(u_t \\ne v_t\\).\n - Let the initial state be \\(\\{u_0,v_0\\}=\\{a,b\\}\\).\n - For each \\(t \\ge 1\\), the transition from \\(\\{u_{t-1},v_{t-1}\\}\\) to \\(\\{u_t,v_t\\}\\) must be achievable by **one allowed move** (i.e., the two pairs share exactly one pinhole, and the Manhattan distances from the shared pinhole to the moved endpoints are equal as defined above).\n\nIf the output violates any feasibility rule, the submission is invalid for that test case.\n\n---\n\n## Objective\nFor a feasible output, define:\n- \\(T\\) = the set of pinholes that appear in any touched pair, i.e.\n \\[\n T = \\{a,b\\} \\cup \\bigcup_{t=1}^{S} \\{u_t, v_t\\}.\n \\]\n- Collected value:\n \\[\n V = \\sum_{i \\in T} w_i.\n \\]\n- Profit:\n \\[\n P = V - c \\cdot S.\n \\]\n\n**Maximize** \\(P\\).\n\n---\n\n## Scoring\nThis is an optimization problem with continuous scoring.\n\nFor each test case, the judge computes:\n- Your profit \\(P\\).\n- A deterministic internal reference profit \\(P_0\\), computed by the judge from the same test case.\n\nThe per-test score ratio is:\n\\[\n\\text{ratio} =\n\\begin{cases}\n0 & \\text{if } P \\le 0 \\\\\n\\mathrm{clamp}\\left(\\dfrac{P - P_0}{P},\\, 0,\\, 1\\right) & \\text{otherwise}\n\\end{cases}\n\\]\nwhere \\(\\mathrm{clamp}(x,0,1)=\\min(1,\\max(0,x))\\).\n\nThe final score is the sum of per-test ratios, scaled to the total points configured for this problem.\n\n---\n\n## Constraints\n- Time limit: 2 seconds\n- Memory limit: 1024 MB\n\n---\n\n## Example\n### Sample input\n```\n6 5 1 2 3\n1 1 10\n4 1 8\n7 1 7\n4 4 100\n1 4 6\n7 4 6\n```\n\n### Sample output\n```\n3\n1 3\n3 6\n6 4\n```\n\n### Explanation (high level)\n- Start touching \\(\\{1,2\\}\\); collected so far: \\(w_1+w_2=18\\).\n- Each printed pair must be reachable by one allowed move (equal-distance rule around the shared pinhole).\n- The judge computes the set of touched pinholes \\(T\\), sums their values to get \\(V\\), subtracts \\(c \\cdot S\\) to get profit \\(P\\), then compares \\(P\\) against the judge's deterministic reference profit \\(P_0\\) using the normalized ratio above.\n```\n", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 8\n score: 100\ntime: 2s\ntype: default\n"}
|
| 130 |
+
{"problem_id": "304", "category": "algorithmic", "statement": "```markdown\n# Forest Mycelium Delay Tour (Optimization Challenge)\n\n## Problem\nVasya is mapping a forest trail network with **mushroom clearings**.\n\nThe forest is modeled as an undirected connected graph with `N` clearings (vertices) and `M` trails (edges). \nAt clearing `i`, mushrooms grow at a constant rate `r[i]` grams per minute, starting from **0 grams at time 0**.\n\n- Vasya starts at clearing `1` at time `t = 0`.\n- Each minute, Vasya **must** traverse exactly one trail to an adjacent clearing (no waiting).\n- When Vasya **first arrives** at a clearing `i` at time `t`, he instantly collects **all mushrooms grown there so far**, equal to `r[i] * t` grams.\n- After the first collection at clearing `i`, that clearing becomes barren and yields **0** on future visits.\n- Vasya will walk for exactly `K` minutes (i.e., traverse exactly `K` edges), ending anywhere.\n- To be feasible, his walk must visit **every clearing at least once** during times `0..K`.\n\nYour goal is to output a feasible walk that **maximizes the total collected mushroom weight**.\n\nThis is an open-ended optimization task: many solutions are valid, and they receive different scores.\n\n## Input\n```\nN M K\nr1 r2 ... rN\nu1 v1\nu2 v2\n...\nuM vM\n```\n\n- `1 ≤ N ≤ 20000`\n- `N-1 ≤ M ≤ 60000`\n- `2·(N-1) ≤ K ≤ 200000`\n- `1 ≤ r[i] ≤ 10^6`\n- `1 ≤ uj, vj ≤ N`, `uj != vj`\n- The graph is connected.\n- Multiple edges may appear; self-loops do not appear.\n\nThe constraints guarantee that a walk of length `K` visiting all vertices exists.\n\n## Output\nOutput exactly `K` integers:\n```\nx1 x2 ... xK\n```\nwhere `xt` is the clearing Vasya is at **after** minute `t` (after the `t`-th move).\n\nFeasibility requirements:\n- Vasya starts at clearing `1` at time `0`.\n- For each `t = 1..K`, the move from the previous clearing to `xt` must follow an existing trail (edge).\n- Every clearing `1..N` must appear at least once among the visited clearings at times `0..K` (including the start at time 0).\n\nIf the output is infeasible, the solution receives **0 score for that test**.\n\n## Objective\nLet `pos(t)` be Vasya’s clearing at time `t` (`pos(0)=1`, `pos(t)=xt` for `t≥1`).\n\nFor each clearing `i`, define its first-visit time:\n- `T[i] = min { t ∈ [0..K] | pos(t) = i }`\n\nTotal collected weight:\n\\[\nV = \\sum_{i=1}^{N} r[i] \\cdot T[i]\n\\]\n(Notice `T[1]=0`, so clearing 1 contributes `0`.)\n\nYou must **maximize** `V`.\n\n## Scoring\nScoring is computed **per test**.\n\n### Reference value `B`\nFor each test, the judge computes a deterministic internal reference walk from the same instance, and lets `B` be the objective value of that walk.\n\n### Per-test score\nIf `V = 0`, the per-test ratio is defined as `0`.\n\nOtherwise, for your solution value `V`, the per-test ratio is:\n\\[\n\\mathrm{ratio} = \\mathrm{clamp}\\left(\\frac{V - B}{V},\\, 0,\\, 1\\right)\n\\]\nwhere `clamp(x,0,1)=min(1,max(0,x))`.\n\n### Total score\nThe final score is the sum of per-test ratios, scaled to the total points configured for this problem.\n\n## Constraints\n- Time limit: 2 seconds\n- Memory limit: 256 MB\n\n## Example\nSample input:\n```\n4 4 6\n5 1 4 10\n1 2\n2 3\n3 4\n1 4\n```\n\nOne valid sample output:\n```\n2 3 2 1 4 3\n```\n\nExplanation (high level):\n- Path: time 0 at 1, time 1 at 2, time 2 at 3, time 3 at 2, time 4 at 1, time 5 at 4, time 6 at 3.\n- First-visit times: `T[1]=0, T[2]=1, T[3]=2, T[4]=5`.\n- Objective value: `V = 5·0 + 1·1 + 4·2 + 10·5 = 59`.\n- The judge also computes the baseline value `B` for this test, then assigns a normalized ratio using the formula above.\n```\n", "config": "checker: chk.cc\nmemory: 256m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 2s\ntype: default\n"}
|
| 131 |
+
{"problem_id": "305", "category": "algorithmic", "statement": "```markdown\n# Cascading Flip Schedule on a Power Grid Tree\n\n## Problem\nYou operate a power grid shaped as a tree with **N** substations (vertices) and **N−1** transmission lines (edges). \nEach substation has a reversible breaker with two states:\n\n- `W` (white) = **safe to service**\n- `B` (black) = **unsafe to service**\n\nInitially, the states are given by a string **S** of length **N**.\n\nYou must **service every substation exactly once** by choosing an order and performing a cascade operation. However, servicing a substation may destabilize nearby substations by flipping breaker states.\n\n### Cascade Service Operation\nYou perform **N rounds**. In round **t** you choose a substation **P_t** that has not been serviced yet, and you:\n1. **Pay cost** equal to the number of currently-unsafe breakers (`B`) among **unserviced** substations (including the chosen one if it is `B`).\n2. **Service** substation **P_t** (it becomes “removed” and is never flipped again).\n3. For every **unserviced neighbor** of **P_t**, **flip** its breaker state (`W ↔ B`).\n\nServiced substations are removed from the system:\n- They no longer contribute to future costs.\n- Their breakers are no longer flipped.\n\n### Feasibility\nAny permutation of vertices is a valid schedule (you may service a `B` substation; it just tends to be expensive). \nYour goal is not feasibility but **minimizing total instability cost**.\n\n## Input\n```\nN\nA_1 B_1\nA_2 B_2\n…\nA_{N-1} B_{N-1}\nS\n```\n- The graph is a tree.\n- Edge `i` connects vertices `A_i` and `B_i`.\n- `S[i]` is `W` or `B`, the initial breaker state at vertex `i`.\n\n## Output\nOutput a permutation of `1..N`:\n```\nP_1 P_2 … P_N\n```\nThis is your service order.\n\nA submission is invalid if:\n- It does not contain each vertex exactly once, or\n- It contains an out-of-range index.\n\nInvalid submissions receive the worst possible score for that test.\n\n## Objective\nLet `U_t` be the set of **unserviced** vertices just before round `t` (so `U_1` is all vertices, `U_{N+1}` is empty).\n\nLet `B_t` be the number of vertices in `U_t` whose breaker is `B` at that moment.\n\nYour **total cost** is:\n\\[\nC = \\sum_{t=1}^{N} B_t\n\\]\nYou must **minimize** `C`.\n\nNotes:\n- Breaker flips happen **after** paying `B_t`.\n- Only **unserviced neighbors** are flipped.\n\n## Scoring\nThis is an **optimization** problem; lower cost is better.\n\nFor each test case, the judge computes:\n- `C_out`: cost of your output schedule.\n- `C_base`: cost of a deterministic internal reference schedule computed from that test case.\n\nYour per-test ratio is:\n\\[\ns =\n\\begin{cases}\n0 & \\text{if } C_{\\text{base}} = 0 \\\\\n\\mathrm{clamp}\\!\\left(\\frac{C_{\\text{base}} - C_{\\text{out}}}{C_{\\text{base}}},\\, 0,\\, 1\\right) & \\text{otherwise}\n\\end{cases}\n\\]\nwhere `clamp(x,0,1)=min(1,max(0,x))`.\n\nSpecial cases:\n- Invalid output: `s = 0`.\n\n### Reference cost `C_base`\n`C_base` is the cost of a deterministic internal reference schedule computed by the judge from the same test case.\n\nThe exact construction of this internal reference schedule is intentionally not part of the contestant-facing specification. For solving the problem, you should optimize `C_out` directly according to the objective above.\n\n### Total score\nThe per-test ratio `s` is scaled to the total points configured for this problem in the judge configuration; the final score is the sum of these scaled per-test contributions across all test cases.\n\n## Why this is hard\nThe cascade flips create long-range dependencies: choosing a vertex changes future states of its neighbors, which changes future costs. Minimizing the integral of “how many unsafe breakers remain over time” is closely related to difficult sequencing problems on graphs; under these constraints, exact optimization is computationally infeasible in practice, so heuristics matter.\n\nMultiple strategies can work well:\n- Greedy selection by estimated marginal impact on future `B_t`\n- Tree decompositions with local dynamic programming + recombination\n- Large neighborhood search / simulated annealing on permutations\n- Beam search over partial schedules\n- Hybrid methods (greedy initialization + local swap/2-opt/segment moves + repair)\n\n## Constraints\n- `1 ≤ N ≤ 2×10^5`\n- `1 ≤ A_i, B_i ≤ N`\n- The input graph is a tree.\n- `S` consists only of `B` and `W`.\n- Time limit: **2 seconds**\n- Memory limit: **1024 MB**\n\n## Example\nSample input:\n```\n4\n1 2\n2 3\n3 4\nWBWW\n```\n\nOne possible output:\n```\n1 2 4 3\n```\n\nExplanation (high level):\n- The judge simulates your order.\n- Each round adds the current count of `B` among remaining vertices, then flips unserviced neighbors of the chosen vertex.\n- The resulting total `C_out` is compared against the judge's deterministic reference cost `C_base`, producing a ratio `s ∈ [0, 1]` for this test which is then scaled to the configured per-test point budget.\n```\n", "config": "checker: chk.cc\nmemory: 1024m\nsubtasks:\n- n_cases: 8\n score: 100\ntime: 2s\ntype: default\n"}
|
| 132 |
{"problem_id": "33", "category": "algorithmic", "statement": "Permutation (Modified Version)\n\nTime Limit: 5 s\nMemory Limit: 1024 MB\n\nThe Pharaohs use the relative movement and gravity of planets to accelerate their spaceships. Suppose a spaceship will pass by some planets with orbital speeds in order. For each planet, the Pharaohs' scientists can choose whether to accelerate the spaceship using this planet or not. To save energy, after accelerating by a planet with orbital speed p[i], the spaceship cannot be accelerated using any planet with orbital speed p[j] < p[i]. In other words, the chosen planets form an increasing subsequence of p.\n\nThe scientists have identified that there are exactly k different ways a set of planets can be chosen to accelerate the spaceship. They have lost their record of all the orbital speeds (even the value of n). However, they remember that p is a permutation of {0, 1, …, n−1}. Your task is to find one possible permutation of sufficiently small length.\n\nInput\nThe first line contains an integer q (1 ≤ q ≤ 100), the number of spaceships.\nThe second line contains q integers k1, k2, …, kq (2 ≤ ki ≤ 10^18).\n\nOutput\nFor each ki, output two lines:\n- The first line contains an integer n (the length of the permutation).\n- The second line contains n integers: a valid permutation of {0, 1, …, n−1} having exactly ki increasing subsequences.\n\nScoring\nLet m be the maximum permutation length you used across all queries.\nYour score for the test file will be determined as follows:\n\nm ≤ 90 → 100 points\n\n90 < m < 2000 -> linear function\n\nm >= 2000 -> 0\n\nExample\nInput\n2\n3 8\n\nOutput\n2\n1 0\n3\n0 1 2\n\nExplanation\nFor k = 3, one valid permutation is [1, 0], which has exactly 3 increasing subsequences: [], [0], [1].\nFor k = 8, one valid permutation is [0, 1, 2], which has exactly 8 increasing subsequences: [], [0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2].\n", "config": "type: default\ntime: 5s\nmemory: 1024m\nsubtasks:\n - score: 100\n n_cases: 3\nchecker: checker.cpp\nchecker_type: testlib"}
|
| 133 |
{"problem_id": "35", "category": "algorithmic", "statement": "Language: C++ only\n\nTime limit per test: 5 seconds\nMemory limit per test: 1024 megabytes\n\nThis is an interactive problem.\n\nThere is a hidden array a containing all the numbers from 1 to n, and all of them appear twice except one (which only appears once).\n\nYou can ask queries in the following format, where S is a subset of {1,2,…,2n−1} and x is an integer in [1,n]:\n\n? x |S| S1 S2 ... S|S|\n\nThe answer to this query is: does there exist i ∈ S such that a_i = x ?\n\nYour task is to find the number appearing exactly once, using at most 5000 queries. You don’t need to find its position.\n\nNote that the interactor is not adaptive, which means that the hidden array does not depend on the queries you make.\n\nInput\nEach test contains multiple test cases.\nThe first line contains the number of test cases t (1 ≤ t ≤ 20).\n\nThe description of the test cases follows.\n\nThe first line of each test case contains a single integer n (n = 300) — the maximum value in the hidden array.\n\nInteraction\nFor each test case, first read a single integer. If the integer you read is -1, it means that the answer to the previous test case was wrong, and you should exit immediately.\n\nYou may ask up to 5000 queries in each test case.\n\nTo ask a query, print a line in the format described above.\nAs a response to the query, you will get:\n\n1 if the answer is yes,\n\n0 if the answer is no,\n\n-1 if you made an invalid query. In this case you should exit immediately.\n\nTo output an answer, print:\n! y\nwhere y is the number that appears exactly once.\nPrinting the answer doesn’t count as a query.\n\nIf you ask too many queries, you ask a malformed query, or your answer is wrong, you will get -1.\n\nAfter printing a query, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded.\nIn C++, you can use:\nfflush(stdout);\ncout.flush();\n\nScoring\n\nIf you solve the problem with at most 500 queries, you get 100 points.\n\nIf you solve it with 5000 queries, you get 0 points.\n\nFor values in between, the score decreases linearly.\n\nExample\nInput\n1\n300\n0\n\nExplanation\nIn the first test case, n = 300, so the hidden array has length 2n − 1 = 599.\n\nContestant prints / Interactor replies\n? 187 1 1\n0\n! 187\n\nQuery: does a1 = 187? → No.\nWe then output ! 187.\nFortunately, the answer is correct.\n\nWe have asked 1 query (printing the answer does not count as a query), which is less than the maximum allowed number of queries (5000).", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cpp\n\n# Time and memory limits still apply to the contestant's solution\ntime: 5s\nmemory: 1024m\n\n# The subtasks section works the same way\nsubtasks:\n - score: 100\n n_cases: 3 # Looks for 1.in, 2.in, ... 5.in"}
|
| 134 |
{"problem_id": "36", "category": "algorithmic", "statement": "Hack!\n\nThis 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.\n\nYou know that unordered_set uses a hash table with n buckets, which are numbered from 0 to\nn − 1. Unfortunately, you do not know the value of n and wish to recover it.\nWhen you insert an integer x into the hash table, it is inserted to the (x mod n) -th bucket. If\nthere are b elements in this bucket prior to the insertion, this will cause b hash collisions to occur.\n\nBy giving k distinct integers x[0],x[1],…,x[k − 1] to the interactor, you can find out the total\nnumber of hash collisions that had occurred while creating an unordered_set containing the\nnumbers. However, feeding this interactor k integers in one query will incur a cost of k.\nFor example, if n = 5, feeding the interactor with x = [2, 15, 7, 27, 8, 30] would cause 4 collisions in\ntotal:\n\nOperation New collisions Buckets\ninitially − [],[],[],[],[]\ninsert x[0] = 2 0 [],[],[2],[],[]\ninsert x[1] = 15 0 [15],[],[2],[],[]\ninsert x[2] = 7 1 [15],[],[2, 7],[],[]\ninsert x[3] = 27 2 [15],[],[2, 7, 27],[],[]\ninsert x[4] = 8 0 [15],[],[2, 7, 27],[8],[]\ninsert x[5] = 30 1 [15, 30],[],[2, 7, 27],[8],[]\n\nNote that the interactor creates the hash table by inserting the elements in order into an initially empty unordered_set, and a new empty unordered_set will be created for each query. In other words, all queries are independent.\n\nYour task is to find the number of buckets n (2<=n<=10^9) using total cost of at most 1 000 000. Total cost is the total length of your queries. You have to minimize total cost as much as possible. Your final score will be calculated as the average of 100 * clamp(log_50(10^6 / (your_total_cost - 9 * 10^4)), 0, 1) across all cases.\n\nInput\n\nThere is no input in this problem.\n\nInteraction\n\nTo ask a query, output one line. First output 0 followed by a space, then output an positive integer m, the number of elements in this query, then print a sequence of m integers ranging from 1 to 10^18 separated by a space. After flushing your output, your program should read a single integer x indicating the number of collisions created by inserting the elements in order to an unordered_set.\n\nIf you want to guess n, output one line. First output 1 followed by a space, then print the n you guess. After flushing your output, your program should exit immediately.\n\nNote that the answer for each test case is pre-determined. That is, the interactor is not adaptive. Also note that your guess does not count as a query.\n\nTo flush your output, you can use:\n\n fflush(stdout) (if you use printf) or cout.flush() (if you use cout) in C and C++.\n\n System.out.flush() in Java.\n\n stdout.flush() in Python.\n\nNote\n\nPlease note that if you receive a Time Limit Exceeded verdict, it is possible that your query is invalid or the number of queries exceeds the limit.\n\nConstraints \n- Time limit: 3 seconds\n- Memory Limit: 1024 MB\n- Let Q be the query cost you make.\n - If your program exceeds time limit, memory limit, or returns incorrect answer → score=0.\n - Otherwise, your score depends on Q:\n - score(Q) = 1000001 / (Q + 1)\n - In other words, a solution with Q <= 1000000 is awarded the full score.\n\nExample input (you to interactor):\n0 6 2 15 7 27 8 30\n\n0 3 1 2 3\n\n0 5 10 20 30 40 50\n\n1 5\n\nExample output (interactor to you):\n\n4\n\n0\n\n10", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cpp\n\n# Time and memory limits still apply to the contestant's solution\ntime: 3s\nmemory: 1024m\n\n# The subtasks section works the same way\nsubtasks:\n - score: 100\n n_cases: 3 # Looks for 1.in, 2.in, ... 5.in"}
|