結果

問題 No.638 Sum of "not power of 2"
ユーザー @abcde@abcde
提出日時 2019-03-09 21:59:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 833 bytes
コンパイル時間 1,260 ms
コンパイル使用メモリ 152,760 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:52:17
合計ジャッジ時間 1,946 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main() {
    
    // 1. 入力情報取得.
    LL N;
    cin >> N;
    
    // 2. N = a + b(a, b は 2の整数乗の形でない正の整数)で表せるか?
    map<LL, LL> pow2;
    LL x = 1;
    pow2[x]++;
    while(x <= N) x *= 2, pow2[x]++;
    // for(auto &p : pow2) cout << p.first << endl;
    
    // 3. a を 計算.
    LL a = 2;
    while(a < N){
        if(pow2[a] == 0 && pow2[N - a] == 0) break;
        a++;
    }
    
    // 4. 出力 ~ 後処理.
    // in01.txt の WA対策
    // -> N = 1 の 場合に, 2 -1 と出力されるバグがあったので, 修正.
    // if(a != N) cout << a << " " << (N - a) << endl;
    if(N != 1 && a != N) cout << a << " " << (N - a) << endl;
    else       cout << -1 << endl;
    return 0;
    
}
0