結果

問題 No.973 余興
ユーザー 👑 jupirojupiro
提出日時 2020-01-18 18:30:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,414 ms / 4,000 ms
コード長 2,397 bytes
コンパイル時間 1,099 ms
コンパイル使用メモリ 118,828 KB
実行使用メモリ 394,676 KB
最終ジャッジ日時 2023-09-10 08:26:21
合計ジャッジ時間 78,444 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,176 ms
394,564 KB
testcase_01 AC 2,131 ms
394,536 KB
testcase_02 AC 2,164 ms
394,412 KB
testcase_03 AC 2,139 ms
394,100 KB
testcase_04 AC 2,135 ms
394,676 KB
testcase_05 AC 2,125 ms
394,568 KB
testcase_06 AC 2,118 ms
394,240 KB
testcase_07 AC 2,135 ms
393,968 KB
testcase_08 AC 2,146 ms
392,976 KB
testcase_09 AC 2,163 ms
394,560 KB
testcase_10 AC 2,030 ms
378,900 KB
testcase_11 AC 700 ms
144,068 KB
testcase_12 AC 689 ms
144,084 KB
testcase_13 AC 671 ms
142,980 KB
testcase_14 AC 679 ms
143,012 KB
testcase_15 AC 46 ms
19,100 KB
testcase_16 AC 49 ms
19,256 KB
testcase_17 AC 28 ms
12,888 KB
testcase_18 AC 37 ms
15,796 KB
testcase_19 AC 37 ms
15,816 KB
testcase_20 AC 27 ms
12,660 KB
testcase_21 AC 48 ms
18,956 KB
testcase_22 AC 48 ms
18,892 KB
testcase_23 AC 38 ms
15,696 KB
testcase_24 AC 39 ms
15,712 KB
testcase_25 AC 17 ms
8,932 KB
testcase_26 AC 27 ms
12,528 KB
testcase_27 AC 59 ms
21,624 KB
testcase_28 AC 37 ms
15,724 KB
testcase_29 AC 37 ms
15,444 KB
testcase_30 AC 2,337 ms
394,636 KB
testcase_31 AC 2,355 ms
394,504 KB
testcase_32 AC 2,348 ms
394,560 KB
testcase_33 AC 2,346 ms
394,036 KB
testcase_34 AC 2,414 ms
392,624 KB
testcase_35 AC 2,332 ms
394,576 KB
testcase_36 AC 2,206 ms
384,068 KB
testcase_37 AC 2,223 ms
384,204 KB
testcase_38 AC 2,319 ms
393,228 KB
testcase_39 AC 2,288 ms
393,584 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 1 ms
4,384 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2,272 ms
394,472 KB
testcase_47 AC 2,182 ms
394,292 KB
testcase_48 AC 2,268 ms
394,576 KB
testcase_49 AC 2,042 ms
363,648 KB
testcase_50 AC 2,285 ms
391,592 KB
testcase_51 AC 2,297 ms
394,476 KB
testcase_52 AC 2,303 ms
394,500 KB
testcase_53 AC 2,184 ms
387,692 KB
testcase_54 AC 2,282 ms
394,624 KB
testcase_55 AC 2,238 ms
394,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

class BIT {
private:
	ll N;
	vector<ll> node;
public:
	BIT(ll M) {
		node = vector<ll>(M + 1, 0);
		N = M;
	}

	ll sum(ll i) {
		ll s = 0;
		while (i > 0) {
			s += node[i];
			i -= i & -i;
		}
		return s;
	}

	ll sum(ll i, ll j) {
		ll l = sum(i - 1);
		ll r = sum(j);
		return r - l;
	}

	void add(ll i, ll x) {
		while (i <= N) {
			node[i] += x;
			i += i & -i;
		}
	}
};


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll N, X; scanf("%lld %lld", &N, &X);
	vector<ll> a(N); for (ll i = 0; i < N; i++) scanf("%lld", &a[i]);
	vector<ll> rb(N);
	vector<ll> lb(N);
	for (ll i = 0; i < N; i++) {
		ll j = i;
		ll sum = 0;
		while (j < N && sum + a[j] <= X) {
			rb[i] = j;
			sum += a[j];
			j++;
		}
	}
	for (ll i = N - 1; i >= 0; i--) {
		ll j = i;
		ll sum = 0;
		while (j >= 0 && sum + a[j] <= X) {
			lb[i] = j;
			sum += a[j];
			j--;
		}
	}

	vector<BIT> vbl(N, BIT(N + 1)), vbr(N, BIT(N + 1));

	for (ll len = 1; len <= N; len++) {
		for (ll left = 0; left + len - 1 < N; left++) {
			ll right = left + len - 1;
			ll lose = 1;
			//cout << right << endl;
			if (vbl[left].sum(max(left, lb[right] - 1) + 1, right)) lose = 0;
			if (vbr[right].sum(left + 2, min(right, rb[left] + 1) + 1)) lose = 0;
			if (lose) {
				vbl[left].add(right + 1, 1);
				vbr[right].add(left + 1, 1);
			}
			//cout << left << " " << right << " " << rb[left]<<" "<<lb[right]<< " "<<vbl[left].sum(right + 1, right + 1) << " " << vbr[right].sum(left + 1, left + 1) << endl;
		}
	}
	if (vbl[0].sum(N,N)) puts("B");
	else puts("A");
	return 0;
}
0