-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_14391
More file actions
60 lines (51 loc) · 1.64 KB
/
BAEKJOON_14391
File metadata and controls
60 lines (51 loc) · 1.64 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
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw =new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] arr =new int[N][M];
for(int i=0; i<N; i++){
StringBuilder sb= new StringBuilder(br.readLine());
for(int j=0; j<M; j++){
arr[i][j] = sb.charAt(j)-48;
}
}
int max=0;
int ans =0;
for(int s=0; s<(1<<N*M); s++){
int sum=0;
for(int i=0; i<N; i++){
int cur=0;
for(int j=0; j<M; j++){
int k =i*M+j;
if((s&(1<<k))==0){
cur = cur * 10 +arr[i][j];
}else{
sum+=cur;
cur=0;
}
}
sum+=cur;
}
for(int j=0; j<M; j++){
int cur=0;
for(int i=0; i<N; i++){
int k =i*M+j;
if((s&(1<<k))!=0){
cur=cur * 10 +arr[i][j];
}else{
sum+=cur;
cur=0;
}
}
sum+=cur;
}
ans = Math.max(ans,sum);
}
System.out.println(ans);
}
}