結果

問題 No.3531 Erase Pair
コンテスト
ユーザー askr58
提出日時 2026-05-04 23:41:37
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 35 ms / 500 ms
コード長 1,296 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,949 ms
コンパイル使用メモリ 348,672 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-05-04 23:41:44
合計ジャッジ時間 6,417 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
bool solve(int n,vector<ll> a){
	vector<ll> b,c;
		for(int i=0;i<n;i++){
			if(a[i]<0)b.push_back(-a[i]);
			if(a[i]>0)c.push_back(a[i]);
		}
		int x=b.size(),y=c.size();
		if(n-x-y!=1){
			if(n-x-y==0)return true;
			else return false;
		}
	if(n%2==0)return false;
	if(x%2==0)return true;
	ranges::sort(b);
	ranges::sort(c);
	x/=2;y/=2;
	if(b[0]!=c[0])return true;
	int cnt1=0,cnt2=0;
	for(int t:b)if(t==b[0])cnt1++;
	for(int t:c)if(t==b[0])cnt2++;
	if(cnt1<x+1||cnt2<y+1)return true;
	int cnt3=0,cnt4=0;
	for(int i=0;i<2*x+1;i++){
		if(b[i]!=b[0]&&b[i]!=b[0]*2&&b[i]!=b[0]*3)return true;
		if(b[i]==2*b[0]){
			cnt3++;
		}
		if(b[i]==3*b[0])cnt4++;
	}
	if(cnt1<2*x+1&&cnt4>=1&&(cnt3%2==0||cnt4>1))return true;
	cnt3=0;cnt4=0;
	swap(cnt1,cnt2);
	swap(x,y);
	swap(b,c);
	for(int i=0;i<2*x+1;i++){
		if(b[i]!=b[0]&&b[i]!=b[0]*2&&b[i]!=b[0]*3)return true;
		if(b[i]==2*b[0]){
			cnt3++;
		}
		if(b[i]==3*b[0])cnt4++;
	}
	if(cnt1<2*x+1&&cnt4>=1&&(cnt3%2==0||cnt4>1))return true;
	return false;
}
	
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int ttt;
	cin>>ttt;
	while(ttt--){
		int n;
		cin>>n;
		vector<ll> a(n);
		for(int i=0;i<n;i++)cin>>a[i];
		if(solve(n,a))cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}


0