結果

問題 No.1006 Share an Integer
ユーザー ganmodokixganmodokix
提出日時 2020-03-08 10:13:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 4,067 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 198,564 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-04-24 12:29:04
合計ジャッジ時間 3,984 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 57 ms
12,032 KB
testcase_12 AC 122 ms
18,048 KB
testcase_13 AC 135 ms
18,816 KB
testcase_14 AC 133 ms
18,816 KB
testcase_15 AC 111 ms
16,640 KB
testcase_16 AC 36 ms
9,856 KB
testcase_17 AC 59 ms
12,160 KB
testcase_18 AC 109 ms
16,640 KB
testcase_19 AC 101 ms
16,128 KB
testcase_20 AC 110 ms
17,152 KB
testcase_21 AC 129 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// May this submission get accepted
#include <bits/stdc++.h>

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using namespace std;

// エイリアス (補完・コンパイルが重くなる)
// #include <boost/multiprecision/cpp_int.hpp>
// using mll = boost::multiprecision::cpp_int;

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define FOREACH(i,q) for (auto &i : q)
template<class T> bool chmax(T &a, const T b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T b) { if (a > b) {a = b; return true;} return false; }
constexpr int INF = numeric_limits<int>::max();
constexpr long long LINF = numeric_limits<long long>::max();
constexpr long double EPS = 1e-10L;
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) DUMP_FUNC(q, #q, __FILE__, __LINE__)
template <typename T> void DUMP_PROC(T x) { cerr << x; }
void DUMP_PROC(string x) { cerr << '"' << x << '"'; }
template <typename T> void DUMP_PROC(vector<T> x) { cerr << "["; for (auto &xi : x) { DUMP_PROC(xi); cerr << (&xi != &*x.rbegin()?", ":""); } cerr << "]"; }
template <typename T> void DUMP_FUNC(T x, const char* name, const char* fn, int ln) { cerr << "\e[32m[DEBUG]\e[0m " << name << ": "; DUMP_PROC(x); cerr << " @ " << fn << "(" << ln << ")" << endl; }
template<class T> T gcd(T a, T b) { if (a < b) swap(a, b); while (b) swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(const T x, const char* end = "\n") { cout << x << end; }
void say(const ld x, const char* end = "\n") { cout << setprecision(30) << x << end; }
template <typename T> void say(const vector<T> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { cout << x[i] << (i+1 == i_len ? end : sep); } }
template <typename T> void say(const vector<vector<T>> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { say(x[i], sep, end); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll x = inp1;
    constexpr ll w = 10000;

    vector<ll> d(x+1, 1);
    RANGE(i, 1, x) {
        STEP(j, i*2, x, i) {
            d[j]++;
        }
    }

    ll ans = -1;

    vector<ll> cand; cand.reserve(w*2+1);
    ll minab = LINF;
    RANGE(a, max(1LL, x/2-w), min(x-1, x/2+w)) {
        ll b = x-a;
        ll fa = a - d[a];
        ll fb = b - d[b];
        ll ab = abs(fa - fb);
        if (chmin(minab, ab)) {
            vector<ll>().swap(cand);
            cand.push_back(a);
        } else if (minab == ab) {
            cand.push_back(a);
        }
    }
    for (ll a : cand) {
        cout << a << " " << x-a << "\n";
    }
    cout << flush;
    
}
0