Submission #42363020


Source Code Expand

class BIT
	def initialize n
		@a = [0]*(n+1) # 1-indexed internally
	end
 
	def [] i
		i += 1
		s = 0
		while 0<i
			s += @a[i]
			i &= i-1
		end
		return s
	end
 
	def add i,d
		i += 1
		while i<@a.size
			@a[i] += d
			i += i&-i
		end
	end
end

N,M = gets.split.map(&:to_i)
S = N.times.map{ gets.split.map(&:to_i).sort }
U = N+1
S.each{|as|
	i = Hash.new -1
	as.map!{|a| a*U+i[a]+=1 }
}
T = S.flatten.tally
C = BIT.new T.size+1
IA = {}
T.keys.sort.each_with_index{|a,i|
	IA[a] = i
	C.add i,T[a]
}
p S.sum{|as|
	as.sum{|a|
		i = IA[a]
		C.add i,-1
		next C[i]
	}
}+(N*(N-1)/2)*(M*(M+1)/2)

Submission Info

Submission Time
Task F - Merge Sets
User ds14050
Language Ruby (2.7.1)
Score 525
Code Size 635 Byte
Status AC
Exec Time 3716 ms
Memory 141764 KiB

Compile Error

./Main.rb:29: warning: ambiguous first argument; put parentheses or a space even after `-' operator

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 33
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 03_random3_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 53 ms 14156 KiB
00_sample_01.txt AC 58 ms 14132 KiB
00_sample_02.txt AC 59 ms 14032 KiB
01_random_00.txt AC 60 ms 14108 KiB
01_random_01.txt AC 57 ms 14216 KiB
01_random_02.txt AC 91 ms 17504 KiB
01_random_03.txt AC 89 ms 17348 KiB
01_random_04.txt AC 3667 ms 138980 KiB
01_random_05.txt AC 3546 ms 130684 KiB
01_random_06.txt AC 3610 ms 140392 KiB
01_random_07.txt AC 3165 ms 131200 KiB
01_random_08.txt AC 3688 ms 136920 KiB
01_random_09.txt AC 3406 ms 135504 KiB
01_random_10.txt AC 3716 ms 139740 KiB
01_random_11.txt AC 3369 ms 131752 KiB
01_random_12.txt AC 3548 ms 138832 KiB
01_random_13.txt AC 3412 ms 131148 KiB
01_random_14.txt AC 3639 ms 139400 KiB
01_random_15.txt AC 3392 ms 135144 KiB
01_random_16.txt AC 3663 ms 141572 KiB
01_random_17.txt AC 3374 ms 133884 KiB
01_random_18.txt AC 3580 ms 139700 KiB
01_random_19.txt AC 3551 ms 140496 KiB
02_random2_00.txt AC 3041 ms 141580 KiB
02_random2_01.txt AC 3073 ms 132136 KiB
02_random2_02.txt AC 3037 ms 132340 KiB
02_random2_03.txt AC 2942 ms 140448 KiB
02_random2_04.txt AC 3085 ms 141764 KiB
03_random3_00.txt AC 3012 ms 120544 KiB
03_random3_01.txt AC 2988 ms 139576 KiB
03_random3_02.txt AC 3056 ms 128712 KiB
03_random3_03.txt AC 3006 ms 139932 KiB
03_random3_04.txt AC 3005 ms 139832 KiB