結果

問題 No.689 E869120 and Constructing Array 3
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-05-19 00:17:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 1,000 ms
コード長 1,013 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 99,384 KB
実行使用メモリ 11,704 KB
最終ジャッジ日時 2023-09-10 23:28:10
合計ジャッジ時間 2,759 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
11,584 KB
testcase_01 AC 17 ms
11,644 KB
testcase_02 AC 17 ms
11,580 KB
testcase_03 AC 18 ms
11,524 KB
testcase_04 AC 20 ms
11,632 KB
testcase_05 AC 17 ms
11,600 KB
testcase_06 AC 17 ms
11,500 KB
testcase_07 AC 17 ms
11,528 KB
testcase_08 AC 19 ms
11,528 KB
testcase_09 AC 23 ms
11,512 KB
testcase_10 AC 18 ms
11,704 KB
testcase_11 AC 19 ms
11,600 KB
testcase_12 AC 20 ms
11,576 KB
testcase_13 AC 17 ms
11,512 KB
testcase_14 AC 18 ms
11,676 KB
testcase_15 AC 17 ms
11,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<iostream>
#include<random>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int N=2100000;
int pr[N];
void init(){
  for(int i=2;i<N;++i)pr[i]=1;
  for(int i=2;i*i<N;++i){
    if(!pr[i])continue;
    for(int j=2;j*i<N;++j)pr[i*j]=0;
  }
}

int main(){
  init();
  int k;
  cin>>k;
  mt19937 mt(0xe869120);
  int w=250/2;
  int trial=0;
  while(1){
    trial++;
    if(trial%100==0)cerr<<"try " << trial<<endl;
    vi e(w),o(w);
    rep(i,w){
      do{
	e[i]=2*(mt()%10)+2;
      }while(e[i]%3==1);
    }
    rep(i,w){
      do{
	o[i]=2*(mt()%10)+1;
      }while(o[i]%3==1);
    }
    int sum=0;
    rep(i,w){
      rep(j,i){
	sum+=pr[e[i]+o[j]];
	sum+=pr[e[j]+o[i]];
      }
      sum+=pr[e[i]+o[i]];
      if(sum==k){
	//found
	cout<<2*(i+1)<<endl;
	rep(j,i+1)cout<<e[j]<<" ";
	rep(j,i+1)cout<<o[j]<<(j==i?"\n":" ");
	return 0;
      }
      if(sum>k)break;
    }
  }
}
0