-
Notifications
You must be signed in to change notification settings - Fork 6
/
Stonegame.java
56 lines (56 loc) · 1.6 KB
/
Stonegame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class Stonegame
{
public static void main (String [] args) throws Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
int n=Integer.parseInt(st.nextToken());
st = new StringTokenizer(in.readLine());
int[] p=new int[n];
for(int i=0;i<n;i++) {
p[i]=Integer.parseInt(st.nextToken());
}
int[] sub=new int[n];
long total=0;
for(;;) {
if(check(p,sub)) {
if(somethingSame(sub)) {
total++;
}
}
sub=addOne(sub,0,p);
if(sub.length==0) break;
}
System.out.println((int)(total%1000000007));
}
private static boolean somethingSame(int[] b) {
for(int i=0;i<b.length;i++) {
if(b[i]==0) return true;
}
return false;
}
private static int[] addOne(int[] sub,int which,int[] max) {
if(which>=sub.length) return new int[0];
sub[which]++;
if(sub[which]>max[which]) {
sub[which]=0;
return addOne(sub,which+1,max);
}
return sub;
}
private static boolean check(int[] nums,int[] sub) {
int total=0;
for(int i=0;i<nums.length;i++) total^=nums[i]-sub[i];
return total==0;
}
private static int mul(long a,long b) {
long both=a*b;
both%=1000000007;
return (int)both;
}
}