Item 1·0% solve rate
Beautiful Path
There is a directed graph with N vertices and M edges. Each edge has two positive integer values: beauty and cost.
For i = 1, 2, \ldots, M, the i-th edge is directed from vertex u_i to vertex v_i, with beauty b_i and cost c_i.
Here, the constraints guarantee that u_i \lt v_i.
Find the maximum value of the following for a path P from vertex 1 to vertex N.
- The total beauty of all edges on P divided by the total cost of all edges on P.
Here, the constraints guarantee that the given graph has at least one path from vertex 1 to vertex N.
Input
The input is given from Standard Input in the following format:
N M
u_1 v_1 b_1 c_1
u_2 v_2 b_2 c_2
\vdots
u_M v_M b_M c_M
Output
Print the answer. Your output will be judged as correct if the relative or absolute error from the true answer is at most 10^{-9}.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq M \leq 2 \times 10^5
- 1 \leq u_i \lt v_i \leq N
- 1 \leq b_i, c_i \leq 10^4
- There is a path from vertex 1 to vertex N.
- All input values are integers.
Sample Input 1
5 7
1 2 3 6
1 3 9 5
2 3 1 5
2 4 5 3
2 5 1 9
3 …How subjects answered
AzeroGPT-64bscore 0
```python
from heapq import heappush, heappop
N, M = map(int, input().split())
edges = [[] for _ in range(N)]
for _ in range(M):
u, v, b, c = map(int, input().split())
edges[u-1].append((v-1, b, c))
def dijkstra(start, edges, N):
"""
:param int start: The starting node
:param list edges: Graph represented as an adjacency list
:param int N: Number of nodes
:return:
"""
dp = [float('inf')] * N
dp[start] = 0
queue = [(0, start)]
while queue:
cost, current = heappop(queue)
if dp[current] < cost:
continue
for neig …
Kimi-k1.6-IOIscore 0
1. **Binary Search on Ratio**: We use binary search to determine the maximum possible ratio. The key insight is that if we can find a path where the sum of (beauty - X * cost) for each edge is non-negative, then X is a feasible ratio. By adjusting X using binary search, we can efficiently narrow down the maximum feasible value.
2. **DAG Topological Order**: Since the graph is a DAG with edges only from lower-numbered to higher-numbered vertices, we can process vertices in topological order (1 to N). This allows us to compute the maximum sum of (beauty - X * cost) efficiently using dynamic prog …
DeepSeek-V3score 0
```python
import sys
import heapq
def main():
N, M = map(int, sys.stdin.readline().split())
edges = [[] for _ in range(N+1)]
for _ in range(M):
u, v, b, c = map(int, sys.stdin.readline().split())
edges[u].append((v, b, c))
def can_achieve(ratio):
dist = [float('-inf')] * (N+1)
dist[1] = 0
heap = []
heapq.heappush(heap, (-dist[1], 1))
while heap:
current_dist, u = heapq.heappop(heap)
current_dist = -current_dist
if u == N:
return True
if current_dist < di …
Item 2·16% solve rate
Ideal Holidays
In the Kingdom of AtCoder, a week consists of A+B days, with the first through A-th days being holidays and the (A+1)-th through (A+B)-th being weekdays.
Takahashi has N plans, and the i-th plan is scheduled D_i days later.
He has forgotten what day of the week it is today. Determine if it is possible for all of his N plans to be scheduled on holidays.
Input
The input is given from Standard Input in the following format:
N A B
D_1 D_2 \ldots D_N
Output
Print Yes in a single line if it is possible for all of Takahashi's N plans to be scheduled on holidays, and No otherwise.
Constraints
- 1\leq N\leq 2\times 10^5
- 1\leq A,B\leq 10^9
- 1\leq D_1<D_2<\ldots<D_N\leq 10^9
Sample Input 1
3 2 5
1 2 9
Sample Output 1
Yes
In this input, a week consists of seven days, with the first through second days being holidays and the third through seventh days being weekdays.
Let us assume today is the seventh day of the week. In this case, one day later would be the first day of the week, two days later would be the second day of the week, and nine days later would also be t …
How subjects answered
gemini-2.5-proscore 1
O3-Mini-2025-01-31 (Low)score 1
```python
def main():
import sys
data = sys.stdin.read().split()
if not data:
return
it = iter(data)
n = int(next(it))
A = int(next(it))
B = int(next(it))
T = A + B
# Read D_i values and compute each D_i mod (A+B)
D = [int(next(it)) for _ in range(n)]
r = [d % T for d in D]
r.sort()
# We now have a set of mod values on a circle of length T.
# The problem becomes: is there a way (a shift of the circle, i.e. choosing today)
# so that every (d + today shift) mod T falls in [0, A)?
# This is equivalent to: Do all our r va …
EXAONE-4.0-32Bscore 0
To solve this problem, we need to determine if there exists a day `x` (modulo `A+B`) such that all of Takahashi's plans, scheduled `D_i` days later, fall on holidays. The holidays are the first `A` days of a week that consists of `A+B` days.
### Approach
1. **Problem Analysis**: The key observation is that for each plan `i`, the day of the week it falls on is `(x + D_i) mod (A+B)`. This day must be within the range `[0, A-1]` (holidays).
2. **Transformation**: For each `D_i`, we compute the interval of `x` values (modulo `A+B`) that satisfy `(x + D_i) mod (A+B) < A`. This translates to `x` b …
Item 3·32% solve rate
K
You are given three integer sequences of length N, namely A=(A_1,A_2,\ldots,A_N), B=(B_1,B_2,\ldots,B_N), and C=(C_1,C_2,\ldots,C_N), and an integer K.
For each of the N^3 choices of integers i,j,k (1\leq i,j,k\leq N), compute the value A_iB_j + B_jC_k + C_kA_i. Among all these values, find the K-th largest value.
Input
The input is given from Standard Input in the following format:
N K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_N
C_1 C_2 \ldots C_N
Output
Print the answer.
Constraints
- 1\leq N \leq 2\times 10^5
- 1\leq K \leq \min(N^3,5\times 10^5)
- 1\leq A_i,B_i,C_i \leq 10^9
- All input values are integers.
Sample Input 1
2 5
1 2
3 4
5 6
Sample Output 1
31
The N^3=8 values are computed as follows:
- For (i,j,k)=(1,1,1): A_1B_1+B_1C_1+C_1A_1=1\times 3+3\times 5+5\times 1=23
- For (i,j,k)=(1,1,2): A_1B_1+B_1C_2+C_2A_1=1\times 3+3\times 6+6\times 1=27
- For (i,j,k)=(1,2,1): A_1B_2+B_2C_1+C_1A_1=1\times 4+4\times 5+5\times 1=29
- For (i,j,k)=(1,2,2): A_1B_2+B_2C_2+C_2A_1=1\times 4+4\times 6+6\times 1=34
- For (i,j,k)=(2,1,1): A_2B_1+B_1C_1+C_1A_2=2\times 3+3\times 5+5\times …
How subjects answered
deepseek-r1-0528score 1
To solve this problem, we need to find the K-th largest value among all possible triplets (i, j, k) from three given arrays A, B, and C, where the value is computed as \(A_i \times B_j + B_j \times C_k + C_k \times A_i\). Given the constraints where \(N\) can be as large as \(2 \times 10^5\) and \(K\) up to \(5 \times 10^5\), a brute-force approach is infeasible. Instead, we use a priority queue (max-heap) to efficiently explore the largest values without generating all possible triplets.
### Approach
1. **Sorting the Arrays**: First, we sort the three arrays in descending order. This allows …
DeepSeek-V3score 0
To solve this problem, we need to find the K-th largest value among all possible combinations of the form \(A_iB_j + B_jC_k + C_kA_i\) for \(1 \leq i, j, k \leq N\). Given the constraints where \(N\) can be as large as \(2 \times 10^5\), a brute-force approach of enumerating all \(N^3\) combinations is infeasible. Instead, we need an efficient algorithm to find the K-th largest value without explicitly generating all possible values.
### Approach
1. **Understanding the Expression**: The expression \(A_iB_j + B_jC_k + C_kA_i\) can be rewritten as \(B_j(A_i + C_k) + C_kA_i\). However, this does …
gpt-4-turbo-2024-04-09score 0
```python
import sys
import heapq
input = sys.stdin.read
data = input().split()
N = int(data[0])
K = int(data[1])
A = list(map(int, data[2:2+N]))
B = list(map(int, data[2+N:2+2*N]))
C = list(map(int, data[2+2*N:2+3*N]))
# We will use a max-heap to keep track of the top K elements
max_heap = []
# Compute all possible values of A_iB_j + B_jC_k + C_kA_i
for i in range(N):
for j in range(N):
for k in range(N):
value = A[i] * B[j] + B[j] * C[k] + C[k] * A[i]
# Use a min-heap by pushing negative values
if len(max_heap) < K:
heapq.h …
Item 4·55% solve rate
largest-element-in-an-array-after-merge-operations
You are given a 0-indexed array nums consisting of positive integers.
You can do the following operation on the array any number of times:
Choose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i + 1]. Replace the element nums[i + 1] with nums[i] + nums[i + 1] and delete the element nums[i] from the array.
Return the value of the largest element that you can possibly obtain in the final array.
Example 1:
Input: nums = [2,3,7,9,3]
Output: 21
Explanation: We can apply the following operations on the array:
- Choose i = 0. The resulting array will be nums = [5,7,9,3].
- Choose i = 1. The resulting array will be nums = [5,16,3].
- Choose i = 0. The resulting array will be nums = [21,3].
The largest element in the final array is 21. It can be shown that we cannot obtain a larger element.
Example 2:
Input: nums = [5,3,3]
Output: 11
Explanation: We can do the following operations on the array:
- Choose i = 1. The resulting array will be nums = [5,6].
- Choose i = 0. The resulting array will be nums = [11].
There i …
How subjects answered
gpt-4o-mini-2024-07-18score 1
```python
class Solution:
def maxArrayValue(self, nums: List[int]) -> int:
max_value = nums[-1]
current_sum = nums[-1]
for i in range(len(nums) - 2, -1, -1):
if nums[i] <= current_sum:
current_sum += nums[i]
else:
current_sum = nums[i]
return current_sum
```
Gemini-Pro-1.5-002score 1
```python
class Solution:
def maxArrayValue(self, nums: List[int]) -> int:
n = len(nums)
res = nums[n - 1]
for i in range(n - 2, -1, -1):
if nums[i] <= res:
res += nums[i]
else:
res = nums[i]
return res
```
DSCoder-33b-Insscore 0
```python
class Solution:
def maxArrayValue(self, nums: List[int]) -> int:
nums.reverse()
max_val = nums[0]
for i in range(1, len(nums)):
if nums[i] >= max_val:
max_val = nums[i]
else:
max_val = max(max_val, nums[i-1] + nums[i])
return max_val
```
Item 5·85% solve rate
extra-characters-in-a-string
You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.
Return the minimum number of extra characters left over if you break up s optimally.
Example 1:
Input: s = "leetscode", dictionary = ["leet","code","leetcode"]
Output: 1
Explanation: We can break s in two substrings: "leet" from index 0 to 3 and "code" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.
Example 2:
Input: s = "sayhelloworld", dictionary = ["hello","world"]
Output: 3
Explanation: We can break s in two substrings: "hello" from index 3 to 7 and "world" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3.
Constraints:
1 <= s.length <= 50
1 <= dictionary.length <= 50
1 <= dictionary[i].length <= 50
dictionary[i] and s consists of only lower …
How subjects answered
gpt-4o-mini-2024-07-18score 1
```python
class Solution:
def minExtraChar(self, s: str, dictionary: list[str]) -> int:
word_set = set(dictionary)
n = len(s)
# dp[i] will store the minimum extra characters for s[:i]
dp = [0] * (n + 1)
for i in range(1, n + 1):
# Start by assuming the worst case: all characters up to i are extra
dp[i] = dp[i - 1] + 1
# Check all possible substrings ending at i
for j in range(i):
if s[j:i] in word_set:
dp[i] = min(dp[i], dp[j]) # Update …
Mistral-Largescore 1
```python
from typing import List
class Solution:
def minExtraChar(self, s: str, dictionary: List[str]) -> int:
n = len(s)
dictionary_set = set(dictionary)
dp = [0] * (n + 1)
for i in range(1, n + 1):
dp[i] = dp[i - 1] + 1
for j in range(i):
if s[j:i] in dictionary_set:
dp[i] = min(dp[i], dp[j])
return dp[n]
```
### Explanation:
1. **Initialization**:
- Convert the `dictionary` list to a set `dictionary_set` for O(1) average-time complexity checks.
- Initialize a `dp` array where ` …
DSCoder-1.3b-Insscore 0
```python
class Solution:
def minExtraChar(self, s: str, dictionary: List[str]) -> int:
# Create a set from the dictionary for faster lookup
dictionary_set = set(dictionary)
# Initialize the memoization table
memo = [-1] * len(s)
def dp(i: int) -> int:
# Base case
if i == len(s):
return 0
# If the result is already computed, return it
if memo[i] != -1:
return memo[i]
# Try to match the substring from i to the end
for j in range(i, len(s)): …
Item 6·100% solve rate
Penalty Kick
Takahashi will have N penalty kicks in a soccer match.
For the i-th penalty kick, he will fail if i is a multiple of 3, and succeed otherwise.
Print the results of his penalty kicks.
Input
The input is given from Standard Input in the following format:
N
Output
Print a string of length N representing the results of Takahashi's penalty kicks. The i-th character (1 \leq i \leq N) should be o if Takahashi succeeds in the i-th penalty kick, and x if he fails.
Constraints
- 1 \leq N \leq 100
- All inputs are integers.
Sample Input 1
7
Sample Output 1
ooxooxo
Takahashi fails the third and sixth penalty kicks, so the third and sixth characters will be x.
Sample Input 2
9
Sample Output 2
ooxooxoox
How subjects answered
AzeroGPT-64bscore 1
```python
N = int(input())
ans = ['o' if (i+1) % 3 != 0 else 'x' for i in range(N)]
print(''.join(ans))
```
Kimi-k1.6-IOIscore 1
```python
n = int(input())
result = []
for i in range(1, n + 1):
if i % 3 == 0:
result.append('x')
else:
result.append('o')
print(''.join(result))
```
All done!
DeepSeek-V3score 1
```python
# YOUR CODE HERE
N = int(input())
result = []
for i in range(1, N+1):
if i % 3 == 0:
result.append('x')
else:
result.append('o')
print(''.join(result))
```