ABC348 F - Oddly Similar
https://atcoder.jp/contests/abc348/tasks/abc348_f (opens in a new tab)
้่ฒไธไฝใbit ไธฆๅๅใ
ใพใๅๆใจใใฆๆฌกใฎใใฏใใใฏใ็ฅใฃใฆใใๅฟ ่ฆใใใใ
-
ใใใใฎใฎๅๆฐใฎๅถๅฅใๅใใใๅ้กใฏใใใใใซใฆใณใใใๅฟ ่ฆใฏใชใใ้ฉๅฎ xor ใๅใใ ใใง่ฏใ
cnt = 0 for e in iterable: if f(e): cnt ^= 1 if cnt == 1: print('Oddly!')
ๅๆฐๅ ใๅๅฅใซใใงใใฏใใใจ TLE ใซใชใใฎใฏ็ฎใซ่ฆใใฆใใใฎใง๏ผ้ซ้ใช่จ่ชใงใฏใใใงใใชใ (opens in a new tab)ใใใ๏ผใๆฐๅใฎๅ่ฆ็ด ๅๅฃซ๏ผใคใณใใใฏในๅใใใฎ๏ผใใพใจใใฆ่จ็ฎใใใใจใ่ฉฆใฟใใฎใฏ่ช็ถใช็บๆณใงใใใ
ใคใพใใ ใซๅฏพใใฆใๅ ใ็ญใใใใฎใใใงใใฏใงใใชใใใจ่ใใใใใ ใใใใคใผใใซ่กใใจ ใใใใใใ็ตๅฑ็ทใใฆ ใจใชใ้ใซๅใใชใใ
ใใใงใ ใฎๅในใใใใงใ ใ็ญใใใชใใจใ 1 ใซใชใใใใช ใฎ่กจใไฝๆใใใใจใซใใใ
ไพใใฐๅ ฅๅไพ 1 ใซใใใฆใ
3 3
1 2 3
1 3 4
2 3 4
ใฎๆใ ใซใใใ ใซใใ่กจใฏๆฌกใฎ้ใใซใชใใ
-
i\j 1 2 3 1 1 1 0 2 1 1 0 3 0 0 1
ๅๆงใซใใฆใ ใฎๆใฎ่กจใฏใใใใใ
-
i\j 1 2 3 1 1 0 0 2 0 1 1 3 0 1 1 -
i\j 1 2 3 1 1 0 0 2 0 1 1 3 0 1 1
ใจใชใใๆ็ต็ใซใใใใฎ่กจใ่ถณใๅใใใใฐใ ่ฆ็ด ใ ใจ ใซใคใใฆใ ใจใชใ ใฎๅๆฐใ่กจใใใใใใใใๅคใๅฅๆฐใจใชใใใฎใฎๅๆฐใใซใฆใณใใใใใจใงๅ้กใซๅ็ญใใใใจใใงใใใใๅฎ้ใฎใจใใใๅ่ฟฐใฎใใฏใใใฏใฎๅฉ็จใซใใใ่กจๅๅฃซใฎๆไป็่ซ็ๅใๅใใใจใงๅใ่งฃใๅพใใใจใใงใใใ
ใใใงใ่กๅๅฃซใฎ่จ็ฎใฏ็ฌ็ซใซ่จ็ฎใงใใใใจใซๆณจๆใใใ
ใใฆใ่กจใ็บใใใจใ ใจใใฆๅใๅคใๆใคใคใณใใใฏใน ใฏ ่กจ ใซใใใฆใ่ก ๏ผใใใใฏๅ ๏ผใ็ญใใใชใใใใ ใฎๅคใ็ญใใใใฎใใพใจใใฆ่จ็ฎใใใใจใใงใใใใใใซใใใฎ่กจใฎๅ่กใ bit ใง็ฎก็ใใใใคใพใ ใจใชใๆใ ใซๅฏพใใฆ ็ช็ฎใจ ็ช็ฎใ็ซใคใใใช bit ใ็จๆใใใฐใๆฌกใฎๆไป็่ซ็ๅใซใใ่จ็ฎใ้ซ้ๅใใใใจใใงใใใ
ๆๅบใณใผใ
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
# mat[i] := mat[i] & 1 << j == 1 ใงใใใฐ A_i ใจ A_j ใฏไผผใฆใใ
mat = [0] * n
for k in range(m):
# bits[x] := sum(1 << i for i in A_{i,k} = x)
bits = [0] * 1000
for i in range(n):
bits[a[i][k]] |= 1 << i
for i in range(n):
mat[i] ^= bits[a[i][k]]
ans = 0
for i in range(n):
for j in range(i + 1, n):
if mat[i] & (1 << j):
ans += 1
print(ans)