|
Download misc/misc-0161.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 4.39 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/misc/misc-0161.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm@b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/misc/misc-0161.jsonl
-
curl -L -o misc-0161.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/misc/misc-0161.jsonl
4.39 kB
| {"type": "session", "harness": "opencode", "id": "misc-0161", "name": "Competitive Programming"} | |
| {"type": "message", "message": {"role": "system", "content": "You are an expert competitive programmer. You solve problems by analyzing requirements, designing algorithms, and writing clean, efficient code. When solving problems, explain your reasoning step by step before providing the final solution."}} | |
| {"type": "message", "message": {"role": "user", "content": "**Note: The time limit for this problem is 4s, twice the default.**\nBessie is on vacation! Due to some recent technological advances, Bessie will\ntravel via technologically sophisticated flights, which can even time travel.\nFurthermore, there are no issues if two \"parallel\" versions of Bessie ever meet.\n\nIn the country there are $N$ airports numbered $1, 2, \\ldots, N$ and $M$\ntime-traveling flights ($1\\leq N, M \\leq 200000$). Flight $j$ leaves airport\n$c_j$ at time $r_j$, and arrives in airport $d_j$ at time $s_j$ \n($0 \\leq r_j, s_j \\leq 10^9$, $s_j < r_j$ is possible). In addition, she must\nleave $a_i$ time for a layover at airport $i$\n($1\\le a_i\\le 10^9$).\n(That is to say, if Bessie takes a flight arriving in airport $i$ at time $s$,\nshe can then transfer to a flight leaving the airport at time $r$ if\n$r \\geq s + a_i$. The layovers do not affect when Bessie arrives at an airport.)\n\nBessie starts at city $1$ at time $0$. For each airport from $1$ to $N$, what is\nthe earliest time when Bessie can get to at it?\n\nINPUT FORMAT (input arrives from the terminal / stdin):\nThe first line of input contains $N$ and $M$.\n\nThe next $M$ lines describe flights. The $j$th of these lines contains $c_j$,\n$r_j$, $d_j$, $s_j$ in that order. ($1\\leq c_j, d_j \\leq N$,\n$0\\leq r_j, s_j \\leq 10^9$)\n\nThe next line describes airports. It contains $N$ space separated integers,\n$a_1, \\ldots, a_N$.\n\nOUTPUT FORMAT (print output to the terminal / stdout):\nThere are $N$ lines of output. Line $i$ contains the earliest time when Bessie\ncan get to airport $i$, or -1 if it is not possible for Bessie to get to that\nairport.\n\nSAMPLE INPUT:\n3 3\n1 0 2 10\n2 11 2 0\n2 1 3 20\n10 1 10\nSAMPLE OUTPUT: \n0\n0\n20\n\nBessie can take the 3 flights in the listed order, which allows her to arrive at\nairports 1 and 2 at time 0, and airport 3 at time 20.\n\nNote that this route passes through airport 2 twice, first from time 10-11 and\nthen from time 0-1.\n\nSAMPLE INPUT:\n3 3\n1 0 2 10\n2 10 2 0\n2 1 3 20\n10 1 10\nSAMPLE OUTPUT: \n0\n10\n-1\n\nIn this case, Bessie can take flight 1, arriving at airport 2 at time 10.\nHowever, she does not arrive in time to also take flight 2, since the departure\ntime is 10 and she cannot make a 1 time-unit layover.\n\nSCORING:\nInputs 3-5: $r_j < s_j$ for all $j$, i.e. all flights arrive after they\ndepart.Inputs 6-10: $N, M \\leq 5000$Inputs 11-20: No additional constraints.\n\n\nProblem credits: Brandon Wang"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "import sys\nimport heapq\n\ndef main():\n sys.setrecursionlimit(1 << 25)\n N, M = map(int, sys.stdin.readline().split())\n adj = [[] for _ in range(N+1)] # 1-based indexing\n for _ in range(M):\n c_j, r_j, d_j, s_j = map(int, sys.stdin.readline().split())\n adj[c_j].append((r_j, s_j, d_j))\n \n a_list = list(map(int, sys.stdin.readline().split()))\n a = [0] * (N + 1)\n for i in range(1, N+1):\n a[i] = a_list[i-1]\n \n INF = 10**18\n dist = [INF] * (N + 1)\n dist[1] = 0\n heap = []\n heapq.heappush(heap, (0, 1))\n \n while heap:\n current_time, u = heapq.heappop(heap)\n if current_time > dist[u]:\n continue\n for flight in adj[u]:\n r_j, s_j, d_j = flight\n # Compute required departure time\n if u == 1 and current_time == 0:\n required = 0\n else:\n required = current_time + a[u]\n if required <= r_j:\n new_time = s_j\n if new_time < dist[d_j]:\n dist[d_j] = new_time\n heapq.heappush(heap, (new_time, d_j))\n \n for i in range(1, N+1):\n if dist[i] == INF:\n print(-1)\n else:\n print(dist[i])\n\nif __name__ == \"__main__\":\n main()"}} | |