답안 #251596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251596 2020-07-21T22:27:13 Z Bruteforceman Popcount (COCI19_popcount) Python 3
110 / 110
32 ms 3564 KB
import math
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
def value(a) :
    ans = 0
    for i in range(len(a)):
        if a[i] == 1:
            ans += 1 << i
    return str(ans)
a = [(i, i) for i in range(n)]
sz = 1
result = []

while len(a) > 0: 
    s = [0] * n
    t = [0] * n
    b = []
    for i in range(1, len(a), 2):
        for j in range(a[i - 1][0], a[i - 1][1] + 1):
            s[j] = 1
        for j in range(a[i][0], a[i][1] + 1):
            t[j] = 1
        b.append((a[i - 1][0], a[i][1]))
    exp = '((A&' + value(s) + ')+((A&' + value(t) + ')>>' + str(sz) + '))'
    if len(a) % 2 == 1:
        s = [0] * n
        t = [0] * n
        for j in range(a[-1][0], a[-1][1] + 1):
            s[j] = 1
        for j in range(a[-1][1] + 1, n):
            t[j] = 1
        extra = '((A&' + value(s) + ')+((A&' + value(t) + ')>>' + str(sz) + '))'
    else:
        s = [0] * n
        for j in range(a[-1][1] + 1, n):
            s[j] = 1
        extra = '(A&' + value(s) + ')' 
    exp = '(' + exp + '|' + extra + ')'
    result.append('A=' + exp)
    a = b[:]
    sz *= 2
if len(result) > k:
    result = result[:k]        
print(len(result))
print('\n'.join(result))
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3436 KB Accepted.
2 Correct 20 ms 3436 KB Accepted.
3 Correct 20 ms 3428 KB Accepted.
4 Correct 20 ms 3428 KB Accepted.
5 Correct 20 ms 3436 KB Accepted.
6 Correct 22 ms 3432 KB Accepted.
7 Correct 22 ms 3436 KB Accepted.
8 Correct 23 ms 3428 KB Accepted.
9 Correct 22 ms 3436 KB Accepted.
10 Correct 20 ms 3436 KB Accepted.
11 Correct 20 ms 3436 KB Accepted.
12 Correct 21 ms 3436 KB Accepted.
13 Correct 20 ms 3428 KB Accepted.
14 Correct 20 ms 3436 KB Accepted.
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3428 KB Accepted.
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3436 KB Accepted.
2 Correct 20 ms 3436 KB Accepted.
3 Correct 20 ms 3428 KB Accepted.
4 Correct 20 ms 3428 KB Accepted.
5 Correct 20 ms 3436 KB Accepted.
6 Correct 20 ms 3436 KB Accepted.
7 Correct 23 ms 3436 KB Accepted.
8 Correct 20 ms 3436 KB Accepted.
9 Correct 27 ms 3428 KB Accepted.
10 Correct 21 ms 3436 KB Accepted.
11 Correct 32 ms 3428 KB Accepted.
12 Correct 32 ms 3428 KB Accepted.
13 Correct 21 ms 3436 KB Accepted.
14 Correct 21 ms 3436 KB Accepted.
15 Correct 20 ms 3564 KB Accepted.
16 Correct 22 ms 3556 KB Accepted.
17 Correct 20 ms 3436 KB Accepted.
18 Correct 20 ms 3436 KB Accepted.
19 Correct 21 ms 3428 KB Accepted.
20 Correct 20 ms 3428 KB Accepted.
21 Correct 20 ms 3436 KB Accepted.
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 3436 KB Accepted.
2 Correct 25 ms 3548 KB Accepted.
3 Correct 23 ms 3436 KB Accepted.
4 Correct 24 ms 3436 KB Accepted.
5 Correct 22 ms 3436 KB Accepted.
6 Correct 22 ms 3436 KB Accepted.
7 Correct 21 ms 3436 KB Accepted.
8 Correct 21 ms 3428 KB Accepted.
9 Correct 22 ms 3436 KB Accepted.
10 Correct 22 ms 3436 KB Accepted.
11 Correct 22 ms 3428 KB Accepted.
12 Correct 24 ms 3428 KB Accepted.