結果

問題 No.3024 等式
ユーザー kotatsugamekotatsugame
提出日時 2020-03-09 08:21:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,357 ms / 5,000 ms
コード長 1,562 bytes
コンパイル時間 940 ms
コンパイル使用メモリ 86,508 KB
実行使用メモリ 262,128 KB
最終ジャッジ日時 2023-09-12 16:18:22
合計ジャッジ時間 13,455 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 65 ms
8,504 KB
testcase_13 AC 65 ms
8,656 KB
testcase_14 AC 83 ms
10,004 KB
testcase_15 AC 87 ms
9,956 KB
testcase_16 AC 76 ms
10,020 KB
testcase_17 AC 67 ms
8,884 KB
testcase_18 AC 2,479 ms
215,052 KB
testcase_19 AC 2,470 ms
213,232 KB
testcase_20 AC 3,357 ms
262,128 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 2,708 ms
224,652 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:11:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   11 | main()
      | ^~~~

ソースコード

diff #

#pragma GCC optimize("O3")
#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++)
	{
		for(int x=i&i-1;x>(i&~x);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));
				}
			}
		}
		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());
		//cout<<i<<endl;
		//for(pair<long,long>p:M[i])cout<<p.first<<"/"<<p.second<<", ";
		//cout<<endl;
	}
	for(int i=1;i+1<1<<N;i++)
	{
		int t=(1<<N)-1&~i;
		for(int j=t;j;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++;
			}
		}
	}
	cout<<"NO"<<endl;
}
0