結果

問題 No.1837 Same but Different
ユーザー lam6er
提出日時 2025-03-26 15:54:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,668 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 62,188 KB
最終ジャッジ日時 2025-03-26 15:55:50
合計ジャッジ時間 5,143 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

if n == 3:
    print("99 824 4353")
    print("0 1 5275")
else:
    # Construct A
    A = [99, 824, 4353]
    current = 4354
    for _ in range(3, n):
        A.append(current)
        current += 1
    sum_A = sum(A)
    
    # Construct B
    B = [0, 1]
    remaining = n - 2
    sum_remaining = sum_A - 1  # since B starts with 0 and 1
    
    # Calculate K for the remaining elements
    m = remaining
    if m == 1:
        # Only one element needed
        B.append(sum_remaining)
    else:
        # Solve for K in arithmetic sequence
        # sum = m*K + (m-1)*m//2
        # K = (sum_remaining - (m-1)*m//2) // m
        total_needed = sum_remaining
        K = (total_needed - (m-1)*m//2) // m
        # Ensure K is sufficiently large to avoid overlaps
        # For safety, start from a large base
        K = max(K, 10**5)
        elements = []
        current_sum = K * m + (m-1)*m//2
        if current_sum > total_needed:
            # Adjust K
            K = (total_needed - (m-1)*m//2) // m
            current_sum = K * m + (m-1)*m//2
        
        # Generate the elements
        elements = list(range(K, K + m))
        current_sum = sum(elements)
        if current_sum < total_needed:
            elements[-1] += total_needed - current_sum
        elif current_sum > total_needed:
            # This shouldn't happen with proper K calculation
            pass
        B.extend(elements)
    
    # Verify B is strictly increasing and within 0-10000
    # In case elements are exceeding 10000, adjust (but per problem statement, it's guaranteed)
    # Output
    print(' '.join(map(str, A)))
    print(' '.join(map(str, B)))
0