andylizf commited on
Commit
d55dab1
·
verified ·
1 Parent(s): 9375d73

Update dataset

Browse files
Files changed (2) hide show
  1. README.md +2 -2
  2. data/test-00000-of-00001.json +1 -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 238 problems across two categories:
23
- - **Algorithmic**: 172 competitive programming problems with automated judging
24
  - **Research**: 66 open-ended research problems
25
 
26
  ## Dataset Structure
 
19
 
20
  ## Dataset Description
21
 
22
+ This dataset contains 239 problems across two categories:
23
+ - **Algorithmic**: 173 competitive programming problems with automated judging
24
  - **Research**: 66 open-ended research problems
25
 
26
  ## Dataset Structure
data/test-00000-of-00001.json CHANGED
@@ -119,6 +119,7 @@
119
  {"problem_id": "257", "category": "algorithmic", "statement": "Problem: Omkar and Modes\n\nTime limit: 3 seconds\n\nMemory limit: 256 MB\n\nThis is an interactive problem.\n\nRay lost his array and needs to find it by asking Omkar. Omkar is willing to disclose that the array has the following qualities:\n1. The array has n (1 <= n <= 2 * 10^5) elements.\n2. Every element in the array a_i is an integer in the range 1 <= a_i <= 10^9.\n3. The array is sorted in nondecreasing order.\n\nRay is allowed to send Omkar a series of queries. A query consists of two integers, l and r such that 1 <= l <= r <= n. Omkar will respond with two integers, x and f.\n- x is the mode of the subarray from index l to index r inclusive. The mode of an array is defined by the number that appears the most frequently. If there are multiple numbers that appear the most number of times, the smallest such number is considered to be the mode.\n- f is the amount of times that x appears in the queried subarray.\n\nThe array has k (1 <= k <= min(25000, n)) distinct elements. However, due to Ray's sins, Omkar will not tell Ray what k is.\n\nHelp Ray find his lost array.\n\nInput\n\nThe only line of the input contains a single integer n (1 <= n <= 2 * 10^5), which equals to the length of the array that you are trying to find.\n\nInteraction Protocol\n\nThe interaction starts with reading n.\n\nThen you can make one type of query:\n\"? l r\" (without quotes) (1 <= l <= r <= n) where l and r are the bounds of the subarray that you wish to query.\n\nThe answer to each query will be in the form \"x f\" where x is the mode of the subarray and f is the number of times x appears in the subarray.\nx satisfies (1 <= x <= 10^9).\nf satisfies (1 <= f <= r - l + 1).\n\nIf you make an invalid query (violating ranges), you will get an output \"-1\". If you terminate after receiving the response \"-1\", you will get the \"Wrong answer\" verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.\n\nTo output your answer, print:\n\"! a_1 a_2 ... a_n\" (without quotes) which is an exclamation point followed by the array with a space between every element. And quit after that. This query is not counted towards the query limit.\n\nAfter printing a query do not forget to output end of line and flush the output.\nOtherwise, you will get Idleness limit exceeded. To do this, use:\n- fflush(stdout) or cout.flush() in C++;\n- System.out.flush() in Java;\n- flush(output) in Pascal;\n- stdout.flush() in Python;\n- see documentation for other languages.\n\nScoring\n\nYour score depends on the number of queries Q you use to find the array. Fewer queries give higher score.\n\nExample Input:\n6\n2 2\n2 2\n3 2\n2 1\n\nExample Output:\n? 1 6\n? 1 3\n? 4 6\n? 3 4\n! 1 1 2 3 3 4", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cc\n\n# Time and memory limits still apply to the contestant's solution\ntime: 3s\nmemory: 256m\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"}
120
  {"problem_id": "258", "category": "algorithmic", "statement": "Problem: Network Synchronization: Finding Dual Anomalies\n\nThis is an interactive task.\n\n[Background]\nYou are managing a distributed network consisting of $n$ server nodes, indexed from 1 to $n$. The network is structured as a tree (a connected graph with $n-1$ edges and no cycles). Two specific, distinct nodes in this network have been flagged as \"Anomaly Points.\" Your mission is to identify the exact indices of these two nodes.\n\nThe distance between any two nodes $u$ and $v$ is the number of connections (edges) in the unique simple path between them.\n\n[The Probing Protocol]\nTo locate the anomalies, you can perform a series of probes. In each probe:\n1. You provide a list of candidate nodes $\\{a_1, a_2, \\dots, a_c\\}$.\n2. The system evaluates the \"Total Latency\" for each node in your list. The Total Latency of a node is the sum of its distances to the two hidden Anomaly Points.\n3. The system returns two values:\n - The index of a node $a_i$ from your list that has the minimum Total Latency. If multiple nodes share the same minimum latency, any one of them may be returned.\n - The value of that minimum Total Latency.\n\n[Input Format]\n- The first line contains an integer $t$ ($1 \\le t \\le 10$), the number of test cases.\n- For each test case:\n - The first line contains $n$ ($2 \\le n \\le 1000$), the number of nodes.\n - The next $n-1$ lines each contain two integers $u$ and $v$, representing a direct connection between those nodes.\n\n[Interaction Steps]\n1. Query: Print \"? c\" followed by $c$ space-separated node indices.\n2. Response: Read two integers $x$ (the selected node) and $d$ (the total latency).\n - If you receive $x = -1$ and $d = -1$, your query limit is exceeded or the query was invalid. Terminate immediately.\n3. Guess: When you have identified the anomalies, print \"!\" followed by the two node indices in any order.\n4. Feedback: Read a single string. \n - If it is \"Correct\", move to the next test case or exit.\n - If it is \"Incorrect\", terminate immediately.\n\n[Technical Requirements]\n- You must flush the output stream after every query to receive a response.\n- In C++, use `cout.flush()` or `fflush(stdout)`.\n- In Python, use `sys.stdout.flush()`.\n- Your goal is to find the anomalies using as few queries as possible to achieve a high efficiency score.\n\n[Interaction Example]\n(System) 1\n(System) 3\n(System) 1 2\n(System) 1 3\n(User) ? 1 1\n(System) 1 2\n(User) ? 1 2\n(System) 2 3\n(User) ? 1 3\n(System) 3 1\n(User) ! 1 3\n(System) Correct", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cc\n\n# Time and memory limits still apply to the contestant's solution\ntime: 2s\nmemory: 256m\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"}
121
  {"problem_id": "26", "category": "algorithmic", "statement": "OgreSort\n\nYou need to sort a permutation v of length n. All elements of the permutation are indexed from 1 to n.\nThe only permitted type of move allows you to take an element from some position x and insert it at\nanother position y, shifting all elements in between by one. The cost of such a move is y.\nFormally, a move takes an element valued t from position x, “freeing” the index x. We then shift the\nremaining elements in v, such that the “free” position becomes y. We then put t in the free position at\nindex y.\nFor example, if we have a permutation [4, 3, 2, 1], some of the possible moves:\n• x = 2, y = 4, the resulting permutation is [4, 2, 1, 3], the cost of the move is 4.\n• x = 2, y = 1, the resulting permutation is [3, 4, 2, 1], the cost of the move is 1.\nThe final cost is computed as (total cost + 1) * (number of moves + 1). You need to minimize the final cost.\n\nInput\nThe first line contains an integer n — the length of the permutation.\nThe second line contains n integers v1, v2, . . . , vn — the values of the permutation.\n\nConstraints\n1 <= n <= 3 * 10^5\n1 <= vi <= n,\nvi != vj for all 1 <= i < j <= n.\n\nOutput\nOn the first line, print two numbers min_cost and len_moves — the minimum final cost needed to sort the\npermutation and the length of the proposed sequence of moves respectively.\nThe next len_moves lines should each contain two integers xk, yk each, signifying that the k-th operation\nshould move the element from position xk to position yk (1 ≤ k ≤ len_moves, 1 <= xk, yk <= n).\nIf several possible sequences of moves exist, you can print any of them.\n\nScoring \nYou will be graded based on the final costs you give. \nTo be more specific, your answer will be compared to a solution best_answer.\nYour final score will be calculated as the average of 100 * min(best_answer / your_answer, 1) across all cases.\n\nTime limit: 2 seconds\n\nMemoriy limit: 512 MB\n\nSample input:\n5\n2 4 1 3 5\nSample Output:\n12 2\n4 2\n4 1\nSample Explanation: \nThe total cost is (2 + 1) = 3, and the number of moves is 2. Thus the final cost is (3 + 1) * (2 + 1) = 12.\n\n", "config": "type: default\ntime: 2s\nmemory: 512m\nchecker: chk.cc\nsubtasks:\n - score: 100\n n_cases: 3"}
 
122
  {"problem_id": "27", "category": "algorithmic", "statement": "# Problem\n\nYou 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.\n\nFormally, 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.\n\n## Input\nA single line with two integers n and m (1 ≤ n, m and n · m ≤ 100000).\n\n## Output\nPrint:\n- The first line: an integer k — the number of black points you place (0 ≤ k ≤ n · m).\n- 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.\n\nAll listed pairs must be distinct. You may print the points in any order.\n\n## Goal\nMaximize k subject to the validity constraint (no axis-parallel rectangle formed by four chosen points).\n\n## Scoring\nLet k be the number of points you output, and let U(n, m) be the theoretical upper bound we use for this problem:\nU(n, m) = floor(min(n · sqrt(m) + m, m · sqrt(n) + n, n · m)).\n\nYour score for a test is:\nscore = 100 × min(k / U(n, m), 1).\n\n- Achieving the upper bound U(n, m) yields a score of 100.\n- Outputting 0 points yields a score of 0.\n- Invalid outputs (out-of-range coordinates, duplicates, or violating the rectangle constraint) receive a score of 0 for that test.\nYour final score is the average over all tests.\n\n## Time limit\n1 second\n\n## Memory limit\n512 MB\n\n## Sample\nInput\n2 2\n\nOutput\n3\n1 1\n1 2\n2 1\n\n(The sample illustrates the format and a valid solution; for a 2×2 grid, 3 is optimal under the given constraint.)\n\n", "config": "type: default\n# The time limit is now 1 second.\ntime: 1s\nmemory: 512m\n# A custom checker is required for the special scoring.\nchecker: chk.cc\nsubtasks:\n - score: 100\n n_cases: 3"}
123
  {"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"}
124
  {"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"}
 
119
  {"problem_id": "257", "category": "algorithmic", "statement": "Problem: Omkar and Modes\n\nTime limit: 3 seconds\n\nMemory limit: 256 MB\n\nThis is an interactive problem.\n\nRay lost his array and needs to find it by asking Omkar. Omkar is willing to disclose that the array has the following qualities:\n1. The array has n (1 <= n <= 2 * 10^5) elements.\n2. Every element in the array a_i is an integer in the range 1 <= a_i <= 10^9.\n3. The array is sorted in nondecreasing order.\n\nRay is allowed to send Omkar a series of queries. A query consists of two integers, l and r such that 1 <= l <= r <= n. Omkar will respond with two integers, x and f.\n- x is the mode of the subarray from index l to index r inclusive. The mode of an array is defined by the number that appears the most frequently. If there are multiple numbers that appear the most number of times, the smallest such number is considered to be the mode.\n- f is the amount of times that x appears in the queried subarray.\n\nThe array has k (1 <= k <= min(25000, n)) distinct elements. However, due to Ray's sins, Omkar will not tell Ray what k is.\n\nHelp Ray find his lost array.\n\nInput\n\nThe only line of the input contains a single integer n (1 <= n <= 2 * 10^5), which equals to the length of the array that you are trying to find.\n\nInteraction Protocol\n\nThe interaction starts with reading n.\n\nThen you can make one type of query:\n\"? l r\" (without quotes) (1 <= l <= r <= n) where l and r are the bounds of the subarray that you wish to query.\n\nThe answer to each query will be in the form \"x f\" where x is the mode of the subarray and f is the number of times x appears in the subarray.\nx satisfies (1 <= x <= 10^9).\nf satisfies (1 <= f <= r - l + 1).\n\nIf you make an invalid query (violating ranges), you will get an output \"-1\". If you terminate after receiving the response \"-1\", you will get the \"Wrong answer\" verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.\n\nTo output your answer, print:\n\"! a_1 a_2 ... a_n\" (without quotes) which is an exclamation point followed by the array with a space between every element. And quit after that. This query is not counted towards the query limit.\n\nAfter printing a query do not forget to output end of line and flush the output.\nOtherwise, you will get Idleness limit exceeded. To do this, use:\n- fflush(stdout) or cout.flush() in C++;\n- System.out.flush() in Java;\n- flush(output) in Pascal;\n- stdout.flush() in Python;\n- see documentation for other languages.\n\nScoring\n\nYour score depends on the number of queries Q you use to find the array. Fewer queries give higher score.\n\nExample Input:\n6\n2 2\n2 2\n3 2\n2 1\n\nExample Output:\n? 1 6\n? 1 3\n? 4 6\n? 3 4\n! 1 1 2 3 3 4", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cc\n\n# Time and memory limits still apply to the contestant's solution\ntime: 3s\nmemory: 256m\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"}
120
  {"problem_id": "258", "category": "algorithmic", "statement": "Problem: Network Synchronization: Finding Dual Anomalies\n\nThis is an interactive task.\n\n[Background]\nYou are managing a distributed network consisting of $n$ server nodes, indexed from 1 to $n$. The network is structured as a tree (a connected graph with $n-1$ edges and no cycles). Two specific, distinct nodes in this network have been flagged as \"Anomaly Points.\" Your mission is to identify the exact indices of these two nodes.\n\nThe distance between any two nodes $u$ and $v$ is the number of connections (edges) in the unique simple path between them.\n\n[The Probing Protocol]\nTo locate the anomalies, you can perform a series of probes. In each probe:\n1. You provide a list of candidate nodes $\\{a_1, a_2, \\dots, a_c\\}$.\n2. The system evaluates the \"Total Latency\" for each node in your list. The Total Latency of a node is the sum of its distances to the two hidden Anomaly Points.\n3. The system returns two values:\n - The index of a node $a_i$ from your list that has the minimum Total Latency. If multiple nodes share the same minimum latency, any one of them may be returned.\n - The value of that minimum Total Latency.\n\n[Input Format]\n- The first line contains an integer $t$ ($1 \\le t \\le 10$), the number of test cases.\n- For each test case:\n - The first line contains $n$ ($2 \\le n \\le 1000$), the number of nodes.\n - The next $n-1$ lines each contain two integers $u$ and $v$, representing a direct connection between those nodes.\n\n[Interaction Steps]\n1. Query: Print \"? c\" followed by $c$ space-separated node indices.\n2. Response: Read two integers $x$ (the selected node) and $d$ (the total latency).\n - If you receive $x = -1$ and $d = -1$, your query limit is exceeded or the query was invalid. Terminate immediately.\n3. Guess: When you have identified the anomalies, print \"!\" followed by the two node indices in any order.\n4. Feedback: Read a single string. \n - If it is \"Correct\", move to the next test case or exit.\n - If it is \"Incorrect\", terminate immediately.\n\n[Technical Requirements]\n- You must flush the output stream after every query to receive a response.\n- In C++, use `cout.flush()` or `fflush(stdout)`.\n- In Python, use `sys.stdout.flush()`.\n- Your goal is to find the anomalies using as few queries as possible to achieve a high efficiency score.\n\n[Interaction Example]\n(System) 1\n(System) 3\n(System) 1 2\n(System) 1 3\n(User) ? 1 1\n(System) 1 2\n(User) ? 1 2\n(System) 2 3\n(User) ? 1 3\n(System) 3 1\n(User) ! 1 3\n(System) Correct", "config": "# Set the problem type to interactive\ntype: interactive\n\n# Specify the interactor source file\ninteractor: interactor.cc\n\n# Time and memory limits still apply to the contestant's solution\ntime: 2s\nmemory: 256m\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"}
121
  {"problem_id": "26", "category": "algorithmic", "statement": "OgreSort\n\nYou need to sort a permutation v of length n. All elements of the permutation are indexed from 1 to n.\nThe only permitted type of move allows you to take an element from some position x and insert it at\nanother position y, shifting all elements in between by one. The cost of such a move is y.\nFormally, a move takes an element valued t from position x, “freeing” the index x. We then shift the\nremaining elements in v, such that the “free” position becomes y. We then put t in the free position at\nindex y.\nFor example, if we have a permutation [4, 3, 2, 1], some of the possible moves:\n• x = 2, y = 4, the resulting permutation is [4, 2, 1, 3], the cost of the move is 4.\n• x = 2, y = 1, the resulting permutation is [3, 4, 2, 1], the cost of the move is 1.\nThe final cost is computed as (total cost + 1) * (number of moves + 1). You need to minimize the final cost.\n\nInput\nThe first line contains an integer n — the length of the permutation.\nThe second line contains n integers v1, v2, . . . , vn — the values of the permutation.\n\nConstraints\n1 <= n <= 3 * 10^5\n1 <= vi <= n,\nvi != vj for all 1 <= i < j <= n.\n\nOutput\nOn the first line, print two numbers min_cost and len_moves — the minimum final cost needed to sort the\npermutation and the length of the proposed sequence of moves respectively.\nThe next len_moves lines should each contain two integers xk, yk each, signifying that the k-th operation\nshould move the element from position xk to position yk (1 ≤ k ≤ len_moves, 1 <= xk, yk <= n).\nIf several possible sequences of moves exist, you can print any of them.\n\nScoring \nYou will be graded based on the final costs you give. \nTo be more specific, your answer will be compared to a solution best_answer.\nYour final score will be calculated as the average of 100 * min(best_answer / your_answer, 1) across all cases.\n\nTime limit: 2 seconds\n\nMemoriy limit: 512 MB\n\nSample input:\n5\n2 4 1 3 5\nSample Output:\n12 2\n4 2\n4 1\nSample Explanation: \nThe total cost is (2 + 1) = 3, and the number of moves is 2. Thus the final cost is (3 + 1) * (2 + 1) = 12.\n\n", "config": "type: default\ntime: 2s\nmemory: 512m\nchecker: chk.cc\nsubtasks:\n - score: 100\n n_cases: 3"}
122
+ {"problem_id": "263", "category": "algorithmic", "statement": "```markdown\n# Sasha’s Smudged Multiplication Poster (Optimization)\n\n## Problem\nTo learn multiplication, Big Ben printed a gigantic poster of a multiplication table created from his favorite integers collected over CALICO's 5 year history. Unfortunately the poster was damaged and now he's very sad :( Many entries were lost, and many others were corrupted. Big Ben now has only a vague memory of his favorite off diagonal cells.\n\nBig Ben is working on a new multiplication table. He doesn't expect a perfect recreation of his old one, and he's happy tolerating a few different entries. Help Big Ben pick numbers for his new multiplication table! \n\nYour task is to construct a list of $\\var{N}$ integers $a_1, a_2, \\dots, a_{\\var{N}}$, which defines a $\\var{N} \\times \\var{N}$ multiplication table where the entry at row $i$ and column $j$ is $a_i a_j$.\n\nYou are given $\\var{M}$ constraints, each consisting of:\n\\begin{itemize}\n \\item A row index $\\var{R}_i$ in the list $\\var{R}_1, \\var{R}_2, \\dots, \\var{R}_{\\var{M}}$ and a column index $\\var{C}_i$ in the list $\\var{C}_1, \\var{C}_2, \\dots, \\var{C}_{\\var{M}}$\n \\begin{itemize}\n \\item Row and indices are guaranteed to be off-diagonal, $\\var{R}_i \\ne \\var{C}_i$.\n \\end{itemize}\n \\item A value $\\var{V}_i$ in the list $\\var{V}_1, \\var{V}_2, \\dots, \\var{V}_{\\var{M}}$\n \\item A weight $\\var{W}_i$ in the list $\\var{W}_1, \\var{W}_2, \\dots, \\var{W}_{\\var{M}}$\n\\end{itemize}\n\nAdditionally, you may select a subset $S \\subseteq \\{1,2,\\dots,\\var{M}\\}$ of $d$ constraints to discard, up to $\\var{D}$.\n\n\\subsection{Input Format}\n\nEach test file describes a single test case, which contains two lines:\n\\begin{itemize}\n \\item The first line of the input contains three space-separated integers $\\var{N}$ $\\var{M}$ $\\var{D}$ denoting the size of the table, the number of observed cells, and the number of observations we can discard, respectively.\n \\item The next $\\var{M}$ lines each describe a constraint and each contain four space-separated integers $\\var{R_i}$ $\\var{C_i}$ $\\var{V_i}$ $\\var{W_i}$ denoting the row index, column index, value, and weight respectively.\n \\begin{itemize}\n \\item The given constraints are 1-indexed: the first constraint contains $\\var{R_1}$, the second contains $\\var{R_2}$, and so on.\n \\end{itemize}\n\\end{itemize}\n\nNote that multiple constraints may have the same $\\var{R_i} = \\var{R_j}$ and $\\var{C_i} = \\var{C_j}$. In these cases, both contribute to the penalty.\n\n\\subsection*{Output Format}\nFor the single test case in each test file, output two lines:\n\\begin{itemize}\n \\item The first line should contain $\\var{N}$ space separated integers, $a_0$ $a_1$ $\\dots$ $a_\\var{N}$\n \\item The second line should contain $d+1$ space separated integers denoting the number of discarded observations followed by the discarded observations themselves, $d$ $S_1$ $S_2$ $\\dots$ $S_d$\n\\end{itemize}\n\n## Objective\nFor each observation `k` not discarded, let:\n\n- `p_k = a_{uk} · a_{vk}` (computed in exact integer arithmetic; note `p_k` can be up to `10^18`)\n- **weighted relative error**\n \\[\n e_k = w_k \\cdot \\frac{|p_k - x_k|}{x_k}\n \\]\n\nYour submission’s **loss** is:\n\\[\nL = \\sum_{k \\notin \\text{discarded}} e_k\n\\]\n\nYou must **minimize** `L`.\n\n---\n\n## Scoring\nLet:\n\n- `L_sub` be your loss.\n- `L_base` be the **baseline loss**, defined deterministically as the loss obtained by:\n - outputting `ai = 1` for all `i`,\n - discarding `t = 0` observations.\n\nThe per-instance score is:\n\\[\nS = 10^6 \\cdot \\text{clamp}\\left(\\frac{L_{base} - L_{sub}}{L_{base} - L_{ref}},\\ 0,\\ 1\\right)\n\\]\nwhere `clamp(z,0,1) = min(1, max(0, z))`.\n\nNotes:\n- `L_ref` is provided in the input and satisfies `0 < L_ref < L_base`.\n- Achieving `L_sub = L_ref` gives full score `1,000,000`.\n- Doing worse than baseline gives score `0`.\n- The final contest score is the **sum of S** over all test instances.\n\nAll computations for judging use high-precision floating point; ties are broken by smaller `L_sub`.\n\n---\n\nTime Limit: \\textbf{10 Seconds}\n\n\\subsubsection{Input Constraints}\n\n$1 \\leq \\var{N} \\leq 4 \\cdot 10^{3}$ \\\\\n$1 \\leq \\var{M} \\leq 2 \\cdot 10^6$ \\\\\n$0 \\leq \\var{D} \\leq \\var{M}$\n\n$1 \\leq \\var{R_i}, \\var{C_i} \\leq \\var{N} \\\\\n\\var{R_i} \\neq \\var{C_i}$ \\\\\n$1 \\leq \\var{V_i} \\leq 10^9$ \\\\\n$1 \\leq \\var{W_i} \\leq 10^{3}$\n\nNote that multiple constraints may have the same $\\var{R_i} = \\var{R_j}$ and $\\var{C_i} = \\var{C_j}$. In these cases, both contribute to the penalty.\n\n\\subsubsection{Output Constraints}\n\n$1 \\leq a_i \\leq 10^9$ \\\\\n$0 \\leq d \\leq \\var{D}$ \\\\\n$1 \\leq S_i \\leq \\var{M}$\n\n(Your program must be fast, but exact optimization is not expected; heuristics are essential.)\n\n---\n\n## Example\n### Sample input\n```\n4 5 1\n120.0\n1 2 6 5\n1 3 9 5\n2 3 18 2\n2 4 7 1\n3 4 12 1\n```\n\n### Sample output\n```\n3 2 6 2\n1 4\n```\n\n### Explanation (high level)\n- Proposed array: `a = [3,2,6,2]`.\n- Discard observation `#4` (at most `D=1` allowed).\n\nLoss is computed over observations {1,2,3,5}:\n- (1,2): predicted 3·2=6, matches x=6 → error 0\n- (1,3): 3·6=18 vs 9 → contributes `5*|18-9|/9 = 5`\n- (2,3): 2·6=12 vs 18 → contributes `2*|12-18|/18 = 0.666...`\n- (3,4): 6·2=12 vs 12 → error 0\n\nTotal `L_sub = 5.666...`. The judge computes `L_base` from all-ones with no discards, then applies the scoring formula using the given `L_ref`.\n```", "config": "checker: chk.cc\nmemory: 256m\nsubtasks:\n- n_cases: 10\n score: 100\ntime: 10s\ntype: default\n"}
123
  {"problem_id": "27", "category": "algorithmic", "statement": "# Problem\n\nYou 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.\n\nFormally, 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.\n\n## Input\nA single line with two integers n and m (1 ≤ n, m and n · m ≤ 100000).\n\n## Output\nPrint:\n- The first line: an integer k — the number of black points you place (0 ≤ k ≤ n · m).\n- 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.\n\nAll listed pairs must be distinct. You may print the points in any order.\n\n## Goal\nMaximize k subject to the validity constraint (no axis-parallel rectangle formed by four chosen points).\n\n## Scoring\nLet k be the number of points you output, and let U(n, m) be the theoretical upper bound we use for this problem:\nU(n, m) = floor(min(n · sqrt(m) + m, m · sqrt(n) + n, n · m)).\n\nYour score for a test is:\nscore = 100 × min(k / U(n, m), 1).\n\n- Achieving the upper bound U(n, m) yields a score of 100.\n- Outputting 0 points yields a score of 0.\n- Invalid outputs (out-of-range coordinates, duplicates, or violating the rectangle constraint) receive a score of 0 for that test.\nYour final score is the average over all tests.\n\n## Time limit\n1 second\n\n## Memory limit\n512 MB\n\n## Sample\nInput\n2 2\n\nOutput\n3\n1 1\n1 2\n2 1\n\n(The sample illustrates the format and a valid solution; for a 2×2 grid, 3 is optimal under the given constraint.)\n\n", "config": "type: default\n# The time limit is now 1 second.\ntime: 1s\nmemory: 512m\n# A custom checker is required for the special scoring.\nchecker: chk.cc\nsubtasks:\n - score: 100\n n_cases: 3"}
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"}