提出 #60779596


ソースコード 拡げる

N,*A = $<.read.split.map(&:to_i)

ans = sum = num = 0
SS = lambda{|as,bs|
	as.sum*bs.size + as.size*bs.sum + as.size*bs.size
}
FF = lambda{|as,bs|
	a0,a1 = as.partition{|a| a&1<1 }
	b0,b1 = bs.partition{|b| b&1<1 }
	ff = 0
	ff += FF[a0.map{|a| a>>1 },b1.map{|b| b>>1 }] if a0[0] && b1[0]
	ff += FF[a1.map{|a| a>>1 },b0.map{|b| b>>1 }] if a1[0] && b0[0]
	ff += SS[a0,b0]
	ff += SS[a1,b1]
	next ff
}
S = lambda{|as|
	s = n = 0
	next as.sum{|a|
		s += a
		n += 1
		next s+(a+1)*n
	}
}
F = lambda{|as|
	a0,a1 = as.partition{|a| a&1<1 }
	f = 0
	f += FF[a0.map{|a| a>>1 },a1.map{|a| a>>1 }] if a0[0] && a1[0]
	f += S[a0]
	f += S[a1]
	next f
}
A.sort_by!{|a| a&-a }.reverse!
A.group_by{|a| (a&-a).bit_length-1 }.each{|b,as|
	s = as.sum
	ans += F[as.map{|a| a>>b+1 }]
	ans += (sum>>b)*as.size
	ans += num*(s>>b)
	sum += s
	num += as.size
}

p ans

提出情報

提出日時
問題 F - Double Sum 2
ユーザ ds14050
言語 Ruby (ruby 3.2.2)
得点 500
コード長 882 Byte
結果 AC
実行時間 608 ms
メモリ 52996 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 24
セット名 テストケース
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_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 44 ms 17012 KiB
00_sample_01.txt AC 45 ms 17280 KiB
00_sample_02.txt AC 46 ms 17072 KiB
01_handmade_00.txt AC 140 ms 41180 KiB
01_handmade_01.txt AC 140 ms 42232 KiB
01_handmade_02.txt AC 141 ms 41908 KiB
01_handmade_03.txt AC 113 ms 31696 KiB
02_random_00.txt AC 551 ms 51352 KiB
02_random_01.txt AC 549 ms 50084 KiB
02_random_02.txt AC 556 ms 51120 KiB
02_random_03.txt AC 553 ms 51556 KiB
02_random_04.txt AC 551 ms 51340 KiB
02_random_05.txt AC 136 ms 39908 KiB
02_random_06.txt AC 533 ms 50036 KiB
02_random_07.txt AC 576 ms 52996 KiB
02_random_08.txt AC 601 ms 51652 KiB
02_random_09.txt AC 608 ms 51684 KiB
02_random_10.txt AC 582 ms 50744 KiB
02_random_11.txt AC 601 ms 51428 KiB
02_random_12.txt AC 592 ms 51360 KiB
02_random_13.txt AC 164 ms 43652 KiB
02_random_14.txt AC 179 ms 46160 KiB
02_random_15.txt AC 174 ms 44784 KiB
02_random_16.txt AC 184 ms 46484 KiB