分析
数据量还是很小,暴力枚举就行了,两组数据中的每个元素都遍历一遍[-2,-1,0,1,2],然后把新组成的密码计数,去重即可
py 代码
from collections import deque
n = int(input().strip())
lisA = list(map(int,input().strip().split()))
lisB = list(map(int,input().strip().split()))
todo = [-2,-1,0,1,2]
ans = dict()
def finds(lis):
a,b,c = lis
for i in todo:
aa = a
while aa + i < 0:aa += n
aa = (aa + i)%n
for j in todo:
bb = b
while bb + j < 0:bb += n
bb = (bb + j)%n
for k in todo:
cc = c
while cc + k < 0:cc += n
cc = (cc + k)%n
res = str(aa) + '-'+str(bb) + '-'+str(cc)
ans[res] = True
finds(lisA)
finds(lisB)
print(len(ans.keys()))