0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ABC72 C - Together を解いた

Posted at

abc72_1.png
abc72_2.png

全部リストしてみよっかな。
それを数えて最大値を出してみる。

Together.py
N = int(input())
A = list(map(int,input().split()))

lis = []

for i in range(N):#O(N)
    a,b,c = A[i]-1,A[i],A[i]+1
    lis.append(a)
    lis.append(b)
    lis.append(c)

from collections import Counter
lis = Counter(lis)#O(N)

print(lis.most_common()[0][1])
##total 計算量 ザックリ O(2N)

意気揚々とカウントしたが、最大値のスマートな出し方に
困ったので、ググった。以下が分かり易い。

尚、collections の Counter は以下を眺めると O(N) で行けるっぽ買った。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?