[BOJ] 16971 배열 B의 값

Time Lapse :31min 43sec

16971.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <algorithm>
using namespace std;

int n, m, num, standard, minA = 987654321, minB = 987654321;
int A[1000], B[1000];

int main(void) {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
scanf("%d", &num);
B[j] += i == 0 || i == n - 1 ? num : num<<1;
A[i] += j == 0 || j == m - 1 ? num : num<<1;
if(i == n - 1 && j != 0 && j != m - 1)
minB = min(minB, B[j]), standard += B[j] << 1;
if(j == m - 1 && i != 0 && i != n - 1)
minA = min(minA, A[i]);
}
}
standard += B[0] + B[m-1];

printf("%d", max(standard, standard + max(max(A[0], A[n - 1]) - minA, max(B[0], B[m - 1]) - minB)));
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/26/PS/BOJ/16971/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.