結果

問題 No.2142 Segment Zero
ユーザー nono00
提出日時 2022-12-29 17:31:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,141 bytes
コンパイル時間 851 ms
コンパイル使用メモリ 75,472 KB
最終ジャッジ日時 2025-02-09 21:52:30
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template<typename T>
void print(const T t, bool ln = true) {
    cout << t;
    if (ln) {
        cout << '\n';
    } else {
        cout << ' ';
    }
}

template<typename T>
void printv(const vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) {
        print(v[i], false);
    }
    cout << '\n';
}

template<typename T>
void printvv(const vector<vector<T>> &vv) {
    for (int i = 0; i < (int)vv.size(); i++) {
        vprint(vv[i]);
    }
}

void solve() {
    // 1回または2回で可能
    long long n, k;
    cin >> n >> k;
    long long m = n * (n + 1) / 2 - k;
    vector<long long> a(n + 1);
    for (int i = 1; i <= n; i++) {
        a[i] = a[i - 1] + i;
    }

    // printv(a);
    
    for (int l = 0; l < n; l++) {
        auto it = lower_bound(a.begin() + l, a.end(), a[l] + m);
        if (it == a.end()) {
            continue;
        } else if (*it == a[l] + m) {
            print(1);
            return;
        }
    }

    print(2);
}

int main() {
    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}
0