結果

問題 No.2142 Segment Zero
ユーザー dyktr_06dyktr_06
提出日時 2022-12-02 22:10:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 2,253 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 164,608 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-18 06:26:25
合計ジャッジ時間 5,153 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 90 ms
11,008 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 90 ms
11,008 KB
testcase_04 AC 98 ms
11,136 KB
testcase_05 AC 96 ms
11,008 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 97 ms
11,008 KB
testcase_08 AC 92 ms
11,008 KB
testcase_09 AC 98 ms
11,008 KB
testcase_10 AC 94 ms
11,008 KB
testcase_11 AC 92 ms
11,008 KB
testcase_12 AC 91 ms
11,136 KB
testcase_13 AC 92 ms
11,008 KB
testcase_14 AC 95 ms
11,008 KB
testcase_15 AC 91 ms
11,008 KB
testcase_16 AC 94 ms
11,008 KB
testcase_17 AC 80 ms
9,728 KB
testcase_18 AC 21 ms
5,376 KB
testcase_19 AC 19 ms
5,376 KB
testcase_20 AC 55 ms
7,680 KB
testcase_21 AC 61 ms
8,064 KB
testcase_22 AC 69 ms
8,960 KB
testcase_23 AC 17 ms
5,376 KB
testcase_24 AC 29 ms
5,760 KB
testcase_25 AC 34 ms
6,144 KB
testcase_26 AC 67 ms
8,704 KB
testcase_27 AC 72 ms
8,832 KB
testcase_28 AC 41 ms
6,912 KB
testcase_29 AC 51 ms
7,552 KB
testcase_30 AC 67 ms
8,704 KB
testcase_31 AC 66 ms
8,704 KB
testcase_32 AC 26 ms
5,504 KB
testcase_33 AC 12 ms
5,376 KB
testcase_34 AC 35 ms
6,400 KB
testcase_35 AC 92 ms
10,880 KB
testcase_36 AC 19 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void in(T& ...)':
main.cpp:28:55: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   28 | template<class... T> void in(T&... a){ (cin >> ... >> a); }
      |                                                       ^
main.cpp: In function 'void out(const T&, const Ts& ...)':
main.cpp:30:112: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   30 | template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
      |                                                                                                                ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())

typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef pair<long long, long long> P;

const long long INF = 0x1fffffffffffffff;
const long long MOD = 998244353;
const long double PI = acos(-1);
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }
template<class... T> void in(T&... a){ (cin >> ... >> a); }
void out(){ cout << '\n'; }
template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T, class U> void inGraph(vector<vector<T>>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } }

template <typename T>
T arithmeticsum(T a, T d, T n){
    return n * (a * 2 + (n - 1) * d) / 2;
}

ll n, k;

void input(){
    in(n, k);
}

void solve(){
    ll ans = 2;
    vll sum(n + 1);
    rep(i, n){
        sum[i + 1] = sum[i] + i + 1;
    }
    rep(i, n){
        ll s = sum[i];
        ll ok = i, ng = n + 1;
        while(abs(ok - ng) > 1){
            ll mid = (ok + ng) / 2;
            if(s + sum[n] - sum[mid] >= k){
                ok = mid;
            }else{
                ng = mid;
            }
        }
        if(s + sum[n] - sum[ok] == k){
            ans = 1;
        }
    }
    if(arithmeticsum(1LL, 1LL, n) == k){
        ans = 0;
    }
    out(ans);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    input();
    solve();
}
0