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 | #include <iostream> #include <stdio.h> #include <vector> #pragma warning (disable : 4996) using namespace std; int main() { int M, N; cin >> M >> N; vector<vector<int> > ary(M, vector<int>(N)); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) scanf("%d", &ary[i][j]); } int result = 0; for (int i = 0; i < M; i++) { bool cool = false; for (int j = 0; j < N; j++) { if (ary[i][j] == 1) cool = true; else if (ary[i][j] == 0 && cool == true) result++; } cool = false; for (int j = N-1; j > -1; j--) { if (ary[i][j] == 1) cool = true; else if (ary[i][j] == 0 && cool == true) result++; } } for (int j = 0; j < N; j++) { bool cool = false; for (int i = 0; i < M; i++) { if (ary[i][j] == 1) cool = true; else if (ary[i][j] == 0 && cool == true) result++; } cool = false; for (int i = M - 1; i > -1; i--) { if (ary[i][j] == 1) cool = true; else if (ary[i][j] == 0 && cool == true) result++; } } cout << result; return 0; } | cs |
'Algorithm Problems > Codeforces' 카테고리의 다른 글
[#380 Virtual Test] A. Interview with Oleg [C++] ☆ (0) | 2016.12.28 |
---|---|
[#388] B. Parallelogram is Back [C++] (0) | 2016.12.20 |
[#388] A. Bachgold Problem [C++] (0) | 2016.12.20 |