結果

問題 No.2142 Segment Zero
ユーザー Varun TejaVarun Teja
提出日時 2022-12-02 23:19:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,324 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 169,140 KB
実行使用メモリ 105,320 KB
最終ジャッジ日時 2024-04-18 08:35:06
合計ジャッジ時間 31,367 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1,357 ms
105,240 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 AC 1,330 ms
105,024 KB
testcase_05 AC 1,338 ms
105,196 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,356 ms
105,112 KB
testcase_09 WA -
testcase_10 AC 1,328 ms
105,112 KB
testcase_11 AC 1,289 ms
105,180 KB
testcase_12 AC 1,338 ms
105,168 KB
testcase_13 AC 1,322 ms
104,972 KB
testcase_14 AC 1,322 ms
105,320 KB
testcase_15 AC 1,338 ms
105,200 KB
testcase_16 AC 1,312 ms
105,260 KB
testcase_17 AC 1,022 ms
87,740 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 585 ms
59,904 KB
testcase_21 WA -
testcase_22 AC 856 ms
77,388 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 436 ms
50,688 KB
testcase_29 AC 529 ms
59,392 KB
testcase_30 AC 767 ms
76,072 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1,192 ms
102,412 KB
testcase_36 AC 117 ms
26,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n, k; cin >> n >> k;
    int sm = (n * (n + 1)) / 2; long long diff1 = sm - k, diff2 = sm - k;
    int F[n], B[n], i; set<long long> stf, stb; 
    for(i = 0; i < n; i++) {
        F[i] = ((i + 1) * (i + 2)) / 2;
        B[n - i - 1] = (n * (n + 1)) / 2 - ((i + 2) * (i + 1)) / 2;
        stf.insert(F[i]);
        stb.insert(B[n - i - 1]);
    }
    int front = 0, back = 0;
    if(k == 0) {
        front = 1; back = 1;
    }
    else {
        for(i = 0; i < n; i++) {
            if(diff1 >= F[i]) {
                diff1 -= F[i];
            }
            else {
                diff1 -= F[i];
                diff1 = abs(diff1);
                if(stf.find(diff1) == stf.end())    front = 2;
                else    front = 1;
                break;
            }
        }
        for(i = n - 1; i >= 0; i--) {
            if(diff2 >= B[i]) {
                diff2 -= B[i];
            }
            else  {
                diff2 -= B[i];
                diff2 = abs(diff2);
                if(stb.find(diff2) == stb.end())    back = 2;
                else                                back = 1;
                break;
            }
        }
    } 
    if(front == 1 || back == 1) cout << 1 << endl;
    else    cout << 2 << endl;
    return 0;
}
0