結果

問題 No.638 Sum of "not power of 2"
ユーザー incuiioincuiio
提出日時 2023-05-18 17:02:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,134 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 131,160 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 10:51:43
合計ジャッジ時間 2,184 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>
#include <cassert>
#include <regex>
using std::cout;
using std::cin;
using std::string;
using std::vector;

int main()
{
    vector<long long> powers;
    long long i = 1;
    while (i < 1e18)
    {
        powers.push_back(i);
        i *= 2;
    }
    long long n;
    cin >> n;
    bool ans = false;
    long long x, y;
    for (long long a = 1; a < n; a++)
    {
        long long b = n - a;
        bool is_power = false;
        for (int i = 0; i < powers.size(); i++)
        {
            if (a == powers[i] || b == powers[i])
            {
                is_power = true;
                break;
            }
        }
        if (!is_power)
        {
            ans = true;
            x = a;
            y = b;
            break;
        }
    }
    if (ans)
    {
        cout << x << ' ' << y;
    }
    else
    {
        cout << -1;
    }
}
0