如题 是个求救帖 这个题目即 矩阵乘法H1005

评测记录在 这里

下面是代码

function str2int(s)::Int128
    ans::Int64 = 0
    for i in 1:length(s)
        ans = (ans << 3) + (ans << 1) + Int(s[i]) - 48
    end
    return ans
end

global myInput = map(str2int, split(readline(stdin)))
n = myInput[1]; m = myInput[2]; p = myInput[3]

L1 = zeros(Int128, n, m)
L2 = zeros(Int128, m, p)

for i in 1:n
    global myInput = map(str2int, split(readline(stdin)))
    for j in 1:m
        L1[i, j] = myInput[j]
    end
end

for i in 1:m
    global myInput = map(str2int, split(readline(stdin)))
    for j in 1:p
        L2[i, j] = myInput[j]
    end
end

ans = L1 * L2
ans = map(function (x::Int128) x = mod(x, 1000000007);x += 1000000007; x = mod(x, 1000000007) end, ans)

for i in 1:n
    for j in 1:p
        print(ans[i, j], ' ')
    end
    println()
end

3 条评论

  • @ 2021-8-3 10:31:43

    哈?展开写是指?

  • @ 2021-7-31 14:03:31
    • @ 2021-8-4 12:35:56

      好像看不到别人的代码? 贴一下

      n=parse(Int,readuntil(stdin,' '))
      p=parse(Int,readuntil(stdin,' '))
      m=parse(Int,readline())
      
      A=Array{Int128,2}(undef,n,p)
      B=Array{Int128,2}(undef,p,m)
      for i in 1:n
      	for j in 1:p-1
      		A[i,j]=parse(Int128,readuntil(stdin,' '))
      	end
      	A[i,p]=parse(Int128,readline())
      end
      for i in 1:p
      	for j in 1:m-1
      		B[i,j]=parse(Int128,readuntil(stdin,' '))
      	end
      	B[i,m]=parse(Int128,readline())
      end
      C=A*B
      for i in 1:n
      	for j in 1:m
      		print(mod(C[i,j],1000000007),' ')
      	end
      	print('\n')
      end
      
  • @ 2021-7-31 1:44:10

    由于第一个测试点通过所以我觉得这件事情很奇怪 也许是因为做乘法的时候爆了

  • 1