結果
問題 | No.991 N×Mマス計算(構築) |
ユーザー | fine |
提出日時 | 2020-02-15 01:16:59 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 2,485 bytes |
コンパイル時間 | 1,671 ms |
コンパイル使用メモリ | 170,620 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-06 13:35:36 |
合計ジャッジ時間 | 4,568 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 18 ms
6,816 KB |
testcase_02 | AC | 18 ms
6,816 KB |
testcase_03 | AC | 18 ms
6,820 KB |
testcase_04 | AC | 18 ms
6,820 KB |
testcase_05 | AC | 18 ms
6,816 KB |
testcase_06 | AC | 18 ms
6,820 KB |
testcase_07 | AC | 18 ms
6,816 KB |
testcase_08 | AC | 18 ms
6,816 KB |
testcase_09 | AC | 18 ms
6,816 KB |
testcase_10 | AC | 18 ms
6,816 KB |
testcase_11 | AC | 17 ms
6,816 KB |
testcase_12 | AC | 18 ms
6,816 KB |
testcase_13 | AC | 19 ms
6,820 KB |
testcase_14 | AC | 18 ms
6,816 KB |
testcase_15 | AC | 18 ms
6,816 KB |
testcase_16 | AC | 18 ms
6,816 KB |
testcase_17 | AC | 18 ms
6,816 KB |
testcase_18 | AC | 18 ms
6,816 KB |
testcase_19 | AC | 17 ms
6,816 KB |
testcase_20 | AC | 17 ms
6,816 KB |
testcase_21 | AC | 17 ms
6,816 KB |
testcase_22 | AC | 18 ms
6,816 KB |
testcase_23 | AC | 18 ms
6,816 KB |
testcase_24 | AC | 19 ms
6,816 KB |
testcase_25 | AC | 18 ms
6,820 KB |
testcase_26 | AC | 17 ms
6,820 KB |
testcase_27 | AC | 18 ms
6,820 KB |
testcase_28 | AC | 18 ms
6,816 KB |
testcase_29 | AC | 18 ms
6,820 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; ll calc(ll x) { ll ok = 1, ng = x + 1; while (ng - ok > 1) { ll mid = (ok + ng) / 2; (mid * mid <= x ? ok : ng) = mid; } return ok; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n = 100000, m = 100000; ll K = 1000000000; char op = '*'; ll x; cin >> x; if (x == 0) { cout << "3 2 129\n"; cout << "+ 12 34\n"; cout << 10 << endl; cout << 20 << endl; cout << 30 << endl; return 0; } ll hoge = calc(x); ll rest = x - hoge * hoge; ll a1 = hoge, a2 = 0, b1 = 0, b2 = hoge; if (rest > 0) { ll diff = 1e15; for (ll i = 1; i * i <= rest && i <= hoge; ++i) { if (rest % i != 0) continue; ll j = rest / i; if (abs(i - j) < diff) { a1 = i; a2 = hoge - i; b1 = j; diff = abs(i - j); } } } vector<ll> a(n), b(m); ll asum = 0, bsum = 0; for (ll i = 0; i < a1; ++i) { a[i] = 50000; (asum += a[i]) %= K; } for (ll i = 0; i < a2; ++i) { a[i + a1] = 25000; (asum += a[i + a1]) %= K; } for (ll i = 0; i < b1; ++i) { b[i] = 20000; (bsum += b[i]) %= K; } for (ll i = 0; i < b2; ++i) { b[i + b1] = 40000; (bsum += b[i + b1]) %= K; } ll rb = (K + 1 - bsum) % K; ll ra = (K + x - asum) % K; ll i = a1 + a2; ll numa = n - i; if (ra < numa) ra += K; ll vala = ra / numa; for (ll ii = 0; ii < numa; ++ii) { a[i + ii] = vala; if (ii < ra % numa) a[i + ii]++; (asum += a[i + ii]) %= K; } ll j = b1 + b2; ll numb = m - j; if (rb < numb) rb += K; ll valb = rb / numb; for (ll ii = 0; ii < numb; ++ii) { b[j + ii] = valb; if (ii < rb % numb) b[j + ii]++; (bsum += b[j + ii]) %= K; } assert(asum * bsum % K == x); cerr << vala << " " << valb << endl; cout << n << " " << m << " " << K << "\n"; cout << op; for (ll i = 0; i < m; ++i) { cout << " " << b[i]; } cout << "\n"; for (int i = 0; i < n; ++i) { cout << a[i] << "\n"; } return 0; } // (sb * n + sa * m) % K == X // K = 10^9 // sb = pb + rb, sa = pa + ra // (rb * n + ra * m) % K == (X - pb * n - pa * m) % K // sa * sb == X