結果

問題 No.774 tatyamと素数大富豪
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-01-25 02:54:32
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 1,130 bytes
コンパイル時間 3,821 ms
コンパイル使用メモリ 87,828 KB
実行使用メモリ 63,760 KB
最終ジャッジ日時 2024-09-16 04:45:07
合計ジャッジ時間 22,746 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 TLE * 1
other AC * 13 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class y774 {
  public static void main(String[] args) { new y774().run(); }
  Scanner in = new Scanner(System.in);
  void _out(Object...os) { System.out.println(deepToString(os)); }
  void _err(Object...os) { System.err.println(deepToString(os)); }

  int N;
  String[] A;
  
  BigInteger ans;
  
  void run() {
    for (; in.hasNext(); ) {
      N = in.nextInt();
      A = new String[N];
      for (int i = 0; i < N; ++i) {
        A[i] = in.next();
      }
      ans = valueOf(-1);
      dfs(0, 0, "");
      System.out.println(ans);
    }
  }
  
  void dfs(int i, int used, String s) {
    if (i == N) {
      BigInteger x = new BigInteger(s);
      if (ans.compareTo(x) < 0) {
        if (x.isProbablePrime(100)) {
          ans = x;
        }
      }
    } else {
      for (int j = 0; j < N; ++j) {
        if (((used >> j) & 1) == 0) {
          dfs(i + 1, used | 1 << j, s + A[j]);
        }
      }
    }
  }
}
0