結果

問題 No.3024 等式
ユーザー kotatsugamekotatsugame
提出日時 2020-03-09 08:12:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,512 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 83,608 KB
実行使用メモリ 497,172 KB
最終ジャッジ日時 2024-04-25 10:11:11
合計ジャッジ時間 18,098 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 107 ms
15,460 KB
testcase_13 AC 109 ms
15,336 KB
testcase_14 AC 144 ms
17,816 KB
testcase_15 AC 150 ms
17,952 KB
testcase_16 AC 132 ms
17,824 KB
testcase_17 AC 115 ms
14,772 KB
testcase_18 AC 4,731 ms
386,728 KB
testcase_19 AC 4,682 ms
387,408 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
vector<pair<long,long> >M[1<<7];
int N;
long A[7];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		M[1<<i].push_back(make_pair(A[i],1));
	}
	for(int i=1;i+1<1<<N;i++)
	{
		if(__builtin_popcount(i)>1)
		{
			for(int x=i;;x=x-1&i)
			{
				int y=i&~x;
				for(const pair<long,long>&X:M[x])
				{
					for(const pair<long,long>&Y:M[y])
					{
						M[i].push_back(make_pair(X.first*Y.second+Y.first*X.second,X.second*Y.second));
						M[i].push_back(make_pair(X.first*Y.second-Y.first*X.second,X.second*Y.second));
						M[i].push_back(make_pair(-X.first*Y.second+Y.first*X.second,X.second*Y.second));
						M[i].push_back(make_pair(X.first*Y.first,X.second*Y.second));
						M[i].push_back(make_pair(X.first*Y.second,X.second*Y.first));
						M[i].push_back(make_pair(Y.first*X.second,Y.second*X.first));
					}
				}
				if(x==0)break;
			}
		}
		for(pair<long,long>&p:M[i])
		{
			long g=gcd(p.first,p.second);
			p.first/=g;
			p.second/=g;
		}
		sort(M[i].begin(),M[i].end());
		M[i].erase(unique(M[i].begin(),M[i].end()),M[i].end());
	}
	for(int i=1;i+1<1<<N;i++)
	{
		int t=(1<<N)-1&~i;
		for(int j=t;;j=j-1&t)
		{
			int ii=0,jj=0;
			while(ii<M[i].size()&&jj<M[j].size())
			{
				if(M[i][ii]==M[j][jj])
				{
					cout<<"YES"<<endl;
					return 0;
				}
				else if(M[i][ii]<M[j][jj])ii++;
				else jj++;
			}
			if(j==0)break;
		}
	}
	cout<<"NO"<<endl;
}
0