-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day13p1.java
79 lines (72 loc) · 2.32 KB
/
Day13p1.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.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static Scanner sc = new Scanner(System.in);
public static PrintWriter out = new PrintWriter(System.out);
public static void solve() throws IOException {
String line;
long ans = 0;
int idx = 0;
ArrayList<String> temp = new ArrayList<>();
while ((line = br.readLine()) != null) {
idx = 0;
temp = new ArrayList<>();
while(line != null && !line.equals("")) {
temp.add(line);
idx++;
line = br.readLine();
}
int m = temp.size();
int n = temp.get(0).length();
char[][] arr = new char[m][n];
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
arr[i][j] = temp.get(i).charAt(j);
}
}
boolean found = false;
for(int i = 0; i < m-1 && !found; i++) {
idx = 0;
boolean curr = true;
while(i-idx >= 0 && i+idx+1 < m && curr) {
for(int j = 0; j < n; j++) {
if(arr[i-idx][j] != arr[i+idx+1][j]) {
curr = false;
break;
}
}
idx++;
}
if(curr) {
ans += 100*(i+1);
found = true;
}
}
if(found) continue;
for(int j = 0; j < n-1; j++) {
idx = 0;
boolean curr = true;
while(j-idx >= 0 && j+idx+1 < n && curr) {
for(int i = 0; i < m; i++) {
if(arr[i][j-idx] != arr[i][j+idx+1]) {
curr = false;
break;
}
}
idx++;
}
if(curr) {
ans += (j+1);
}
}
}
out.println(ans);
}
public static void main (String[] args) throws IOException {
solve();
out.close();
}
}