-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcbarn.java
79 lines (64 loc) · 2.05 KB
/
cbarn.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;
class cows{
int shifted;
int count;
}
public class cbarn {
static void print(cows[] n){
for(int i = 0; i<n.length;i++){
System.out.print(n[i].count+" ");
}
System.out.println();
}
static void dostuff(cows[] stuff, int cur){
//print(stuff);
System.out.println("cur = "+cur);
cows m = stuff[cur];
int curshift = 0;
for(int i = 0; i<m.count;i++){
cows tobemapped = stuff[(m.shifted+i+cur)%stuff.length];
if(tobemapped.count>0&&m.shifted+i!=0){
tobemapped.shifted += m.shifted + m.count + curshift - 1;
//System.out.println(cur+i);
curshift += tobemapped.count - 1;
dostuff(stuff, (m.shifted + cur + i) % stuff.length);
}
cows newone = new cows();
newone.count = 1;
newone.shifted = i+m.shifted;
stuff[(m.shifted+cur+i)%stuff.length]= newone;
}
}
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader f = new BufferedReader(new FileReader("cbarn.in"));
// input file name goes above
BufferedWriter out = new BufferedWriter(new FileWriter("cbarn.out"));
int k = Integer.parseInt(f.readLine());
cows[] stuff = new cows[k];
for(int i = 0; i<k;i++){
int lmao = Integer.parseInt(f.readLine());
stuff[i] = new cows();
stuff[i].count=lmao;
}
for(int i = 0; i<k;i++){
if(stuff[i].count>1) {
if(i==7){
System.out.println("yo");
}
print(stuff);
dostuff(stuff, i);
}
}
int count = 0;
print(stuff);
for(cows m:stuff){
count+=m.shifted*m.shifted;
}
out.write(count+"\n");
System.out.println(count);
out.close();
}
}