結果

問題 No.1470 Mex Sum
ユーザー yuly3yuly3
提出日時 2021-05-16 19:26:41
言語 Nim
(2.0.2)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 4,993 ms
コンパイル使用メモリ 73,088 KB
実行使用メモリ 15,708 KB
最終ジャッジ日時 2024-04-15 10:28:19
合計ジャッジ時間 8,112 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 36 ms
15,632 KB
testcase_13 AC 35 ms
15,488 KB
testcase_14 AC 35 ms
15,632 KB
testcase_15 AC 37 ms
15,488 KB
testcase_16 AC 35 ms
15,616 KB
testcase_17 AC 35 ms
15,488 KB
testcase_18 AC 31 ms
15,656 KB
testcase_19 AC 35 ms
15,648 KB
testcase_20 AC 34 ms
15,616 KB
testcase_21 AC 35 ms
15,488 KB
testcase_22 AC 39 ms
15,616 KB
testcase_23 AC 34 ms
15,616 KB
testcase_24 AC 35 ms
15,600 KB
testcase_25 AC 37 ms
15,548 KB
testcase_26 AC 38 ms
15,604 KB
testcase_27 AC 37 ms
15,616 KB
testcase_28 AC 36 ms
15,488 KB
testcase_29 AC 36 ms
15,488 KB
testcase_30 AC 34 ms
15,708 KB
testcase_31 AC 36 ms
15,488 KB
testcase_32 AC 36 ms
15,488 KB
testcase_33 AC 35 ms
15,564 KB
testcase_34 AC 35 ms
15,632 KB
testcase_35 AC 34 ms
15,488 KB
testcase_36 AC 33 ms
15,616 KB
testcase_37 AC 27 ms
15,104 KB
testcase_38 AC 27 ms
15,104 KB
testcase_39 AC 26 ms
15,104 KB
testcase_40 AC 29 ms
15,336 KB
testcase_41 AC 28 ms
15,232 KB
testcase_42 AC 28 ms
15,104 KB
testcase_43 AC 28 ms
15,104 KB
testcase_44 AC 29 ms
15,232 KB
testcase_45 AC 28 ms
15,224 KB
testcase_46 AC 29 ms
15,104 KB
testcase_47 AC 29 ms
15,232 KB
testcase_48 AC 30 ms
15,212 KB
testcase_49 AC 31 ms
15,344 KB
testcase_50 AC 29 ms
15,232 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 3) Warning: imported and not used: 'algorithm' [UnusedImport]
/home/judge/data/code/Main.nim(2, 14) Warning: imported and not used: 'bitops' [UnusedImport]
/home/judge/data/code/Main.nim(2, 22) Warning: imported and not used: 'deques' [UnusedImport]
/home/judge/data/code/Main.nim(2, 30) Warning: imported and not used: 'heapqueue' [UnusedImport]
/home/judge/data/code/Main.nim(3, 31) Warning: imported and not used: 'tables' [UnusedImport]
/home/judge/data/code/Main.nim(2, 47) Warning: imported and not used: 'macros' [UnusedImport]
/home/judge/data/code/Main.nim(2, 55) Warning: imported and not used: 'sets' [UnusedImport]
/home/judge/data/code/Main.nim(3, 24) Warning: imported and not used: 'sugar' [UnusedImport]
/home/judge/data/code/Main.nim(3, 3) Warning: imported and not used: 'strformat' [UnusedImport]

ソースコード

diff #

import
  algorithm, bitops, deques, heapqueue, math, macros, sets, sequtils,
  strformat, strutils, sugar, tables

proc input*(): string {.inline.} = stdin.readLine
proc inputs*(): seq[string] {.inline.} = stdin.readLine.split
proc inputInt*(): int {.inline.} = stdin.readLine.parseInt
proc inputInts*(): seq[int] {.inline.} = stdin.readLine.split.map(parseInt)
proc chmax*[T: SomeNumber](n: var T, m: T) {.inline.} = n = max(n, m)
proc chmin*[T: SomeNumber](n: var T, m: T) {.inline.} = n = min(n, m)
proc `%=`*[T: SomeInteger](n: var T, m: T) {.inline.} = n = floorMod(n, m)

when isMainModule:
  var
    N = inputInt()
    A = inputInts()
  
  var ones, twos: int
  for ai in A:
    if ai == 1:
      ones.inc
    elif ai == 2:
      twos.inc
  
  var ans = 0
  for i, ai in A:
    if ai == 1:
      ones.dec
      ans += 3*twos + 2*(N - twos - (i + 1))
    elif ai == 2:
      twos.dec
      ans += 3*ones + N - ones - (i + 1)
    else:
      ans += 2*ones + N - ones - (i + 1)
  echo ans
0