結果

問題 No.699 ペアでチームを作ろう2
ユーザー GrenacheGrenache
提出日時 2018-09-22 17:50:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 870 ms / 1,000 ms
コード長 1,930 bytes
コンパイル時間 4,090 ms
コンパイル使用メモリ 76,192 KB
実行使用メモリ 62,620 KB
最終ジャッジ日時 2023-09-25 11:12:28
合計ジャッジ時間 14,500 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,884 KB
testcase_01 AC 127 ms
55,572 KB
testcase_02 AC 194 ms
59,408 KB
testcase_03 AC 125 ms
55,648 KB
testcase_04 AC 296 ms
61,448 KB
testcase_05 AC 852 ms
62,236 KB
testcase_06 AC 850 ms
62,400 KB
testcase_07 AC 847 ms
62,492 KB
testcase_08 AC 787 ms
62,240 KB
testcase_09 AC 850 ms
62,216 KB
testcase_10 AC 847 ms
62,448 KB
testcase_11 AC 852 ms
62,568 KB
testcase_12 AC 856 ms
62,296 KB
testcase_13 AC 854 ms
62,620 KB
testcase_14 AC 870 ms
62,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder699_1 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		long max = 0;

		Deque<List<Integer>> st = new ArrayDeque<>();
		List<Integer> ltmp = new ArrayList<>(n + 1);
		for (int i = 0; i < n; i++) {
			ltmp.add(i);
		}
		ltmp.add(1);
		st.push(ltmp);
		int cnt = 0;
		while (!st.isEmpty()) {
			List<Integer> e = st.pop();
			int size = e.get(n);

			if (size == n) {
//				pr.println(e);
				cnt++;

				long tmp = 0;
				long tmp2 = 0;
				for (int i = 0; i < n; i++) {
					if (i % 2 == 0) {
						tmp2 += a[e.get(i)];
					} else {
						tmp2 += a[e.get(i)];
						tmp ^= tmp2;
						tmp2 = 0;
					}
				}
				
				max = Math.max(max, tmp);
			} else {
				out:
				for (int i = size; i < n; i++) {
					List<Integer> ee = new ArrayList<>(e);
					
					if (size % 2 == 0) {
						for (int j = 0; j < size; j += 2) {
							if (ee.get(j) > ee.get(i)) {
								continue out;
							}
						}
						
						int tmp = ee.get(size); ee.set(size, ee.get(i)); ee.set(i, tmp);
						ee.set(n, ee.get(n) + 1);
					} else {
						if (ee.get(size - 1) > ee.get(i)) {
							continue out;
						}
						
						int tmp = ee.get(size); ee.set(size, ee.get(i)); ee.set(i, tmp);
						ee.set(n, ee.get(n) + 1);
					}

					st.push(ee);
				}
			}
		}

//		pr.println(cnt);
		pr.println(max);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0