PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000057. Kinh doanh chênh lệch tiền tệ (Arbitrage)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kinh doanh chênh lệch tiền tệ (Arbitrage)
Arbitrage
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Directed exchange rates between named currencies are given. An arbitrage opportunity exists if some closed sequence of exchanges multiplies one unit of currency into strictly more than one unit. Determine whether such a sequence exists.
Input
First n; then n distinct currency names; then m; then m lines sourceCurrency exchangeRate targetCurrency.
Output
Print exactly YES if an arbitrage cycle exists, otherwise NO.
Subtasks
- Subtask 1 (40 points): . Currency names are distinct alphanumeric tokens with no spaces. Rates are positive; self-exchange is allowed.
- Subtask 2 (60 points): . Currency names are distinct alphanumeric tokens with no spaces. Rates are positive; self-exchange is allowed.
Examples
Input
3
USD
GBP
FRF
3
USD 0.50000 GBP
GBP 10.00000 FRF
FRF 0.21000 USD
Output
YES
Explanation
USD→GBP→FRF→USD has product 0.5 × 10 × 0.21 = 1.05 > 1, so arbitrage exists.