結果
問題 | No.2142 Segment Zero |
ユーザー |
![]() |
提出日時 | 2024-11-13 11:31:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 1,275 bytes |
コンパイル時間 | 2,036 ms |
コンパイル使用メモリ | 196,564 KB |
最終ジャッジ日時 | 2025-02-25 04:03:13 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>//#include <atcoder/modint>using namespace std;//using namespace atcoder;using ll = long long;//using mint = modint998244353;vector<ll> factor;void all_factor(ll n){factor.clear();for (ll i = 1; i*i <= n; i++){if (n % i == 0){factor.push_back(i);if (i*i != n) factor.push_back(n / i);}}}int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);ll N, K, y, M, B, A;cin >> N >> K;M = N*(N+1)-K*2;/*S(x)=1+...+x > Kとなる最小のxを考える。S(x)-KをS(x)から引けば良いが、これはS(x)-x <= K, S(x)-K <= xよりx以下つまり、S(x)-Kと[x+1, ..., K]の2つを消せば良い。1回でKにできる場合は愚直に判定する。N*(N+1)/2 - (B*(B+1)/2 - A*(A+1)/2) = K(B-A)(B+A+1) = N*(N+1)-2Kを満たす[A+1, ..., B]が存在するか判定する。*/all_factor(M);for (auto x : factor){y = M/x-1;if ((x+y) % 2 == 1) continue;B = (x+y)/2;A = (y-x)/2;if (0 <= A && A <= B && B <= N){cout << 1 << endl;return 0;}}cout << 2 << endl;return 0;}