用户输出
1
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#70291 | #1086. jwp的幸运集合 | Accepted | 100 | 1156 ms | 26116 K | Java / 2.6 K | Rhodoks | 2022-06-28 8:52:15 |
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Read in = new Read();
int n = in.nextInt();
int k = n / 2;
int m = n - k;
int[] b = in.readArray(k);
int[] c = in.readArray(m);
Map<Integer, int[]> c1 = new HashMap<>();
Map<Integer, int[]> c2 = new HashMap<>();
for (int i = 0; i < (1 << k); i++) {
int now = 0;
int cnt = 0;
for (int j = 0; j < k; j++) {
if (((i >> j) & 1) == 1) {
now += b[j];
cnt++;
}
}
if (!c1.containsKey(now)) {
c1.put(now, new int[2]);
}
if (cnt % 2 == 0) {
c1.get(now)[0]++;
} else
c1.get(now)[1]++;
}
for (int i = 0; i < (1 << m); i++) {
int now = 0;
int cnt = 0;
for (int j = 0; j < m; j++) {
if (((i >> j) & 1) == 1) {
now += c[j];
cnt++;
}
}
if (!c2.containsKey(now)) {
c2.put(now, new int[2]);
}
if (cnt % 2 == 0) {
c2.get(now)[0]++;
} else
c2.get(now)[1]++;
}
long res = 0;
for (int x : c1.keySet()) {
if (c2.containsKey(-x)) {
res += (long) c1.get(x)[0] * c2.get(-x)[0];
res += (long) c1.get(x)[1] * c2.get(-x)[1];
}
}
System.out.println(res - 1);
}
static class Read {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens()) try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
char nextChar() {
return next().charAt(0);
}
}
}
31
749 349 69 -880 282 -926 -831 225 988 552 -193 634 369 476 204 487 387 -803 -370 -975 -17 -485 3
<40 bytes omitted>
用户输出
260459
系统信息
Exited with return code 0
31
362 -14 -181 -465 -400 -232 26 963 70 728 -728 -222 -510 854 139 386 555 994 103 279 213 76 953
<36 bytes omitted>
用户输出
81861
系统信息
Exited with return code 0
用户输出
16383
系统信息
Exited with return code 0