結果
| 問題 | No.2142 Segment Zero | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2024-12-03 15:13:21 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 208 ms / 2,000 ms | 
| コード長 | 1,430 bytes | 
| コンパイル時間 | 5,457 ms | 
| コンパイル使用メモリ | 308,832 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-03 15:13:32 | 
| 合計ジャッジ時間 | 10,530 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 35 | 
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
namespace my{
#define done(...) return pp(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define FO(n) for(ll ij=n;ij--;)
#define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__))
#define single_testcase void solve();}int main(){my::io();my::solve();}namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
constexpr auto range(bool s,auto...a){array<ll,3>r{0,0,1};ll I=0;((r[I++]=a),...);if(!s&&I==1)swap(r[0],r[1]);r[0]-=s;return r;}
constexpr char newline=10;
constexpr char space=32;
constexpr auto zz(auto x){return x<0?-x:x;}
void lin(auto&...a){(cin>>...>>a);}
template<char c=space>void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<string(--n>0,c)),...);cout<<newline;}
ll bsl(const auto&f,ll o,ll x){while(zz(o-x)>1)(f((o+x)/2)?o:x)=(o+x)/2;return o;}
single_testcase
void solve(){
  LL(R,K);++R;
  if((R-1)*R==K*2)done(0);
  if(K==0)done(1);
  fo(l,1,R){
    ll r=bsl([&](ll r){
      return(r-l)*(l+r-1)<=K*2;
    },l,R+2);
    if(r==R+1)continue;
    if((l==1||r==R)&&(r-l)*(l+r-1)==K*2)done(1);
  }
  fo(l,1,R){
    ll r=bsl([&](ll r){
      return(r-l)*(l+r-1)<=(R-1)*R-K*2;
    },l,R+2);
    if(r==R+1)continue;
    if((r-l)*(l+r-1)==(R-1)*R-K*2)done(1);
  }
  pp(2);
}}
            
            
            
        