結果
| 問題 | No.698 ペアでチームを作ろう |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-02 15:23:51 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 103 ms / 1,000 ms |
| コード長 | 1,825 bytes |
| 記録 | |
| コンパイル時間 | 2,318 ms |
| コンパイル使用メモリ | 76,768 KB |
| 実行使用メモリ | 38,904 KB |
| 最終ジャッジ日時 | 2024-10-11 19:31:48 |
| 合計ジャッジ時間 | 4,382 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
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]));
}
static int check1(int idx, boolean[] used) {
if (idx == n) {
return 0;
}
int ans = 0;
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 int check2(int idx, boolean[] used, int v) {
int max = 0;
for (int i = 0; i < n; i++) {
if (used[i]) {
continue;
}
used[i] = true;
max = Math.max(max, (v ^ values[i]) + check1(idx + 1, used));
used[i] = false;
}
return max;
}
}
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