結果
| 問題 |
No.699 ペアでチームを作ろう2
|
| ユーザー |
tenten
|
| 提出日時 | 2022-10-19 09:40:40 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 95 ms / 1,000 ms |
| コード長 | 1,807 bytes |
| コンパイル時間 | 2,079 ms |
| コンパイル使用メモリ | 77,580 KB |
| 実行使用メモリ | 38,992 KB |
| 最終ジャッジ日時 | 2024-06-29 13:21:15 |
| 合計ジャッジ時間 | 4,037 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static int max = 0;
static int[] values;
static int n;
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();
}
calc(0, new boolean[n], 0);
System.out.println(max);
}
static void calc(int idx, boolean[] used, int sum) {
if (idx >= n) {
max = Math.max(max, sum);
return;
}
for (int i = 0; i < n; i++) {
if (used[i]) {
continue;
}
used[i] = true;
for (int j = i + 1; j < n; j++) {
if (used[j]) {
continue;
}
used[j] = true;
calc(idx + 2, used, sum ^ (values[i] + values[j]));
used[j] = false;
}
used[i] = false;
break;
}
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten