結果

問題 No.2343 (l+r)/2
ユーザー Heart_BlueHeart_Blue
提出日時 2023-06-09 21:34:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,251 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 143,508 KB
実行使用メモリ 814,432 KB
最終ジャッジ日時 2023-08-30 12:58:16
合計ジャッジ時間 5,271 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 MLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

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 >> o)
	{
		vector<pair<int, int>> vp;
		for (int i = 0; i < n; i++)
		{
			vp.emplace_back(o, 1);
			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);
			}
		}
	}
}
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 (v[0] != v[n - 1])
		{
			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 flag = 0;
		for (int i = 1; i < v.size(); i++)
		{
			if (v[i] == v[i - 1])
				flag = 1;
		}
		if (flag || v.size() >= 9)
		{
			puts("Yes");
		}
		else puts("No");

	}
	return 0;
}
0