結果

問題 No.2343 (l+r)/2
ユーザー Heart_BlueHeart_Blue
提出日時 2023-06-09 21:46:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 2,468 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 143,176 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 13:07:19
合計ジャッジ時間 2,804 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
pair<int, int> vp[N];
pair<int, int> getsum(pair<int, int>& p1, pair<int, int>& p2)
{
	int a = p1.first * p2.second + p1.second * p2.first;
	int b = p1.second * p2.second * 2;
	int g = gcd(a, b);
	a /= g, b /= g;
	return { a,b };
}
void init()
{
	int n, o;
	while (cin >> n)
	{
		vector<pair<int, int>> vp;
		for (int i = 0; i < n; i++)
		{
			cin >> o;
			vp.emplace_back(o, 1);
		}
		queue< vector<pair<int, int>> > q;
		map< vector<pair<int, int>>, int > mc;
		q.push(vp);
		mc[vp] = 1;
		while (!q.empty())
		{
			auto v = q.front();
			q.pop();
			if (v.size() == 1)
				for (int i = 0; i < v.size(); i++)
					printf("%d/%d%c", v[i].first, v[i].second, " \n"[i + 1 == v.size()]);
			for (int i = 0; i + 1 < v.size(); i++)
			{
				vector<pair<int, int>> v0;
				for (int j = 0; j < v.size(); j++)
				{
					if (j != i) v0.push_back(v[j]);
					else v0.push_back(getsum(v[j], v[j + 1])), j++;
				}
				if (mc.count(v0)) continue;
				mc[v0] = 1;
				q.push(v0);
			}
		}
	}
}
bool check(vector<int> v)
{
	while (v.front() == v.back())
	{
		int x = v.back();
		while (!v.empty() && v.back() == x)
			v.pop_back();
		if (v.empty()) return false;
		v.pop_back();
		if (v.empty()) return true;
	}
	return true;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//init();
	int ncase;
	scanf("%d", &ncase);
	while (ncase--)
	{
		int n;
		scanf("%d", &n);
		vector<int> v(n);
		for (auto& x : v)
			scanf("%d", &x);
		if (check(v))
		{
			puts("Yes");
			continue;
		}
		//while (v.size() >= 2 && v[v.size() - 1] == v[v.size() - 2])
		//	v.pop_back();
		//reverse(v.begin(), v.end());
		//while (v.size() >= 2 && v[v.size() - 1] == v[v.size() - 2])
		//	v.pop_back();
		int cnt = 1;
		for (int i = 1; i < v.size(); i++)
		{
			if (v[i] != v[i - 1])
				cnt++;
		}
		if (cnt >= 9)
		{
			puts("Yes");
		}
		else puts("No");

	}
	return 0;
}
0