← 返回 optiver 的题目列表Detect Currency Arbitrage with a Cycle Fee
类型:online_judge
You are given n currencies and an n × n matrix of positive floating-point exchange rates:
rates[i][j]
is the amount of currency j received for one unit of currency i.
A transaction sequence starts with one currency and eventually returns to that same currency. After the complete closed sequence, a fee equal to 0.01% of the starting amount is charged; equivalently, the final amount is multiplied by 0.9999.
Determine whether an arbitrage opportunity exists: whether there is a closed exchange sequence whose amount after the fee is strictly greater than the starting amount.
Input
n
rates[0][0] rates[0][1] ... rates[0][n-1]
...
rates[n-1][0] ... rates[n-1][n-1]
All exchange rates are positive.
Output
Print:
True
if arbitrage exists; otherwise print:
False
Example
Input
2
1 0.5
2.0 1
Output
False
This formulation follows the literal wording that the fee is charged once after the entire closed sequence. If a cycle has a product greater than 1, it may be repeated enough times to overcome that fixed fee.
Example
Input
2
1 0.5
2.0 1
Output
False