Submission #36332261


Source Code Expand

P,N,*Z = 998244353,*$<.read.split.map(&:to_i)
AE = Z.each_slice(N).map(&:tally)
JJKK = 5.times.map{|i|
	j = i<1 ? 1 : 0
	jkk = [*j+1..4]-[i]
	next 3.times.map{ [j,*jkk.rotate!] }
}

sum = 0
Lo = [0]*5
Up = [N]*5
Z.uniq.sort.each{|z|
	tie = AE.map{|as| as[z]||0 }
	sum += z*tie.each_with_index.sum{|n,i|
		Lo[i] += n
		Up[i] -= n
		next n<1 ? 0 : n*JJKK[i].sum{|j1,j2,k1,k2|
			Lo[j1]*Lo[j2]%P*Up[k1]%P*Up[k2]%P+
			Up[j1]*Up[j2]%P*Lo[k1]%P*Lo[k2]%P
		}%P
	}%P
	sum %= P
}

p sum

Submission Info

Submission Time
Task C - Five Med Sum
User ds14050
Language Ruby (2.7.1)
Score 200
Code Size 504 Byte
Status AC
Exec Time 1918 ms
Memory 97200 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 28
Set Name Test Cases
Sample sample-01.txt, sample-02.txt
All handmade-01.txt, handmade-02.txt, handmade-03.txt, handmade-04.txt, handmade-05.txt, handmade-06.txt, random-01.txt, random-02.txt, random-03.txt, random-04.txt, random-05.txt, random-06.txt, random-07.txt, random-08.txt, random-09.txt, random-10.txt, random-11.txt, random-12.txt, random-13.txt, random-14.txt, random-15.txt, random-16.txt, random-17.txt, random-18.txt, random-19.txt, random-20.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
handmade-01.txt AC 58 ms 14352 KiB
handmade-02.txt AC 59 ms 14160 KiB
handmade-03.txt AC 220 ms 59640 KiB
handmade-04.txt AC 1918 ms 97200 KiB
handmade-05.txt AC 223 ms 59284 KiB
handmade-06.txt AC 225 ms 59672 KiB
random-01.txt AC 55 ms 14220 KiB
random-02.txt AC 71 ms 15128 KiB
random-03.txt AC 56 ms 14256 KiB
random-04.txt AC 1650 ms 85880 KiB
random-05.txt AC 56 ms 14080 KiB
random-06.txt AC 299 ms 26308 KiB
random-07.txt AC 55 ms 14320 KiB
random-08.txt AC 55 ms 14224 KiB
random-09.txt AC 157 ms 18808 KiB
random-10.txt AC 65 ms 14556 KiB
random-11.txt AC 114 ms 17428 KiB
random-12.txt AC 56 ms 14256 KiB
random-13.txt AC 56 ms 14152 KiB
random-14.txt AC 54 ms 14164 KiB
random-15.txt AC 55 ms 14220 KiB
random-16.txt AC 419 ms 31552 KiB
random-17.txt AC 412 ms 31576 KiB
random-18.txt AC 56 ms 14228 KiB
random-19.txt AC 55 ms 14120 KiB
random-20.txt AC 199 ms 21644 KiB
sample-01.txt AC 55 ms 14156 KiB
sample-02.txt AC 58 ms 14232 KiB