結果

問題 No.2142 Segment Zero
ユーザー t98slider
提出日時 2022-12-02 21:31:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 569 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 168,852 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-10-09 22:35:35
合計ジャッジ時間 3,380 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, K;
    cin >> N >> K;
    vector<ll> s(N + 1);
    iota(s.begin(), s.end(), 0);
    for(int i = 0; i < N; i++){
        s[i + 1] += s[i];
    }
    if(s.back() == K){
        cout << 0 << '\n';
        return 0;
    }
    ll rem = s.back() - K;
    for(int i = 0; i < N; i++){
        if(binary_search(s.begin(), s.end(), s[i] + rem)){
            cout << 1 << '\n';
            return 0;
        }
    }
    cout << 2 << '\n';
}
0