結果
| 問題 |
No.699 ペアでチームを作ろう2
|
| ユーザー |
tenten
|
| 提出日時 | 2021-11-02 15:45:17 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,055 bytes |
| コンパイル時間 | 2,197 ms |
| コンパイル使用メモリ | 78,464 KB |
| 実行使用メモリ | 73,192 KB |
| 最終ジャッジ日時 | 2024-10-11 20:05:25 |
| 合計ジャッジ時間 | 11,147 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 2 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static int n;
static int[] values;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
n = sc.nextInt();
values = new int[n];
for (int i = 0; i < n; i++) {
values[i] = sc.nextInt();
}
System.out.println(check1(0, new boolean[n]).last());
}
static TreeSet<Integer> check1(int idx, boolean[] used) {
if (idx == n) {
TreeSet<Integer> ans = new TreeSet<>();
ans.add(0);
return ans;
}
TreeSet<Integer> ans = null;
for (int i = 0; i < n; i++) {
if (!used[i]) {
used[i] = true;
ans = check2(idx + 1, used, values[i]);
used[i] = false;
break;
}
}
return ans;
}
static TreeSet<Integer> check2(int idx, boolean[] used, int v) {
TreeSet<Integer> ans = new TreeSet<>();
for (int i = 0; i < n; i++) {
if (used[i]) {
continue;
}
used[i] = true;
TreeSet<Integer> tmp = check1(idx + 1, used);
for (int x : tmp) {
ans.add((v + values[i]) ^ x);
}
used[i] = false;
}
return ans;
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public String nextLine() throws Exception {
return br.readLine();
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten