-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombo.java
More file actions
69 lines (66 loc) · 2.23 KB
/
combo.java
File metadata and controls
69 lines (66 loc) · 2.23 KB
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
/*
ID: j.jonny1
LANG: JAVA
TASK: combo
*/
import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;
public class combo {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("combo.in"));
PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter("combo.out")));
//Scanner reader = new Scanner(System.in);
int n = Integer.parseInt(reader.readLine());
if(n <= 5)
{
writer.println(n * n * n);
reader.close();
writer.close();
return;
}
int[] combo = new int[3];
int[] master = new int[3];
StringTokenizer st = new StringTokenizer(reader.readLine());
for(int i = 0; i < 3; i++)
{
combo[i] = Integer.parseInt(st.nextToken());
}
st = new StringTokenizer(reader.readLine());
for(int i = 0; i < 3; i++)
{
master[i] = Integer.parseInt(st.nextToken());
}
HashSet<Integer>[] combolist = new HashSet[3];
HashSet<Integer>[] masterlist = new HashSet[3];
for(int i = 0; i < 3; i++)
{
combolist[i] = new HashSet<Integer>();
for(int j = -2; j <= 2; j++) {
if (combo[i] + j < 0) combolist[i].add(combo[i] + j + n);
else combolist[i].add((combo[i] + j) % n);
}
}
for(int i = 0; i < 3; i++)
{
masterlist[i] = new HashSet<Integer>();
for(int j = -2; j <= 2; j++) {
if (master[i] + j < 0) masterlist[i].add(master[i] + j + n);
else masterlist[i].add((master[i] + j) % n);
}
}
writer.println(250 - sameTerms(combolist[0], masterlist[0]) * sameTerms(combolist[1], masterlist[1]) * sameTerms(combolist[2], masterlist[2]));
reader.close();
writer.close();
}
public static int sameTerms(HashSet<Integer> a, HashSet<Integer> b)
{
int count = 0;
for(int i : a)
{
if(b.contains(i)) count++;
}
return count;
}
}