結果

問題 No.12 限定された素数
ユーザー kotatsugamekotatsugame
提出日時 2019-10-14 02:41:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 592 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 65,156 KB
実行使用メモリ 8,556 KB
最終ジャッジ日時 2023-08-16 01:00:37
合計ジャッジ時間 2,690 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
8,232 KB
testcase_01 AC 42 ms
8,276 KB
testcase_02 AC 41 ms
8,356 KB
testcase_03 AC 41 ms
8,244 KB
testcase_04 AC 41 ms
8,244 KB
testcase_05 AC 42 ms
8,352 KB
testcase_06 AC 41 ms
8,288 KB
testcase_07 AC 44 ms
8,556 KB
testcase_08 AC 41 ms
8,248 KB
testcase_09 AC 41 ms
8,352 KB
testcase_10 AC 43 ms
8,248 KB
testcase_11 AC 42 ms
8,252 KB
testcase_12 AC 43 ms
8,424 KB
testcase_13 AC 42 ms
8,232 KB
testcase_14 AC 42 ms
8,296 KB
testcase_15 AC 42 ms
8,276 KB
testcase_16 AC 43 ms
8,432 KB
testcase_17 AC 42 ms
8,420 KB
testcase_18 AC 43 ms
8,288 KB
testcase_19 AC 42 ms
8,240 KB
testcase_20 AC 42 ms
8,220 KB
testcase_21 AC 42 ms
8,252 KB
testcase_22 AC 42 ms
8,344 KB
testcase_23 AC 42 ms
8,232 KB
testcase_24 AC 42 ms
8,216 KB
testcase_25 AC 42 ms
8,340 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:16:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   16 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
const int MAX=5000000;
bool isp[MAX+1];
int ok;
int f(int X)
{
	int ret=0;
	while(X)
	{
		ret|=1<<X%10;
		X/=10;
	}
	return ret;
}
main()
{
	int N;cin>>N;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;ok|=1<<a;
	}
	int ans=-1,pre=1,now=0;
	for(int i=2;i<=MAX;i++)isp[i]=true;
	for(int i=2;i<=MAX;i++)
	{
		if(isp[i])
		{
			int x=f(i);
			if(~ok&x)
			{
				if(now==ok)
				{
					ans=max(ans,i-1-pre);
				}
				now=0;
				pre=i+1;
			}
			else now|=x;
			for(int j=i+i;j<=MAX;j+=i)isp[j]=false;
		}
	}
	if(now==ok)ans=max(ans,MAX-pre);
	cout<<ans<<endl;
}
0