結果

問題 No.2142 Segment Zero
ユーザー Varun TejaVarun Teja
提出日時 2022-12-02 23:02:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,189 bytes
コンパイル時間 1,800 ms
コンパイル使用メモリ 168,316 KB
実行使用メモリ 105,344 KB
最終ジャッジ日時 2024-04-18 08:20:41
合計ジャッジ時間 28,506 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1,239 ms
105,216 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1,156 ms
105,104 KB
testcase_05 AC 1,194 ms
105,028 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 1,168 ms
104,960 KB
testcase_09 WA -
testcase_10 AC 1,225 ms
105,096 KB
testcase_11 AC 1,312 ms
104,960 KB
testcase_12 AC 1,265 ms
104,960 KB
testcase_13 AC 1,148 ms
105,088 KB
testcase_14 AC 1,117 ms
105,156 KB
testcase_15 AC 1,166 ms
105,060 KB
testcase_16 AC 1,208 ms
105,088 KB
testcase_17 AC 935 ms
88,036 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 518 ms
59,776 KB
testcase_21 WA -
testcase_22 AC 771 ms
77,568 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 358 ms
50,816 KB
testcase_29 AC 455 ms
59,220 KB
testcase_30 AC 711 ms
75,776 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1,139 ms
102,396 KB
testcase_36 AC 121 ms
25,984 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;
    stf.insert(0); stb.insert(0);
    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;
    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