/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 11ms 880.0 KiB
#3 Accepted 7ms 796.0 KiB
#4 Accepted 7ms 632.0 KiB
#5 Accepted 9ms 540.0 KiB
#6 Accepted 7ms 540.0 KiB
#7 Accepted 21ms 540.0 KiB
#8 Accepted 39ms 840.0 KiB
#9 Accepted 41ms 1.23 MiB
#10 Accepted 41ms 1.027 MiB
#11 Accepted 22ms 1.035 MiB
#12 Accepted 24ms 5.332 MiB
#13 Accepted 24ms 5.324 MiB
#14 Accepted 24ms 5.312 MiB
#15 Accepted 24ms 5.52 MiB
#16 Accepted 24ms 5.355 MiB
#17 Accepted 30ms 5.281 MiB
#18 Accepted 24ms 5.289 MiB
#19 Accepted 34ms 5.312 MiB
#20 Accepted 27ms 5.277 MiB
#21 Accepted 136ms 19.934 MiB
#22 Accepted 137ms 19.953 MiB
#23 Accepted 152ms 19.703 MiB
#24 Accepted 149ms 19.816 MiB
#25 Accepted 224ms 19.816 MiB
#26 Accepted 158ms 19.816 MiB
#27 Accepted 151ms 19.82 MiB
#28 Accepted 156ms 19.82 MiB
#29 Accepted 140ms 19.82 MiB
#30 Accepted 138ms 19.699 MiB

Code

#include<bits/stdc++.h>
using namespace std; 
using i64 = long long;

void solve() {
    int n, m; cin >> n >> m;
    vector<vector<char>> s(n, vector<char> (m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> s[i][j];
        }
    }
    vector<vector<int>> Max(n, vector<int> (m, n));
    for (int i = 0; i < n; i++) {
        int cur = 0;
        for (int j = 0; j < m; j++) {
            cur += (s[i][j] == '+' ? 1 : -cur);
            Max[i][j] = min(Max[i][j], cur);
        }
        cur = 0;
        for (int j = m -1; j >= 0; j--) {
            cur += (s[i][j] == '+' ? 1 : -cur);
            Max[i][j] = min(Max[i][j], cur);
        }
    }
    for (int j = 0; j < m; j++) {
        int cur = 0;
        for (int i = 0; i < n; i++) {
            cur += (s[i][j] == '+' ? 1 : -cur);
            Max[i][j] = min(Max[i][j], cur);
        }
        cur = 0;
        for (int i = n -1; i >= 0; i--) {
            cur += (s[i][j] == '+' ? 1 : -cur);
            Max[i][j] = min(Max[i][j], cur);
        }
    }
    int ans = 0;
    for (auto& r : Max) {
        for (auto& c : r) ans = max(ans, c);
    }
    if (ans) {
        cout << 1 + 4 * (ans - 1) << '\n';
    } else {
        cout << 0 << '\n';
    }
} 

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt = 1;
    cin >> tt;
    for(int t = 1; t <= tt; t++) {
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Contest
LU IUJPC : Sylhet Division 2024 Replay Contest
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-10 10:42:33
Judged At
2024-12-10 10:42:33
Judged By
Score
100
Total Time
224ms
Peak Memory
19.953 MiB