結果

問題 No.2608 Divide into two
ユーザー ryomacryomac
提出日時 2024-01-19 21:49:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 1,000 ms
コード長 1,637 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 75,764 KB
最終ジャッジ日時 2024-01-19 21:49:34
合計ジャッジ時間 970 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 61 ms
68,720 KB
testcase_02 AC 74 ms
75,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())


def calc(N):
    S = N * (N + 1) / 2
    return S


def greedy(N, S):
    num = [i for i in range(1, N + 1)]
    ans = []
    s = []
    for n in num:
        s.append(n)
        if sum(s) == S:
            for i in range(1, N + 1):
                if i in s:
                    ans.append(1)
                else:
                    ans.append(0)
            return ans
        if sum(s) > S:
            pop = []
            while s and sum(s) > S:
                pop.append(s[0])
                s = s[1:]
                if sum(s) == S:
                    for i in range(1, N + 1):
                        if i in s:
                            ans.append(1)
                        else:
                            ans.append(0)
                    return ans
            if sum(s) < S:
                diff = S - sum(s)
                if diff in pop:
                    s.append(diff)
                    for i in range(1, N + 1):
                        if i in s:
                            ans.append(1)
                        else:
                            ans.append(0)
                    return ans
            return -1


def check(s: str):
    one = 0
    zero = 0
    for i in range(len(s)):
        if s[i] == "0":
            zero += i + 1
        else:
            one += i + 1
    print(one, zero)


for _ in range(T):
    N = int(input())
    S = calc(N)
    # print(N, S)
    if S % 2 == 1:
        print(-1)
        continue
    S //= 2
    ans = greedy(N, S)
    if ans == -1:
        print(-1)
    else:
        ans = "".join(map(str, ans))
        # check(ans)
        print(ans)
0