結果

問題 No.754 畳み込みの和
ユーザー nadeshinonadeshino
提出日時 2020-02-22 04:18:13
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,037 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 80,916 KB
最終ジャッジ日時 2024-11-14 22:08:05
合計ジャッジ時間 1,401 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(106, 22) Error: type mismatch
Expression: N + 1
  [1] N: (int,)
  [2] 1: int literal(1)

Expected one of (first mismatch at [position]):
[1] func `+`[T](x, y: Complex[T]): Complex[T]
[1] func `+`[T](x, y: set[T]): set[T]
[1] func `+`[T](x: Complex[T]; y: T): Complex[T]
[1] proc `+`(a, b: Duration): Duration
[1] proc `+`(a: ModInt; b: ModInt): ModInt
[1] proc `+`(a: ModInt; b: int): ModInt
[1] proc `+`(a: Time; b: Duration): Time
[1] proc `+`(a: int; b: ModInt): ModInt
[1] proc `+`(dt: DateTime; dur: Duration): DateTime
[1] proc `+`(dt: DateTime; interval: TimeInterval): DateTime
[1] proc `+`(ti1, ti2: TimeInterval): TimeInterval
[1] proc `+`(time: Time; interval: TimeInterval): Time
[1] proc `+`(x, y: float): float
[1] proc `+`(x, y: float32): float32
[1] proc `+`(x, y: int): int
[1] proc `+`(x, y: int16): int16
[1] proc `+`(x, y: int32): int32
[1] proc `+`(x, y: int64): int64
[1] proc `+`(x, y: int8): int8
[1] proc `+`(x, y: uint): uint
[1] proc `+`(x, y: uint16): uint16
[1] proc `+`(x, y: uint32): uint32
[1] proc `+`(x, y: uint64): uint64
[1] proc `+`(x, y: uint8): uint8
[1] proc `+`(x: ModInt): ModInt
[1] proc `+`(x: float): float
[1] proc `+`(x: float32): float32
[1] proc `+`(x: int): int
[1] proc `+`(x: int16): int16
[1] proc `+`(x: int32): int32
[1] proc `+`(x: int64): int64
[1] proc `+`(x: int8): int8
[1] proc `+`[A](s1, s2: HashSet[A]): HashSet[A]
[2] func `+`[T](x: T; y: Complex[T]): Complex[T]

ソースコード

diff #

import algorithm, complex, macros, math, sequtils, sets, strutils, tables, times

macro unpack*(rhs: seq, cnt: static[int]): auto =
  let v = genSym(); result = quote do:(let `v` = `rhs`;())
  for i in 0 ..< cnt: result[1].add(quote do:`v`[`i`])

template input*(T: typedesc, cnt: Natural = 1): untyped =
  let line = stdin.readLine.split(" ")
  when T is int:         line.map(parseInt).unpack(cnt)
  elif T is float:       line.map(parseFloat).unpack(cnt)
  elif T is string:      line.unpack(cnt)
  elif T is char:        line.mapIt(it[0]).unpack(cnt)
  elif T is seq[int]:    line.map(parseint)
  elif T is seq[float]:  line.map(parseFloat)
  elif T is seq[string]: line
  elif T is seq[char]:   line.mapIt(it[0])

# -------------------------------------------------- #

let modulus = 10 ^ 9 + 7

type ModInt* = object
  v: int

proc initModInt*(n: int): ModInt =
  result.v = (n mod modulus + modulus) mod modulus

proc `$`*(x: ModInt): string =
  $x.v

proc pow*(x: ModInt, n: int): ModInt =
  if n < 0:
    return pow(x, -n).pow(modulus - 2)
  var p = 1
  var x = x.v
  var n = n
  while n > 0:
    if (n and 1) != 0:
      p = p * x mod modulus
    x = x * x mod modulus
    n = n shr 1

  result.v = p

proc inverse*(x: ModInt): ModInt =
  pow(x, modulus - 2)

proc `+`*(x: ModInt): ModInt =
  result.v = x.v
proc `-`*(x: ModInt): ModInt =
  result.v = modulus - x.v
  if result.v == modulus: result.v = 0

proc `+`*(a: ModInt, b: ModInt): ModInt =
  result.v = a.v + b.v
  if result.v >= modulus: result.v -= modulus
proc `-`*(a: ModInt, b: ModInt): ModInt =
  result.v = a.v - b.v
  if result.v < 0: result.v += modulus
proc `*`*(a: ModInt, b: ModInt): ModInt =
  result.v = a.v * b.v
  if result.v >= modulus: result.v = result.v mod modulus
proc `/`*(a: ModInt, b: ModInt): ModInt =
  result.v = a.v * b.inverse().v
  if result.v >= modulus: result.v = result.v mod modulus

proc `+`*(a: ModInt, b: int): ModInt =
  a + initModInt(b)
proc `-`*(a: ModInt, b: int): ModInt =
  a - initModInt(b)
proc `*`*(a: ModInt, b: int): ModInt =
  a * initModInt(b)
proc `/`*(a: ModInt, b: int): ModInt =
  a / initModInt(b)

proc `+`*(a: int, b: ModInt): ModInt =
  initModInt(a) + b
proc `-`*(a: int, b: ModInt): ModInt =
  initModInt(a) - b
proc `*`*(a: int, b: ModInt): ModInt =
  initModInt(a) * b
proc `/`*(a: int, b: ModInt): ModInt =
  initModInt(a) / b

proc `+=`*(a: var ModInt; b: ModInt) =
  a = a + b
proc `-=`*(a: var ModInt; b: ModInt) =
  a = a - b
proc `*=`*(a: var ModInt; b: ModInt) =
  a = a * b
proc `/=`*(a: var ModInt; b: ModInt) =
  a = a / b

proc `+=`*(a: var ModInt; b: int) =
  a = a + b
proc `-=`*(a: var ModInt; b: int) =
  a = a - b
proc `*=`*(a: var ModInt; b: int) =
  a = a * b
proc `/=`*(a: var ModInt; b: int) =
  a = a / b

# -------------------------------------------------- #

let N = input(int)
let A = newSeqWith(N + 1, input(int))
let B = newSeqWith(N + 1, input(int))
var C = initModInt(0)
for a in A:
  C += a
var res = initModInt(0)
for i in 0 .. N:
  res += C * B[i]
  C -= A[N - i]
echo res
0