Submission #24337207
Source Code Expand
(N,M),*AC = $<.map{|ln| ln.split.map(&:to_i) }
C2A = Hash.new{|h,k|h[k]=[]}
AC.each{|a,c|
C2A[c] |= [a%N]
}
C = C2A.keys.sort
if C2A[C[0]].any?{|a| a.gcd(N)<2 }
p (N-1)*C[0]
elsif AC.all?{|a,c| 1<N.gcd(a%N) }
p(-1)
else
n = d = N
p C.sum{|c|
c*C2A[c].sum{|a|
n - n = d = d.gcd(a)
}
}
end
Submission Info
| Submission Time | |
|---|---|
| Task | E - Ring MST |
| User | ds14050 |
| Language | Ruby (2.7.1) |
| Score | 500 |
| Code Size | 319 Byte |
| Status | AC |
| Exec Time | 273 ms |
| Memory | 31444 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 231 ms | 31372 KiB |
| 001.txt | AC | 240 ms | 31348 KiB |
| 002.txt | AC | 273 ms | 31244 KiB |
| 003.txt | AC | 238 ms | 31444 KiB |
| 004.txt | AC | 239 ms | 31188 KiB |
| 005.txt | AC | 183 ms | 22768 KiB |
| 006.txt | AC | 192 ms | 23068 KiB |
| 007.txt | AC | 61 ms | 14332 KiB |
| 008.txt | AC | 173 ms | 23184 KiB |
| 009.txt | AC | 184 ms | 22976 KiB |
| 010.txt | AC | 61 ms | 14076 KiB |
| 011.txt | AC | 65 ms | 14336 KiB |
| 012.txt | AC | 62 ms | 14136 KiB |
| 013.txt | AC | 58 ms | 14240 KiB |
| 014.txt | AC | 62 ms | 14192 KiB |
| 015.txt | AC | 175 ms | 24428 KiB |
| 016.txt | AC | 131 ms | 20964 KiB |
| 017.txt | AC | 109 ms | 18820 KiB |
| 018.txt | AC | 115 ms | 18652 KiB |
| 019.txt | AC | 115 ms | 18808 KiB |
| 020.txt | AC | 114 ms | 18828 KiB |
| 021.txt | AC | 105 ms | 18504 KiB |
| 022.txt | AC | 108 ms | 18564 KiB |
| 023.txt | AC | 117 ms | 18972 KiB |
| 024.txt | AC | 110 ms | 18328 KiB |
| 025.txt | AC | 227 ms | 31160 KiB |
| 026.txt | AC | 66 ms | 14288 KiB |
| 027.txt | AC | 101 ms | 18000 KiB |
| example0.txt | AC | 62 ms | 14148 KiB |
| example1.txt | AC | 61 ms | 14120 KiB |