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.

ABC182 C - To 3 から学んだ

Posted at

abc182_1.png
abc182_2.png
abc182_3.png
abc182_4.png

bit 全探索かな?。
っで、どうやるんだっけ?
こちらが神です。

ザックリ見積もりで計算量が O(10^6 ~ 10^7) 。
python で行けない可能性を危惧し、pypy で提出。無事通った。

To3.py
N = list(input())

from itertools import product
def solv():
    ans = float("inf")
    for nums in product([0,1],repeat=len(N)):# O(2*10^5)
       nums = list(nums)
       score = ""
       if sum(nums) == 0:
          continue
       for i in range(len(N)):# O(19)
          if nums[i] == 1:
              score += N[i]
       score = "".join(score)
       if (int(score))%3 == 0:
          ans = min(len(N)-len(score),ans)
    print(ans if ans != float("inf") else -1)

solv()
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?