結果
問題 | No.991 N×Mマス計算(構築) |
ユーザー | fine |
提出日時 | 2020-02-15 01:14:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,580 bytes |
コンパイル時間 | 1,732 ms |
コンパイル使用メモリ | 171,924 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-06 13:35:26 |
合計ジャッジ時間 | 4,674 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 17 ms
5,248 KB |
testcase_02 | AC | 15 ms
5,248 KB |
testcase_03 | AC | 15 ms
5,248 KB |
testcase_04 | AC | 17 ms
5,248 KB |
testcase_05 | AC | 16 ms
5,248 KB |
testcase_06 | AC | 16 ms
5,248 KB |
testcase_07 | AC | 17 ms
5,248 KB |
testcase_08 | AC | 16 ms
5,248 KB |
testcase_09 | AC | 16 ms
5,248 KB |
testcase_10 | AC | 18 ms
5,248 KB |
testcase_11 | AC | 17 ms
5,248 KB |
testcase_12 | AC | 16 ms
5,248 KB |
testcase_13 | AC | 17 ms
5,248 KB |
testcase_14 | AC | 16 ms
5,248 KB |
testcase_15 | AC | 16 ms
5,248 KB |
testcase_16 | AC | 15 ms
5,248 KB |
testcase_17 | AC | 15 ms
5,248 KB |
testcase_18 | AC | 16 ms
5,248 KB |
testcase_19 | AC | 16 ms
5,248 KB |
testcase_20 | AC | 17 ms
5,248 KB |
testcase_21 | AC | 16 ms
5,248 KB |
testcase_22 | AC | 17 ms
5,248 KB |
testcase_23 | AC | 16 ms
5,248 KB |
testcase_24 | AC | 17 ms
5,248 KB |
testcase_25 | AC | 17 ms
5,248 KB |
testcase_26 | AC | 16 ms
5,248 KB |
testcase_27 | AC | 17 ms
5,248 KB |
testcase_28 | AC | 16 ms
5,248 KB |
testcase_29 | AC | 17 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; // a * x + b * y == gcd(a, b) なるx, yを計算 // 返り値はgcd(a, b) template<typename T> T extgcd(T a, T b, T& x, T& y) { T d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } 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; 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