Submission #33887453
Source Code Expand
n, m = gets.chomp.split.map(&:to_i)
s = gets.chomp.chars
t = gets.chomp.chars
lcm = n.lcm(m)
gcd = n.gcd(m)
if gcd == 1
p s[0] == t[0] ? lcm : -1
exit
end
if n < m
shorter, longer = n, m
shorter_str, longer_str = s, t
else
shorter, longer = m, n
shorter_str, longer_str = t, s
end
(0..n - 1).each do |shorter_index|
str_index = shorter_index * (lcm / shorter)
longer_index, mod = str_index.divmod(lcm / longer)
if mod == 0 && shorter_str[shorter_index] != longer_str[longer_index]
p -1
exit
end
end
p lcm
Submission Info
| Submission Time | |
|---|---|
| Task | A - Two Abbreviations |
| User | thatblue |
| Language | Ruby (2.7.1) |
| Score | 300 |
| Code Size | 568 Byte |
| Status | AC |
| Exec Time | 93 ms |
| Memory | 24692 KiB |
Compile Error
./Main.rb:26: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample-01.txt, sample-02.txt, sample-03.txt |
| All | sample-01.txt, sample-02.txt, sample-03.txt, sample-01.txt, sample-02.txt, sample-03.txt, subtask01-01.txt, subtask01-02.txt, subtask01-03.txt, subtask01-04.txt, subtask01-05.txt, subtask01-06.txt, subtask01-07.txt, subtask01-08.txt, subtask01-09.txt, subtask01-10.txt, subtask01-11.txt, subtask01-12.txt, subtask01-13.txt, subtask01-14.txt, subtask01-15.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample-01.txt | AC | 57 ms | 14124 KiB |
| sample-02.txt | AC | 56 ms | 14120 KiB |
| sample-03.txt | AC | 57 ms | 14068 KiB |
| subtask01-01.txt | AC | 60 ms | 14352 KiB |
| subtask01-02.txt | AC | 63 ms | 17212 KiB |
| subtask01-03.txt | AC | 76 ms | 20664 KiB |
| subtask01-04.txt | AC | 85 ms | 22020 KiB |
| subtask01-05.txt | AC | 75 ms | 22332 KiB |
| subtask01-06.txt | AC | 76 ms | 21460 KiB |
| subtask01-07.txt | AC | 61 ms | 15860 KiB |
| subtask01-08.txt | AC | 69 ms | 19656 KiB |
| subtask01-09.txt | AC | 68 ms | 19876 KiB |
| subtask01-10.txt | AC | 78 ms | 22568 KiB |
| subtask01-11.txt | AC | 93 ms | 24692 KiB |
| subtask01-12.txt | AC | 87 ms | 24068 KiB |
| subtask01-13.txt | AC | 74 ms | 21380 KiB |
| subtask01-14.txt | AC | 81 ms | 22500 KiB |
| subtask01-15.txt | AC | 78 ms | 21200 KiB |