結果

問題 No.2343 (l+r)/2
ユーザー startcppstartcpp
提出日時 2023-06-10 07:23:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 674 ms
コンパイル使用メモリ 72,212 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-30 18:44:22
合計ジャッジ時間 2,190 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 335 ms
4,380 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 61 ms
4,376 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 AC 7 ms
4,376 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 15 ms
4,384 KB
testcase_08 AC 20 ms
4,380 KB
testcase_09 AC 14 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 17 ms
4,504 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 20 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//0~と1~で対称性があるので、0~だけを考える。
//最大値 < 0.5なら無理。それ以外は作れそう。
//・最大化の気持ちになると、0だけをランレングス圧縮した列Bを作りたい。
//・Bの総和>=0なら、0と1を同数にできて、あとは[10]->0.5, [01]->0.5、[111000]->[1100]->[10]->[0.5]あたりを意識すればできそう。
//・Bの総和=-1でも、|B| >= 9だとできる。
//・それ以外は、できなそう。(未証明)
#include <iostream>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

bool solve(vector<int> a) {
	int n = a.size();
	int i;
	if (a[0] == 1) rep(i, n) a[i] = !a[i];

	vector<int> na;
	int len = 0;
	rep(i, n) {
		if (a[i] == 1) {
			if (len > 0) na.push_back(0);
			na.push_back(1);
			len = 0;
		}
		else {
			len++;
		}
	}
	if (len > 0) na.push_back(0);

	int s = 0;
	rep(i, na.size()) { if (na[i] == 0) s--; else s++; }
	if (s >= 0) return true;
	if (na.size() >= 9) return true;
	return false;
}

int main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		vector<int> a(n);
		for (int i = 0; i < n; i++) cin >> a[i];
		bool res = solve(a);
		if (res) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}
0