結果

問題 No.5005 3-SAT
ユーザー lam6er
提出日時 2025-03-26 15:46:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 65,664 KB
スコア 17,782
最終ジャッジ日時 2025-03-26 15:46:33
合計ジャッジ時間 9,353 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    bits = [None] * 256
    for _ in range(2048):
        line = sys.stdin.readline()
        if not line:
            break
        a, b, c, p, q, r = map(int, line.strip().split())
        satisfied = False
        # Check a's clause
        if bits[a] is not None:
            if bits[a] == p:
                satisfied = True
        # Check b's clause if not satisfied
        if not satisfied:
            if bits[b] is not None:
                if bits[b] == q:
                    satisfied = True
        # Check c's clause if not satisfied
        if not satisfied:
            if bits[c] is not None:
                if bits[c] == r:
                    satisfied = True
        if satisfied:
            continue
        # Assign a bit
        if bits[a] is None:
            bits[a] = p
        elif bits[b] is None:
            bits[b] = q
        elif bits[c] is None:
            bits[c] = r
        # else: all assigned and none match, this clause is the first failed
    
    # Fill unassigned bits with 1
    for i in range(256):
        if bits[i] is None:
            bits[i] = 1
    
    # Convert to string, reversed to match the required order (MSB first)
    output = ''.join(str(bit) for bit in reversed(bits))
    print(output[:256])

if __name__ == "__main__":
    main()
0