/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 588.0 KiB
#2 Accepted 14ms 720.0 KiB
#3 Accepted 9ms 796.0 KiB
#4 Accepted 9ms 788.0 KiB
#5 Accepted 11ms 796.0 KiB
#6 Accepted 9ms 796.0 KiB
#7 Accepted 25ms 540.0 KiB
#8 Accepted 48ms 540.0 KiB
#9 Accepted 47ms 2.441 MiB
#10 Accepted 50ms 2.148 MiB
#11 Accepted 32ms 2.223 MiB
#12 Accepted 37ms 16.77 MiB
#13 Accepted 33ms 16.828 MiB
#14 Accepted 30ms 16.977 MiB
#15 Accepted 36ms 16.812 MiB
#16 Accepted 30ms 16.75 MiB
#17 Accepted 30ms 16.754 MiB
#18 Accepted 37ms 17.094 MiB
#19 Accepted 47ms 17.008 MiB
#20 Accepted 38ms 16.75 MiB
#21 Accepted 254ms 65.617 MiB
#22 Accepted 255ms 65.812 MiB
#23 Accepted 257ms 65.84 MiB
#24 Accepted 250ms 65.828 MiB
#25 Accepted 264ms 65.621 MiB
#26 Accepted 267ms 65.836 MiB
#27 Accepted 263ms 65.836 MiB
#28 Accepted 266ms 65.832 MiB
#29 Accepted 258ms 65.621 MiB
#30 Accepted 257ms 66.02 MiB

Code

#include <bits/stdc++.h>
//#define int long long 
#define ll long long
#define ull unsigned long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define max_ele(v) *max_element(v.begin(), v.end())
#define min_ele(v) *min_element(v.begin(), v.end())
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v) reverse(v.begin(), v.end())
#define REV_SORT(v) sort((v).begin(), (v).end(), greater<>())
#define all(v) v.begin(), v.end()
#define vint vector<int>
#define u_set unordered_set
#define u_map unordered_map
#define setbit(x) __builtin_popcount(x)
#define lead_zero(x) __builtin_clz(x) 
#define trail_zero(x) __builtin_ctz(x) 
#define coutall(v) for(auto &&it : v) cout << it <<" "
#define coutnl(v) for(auto &&it : v) cout << it <<'\n'
#define cinall(v) for(auto &&it : v) cin >> it
#define cin2d(v) for(auto &&row : v) for(auto &&element : row) cin >> element;
#define cout2d(v) for (const auto& row : v) { for (const auto& element : row) cout << element << ' '; cout << '\n';}
#define nl cout << '\n';
using namespace std;
int cerrr = 1;
#define err cerr << "Thats GFG! " << cerrr++ << '\n'
const ll Inf = 0x3fffffffffffffff;
const int mod = 0x3b9aca07;

void debug_mode(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}

void solve();
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    //debug_mode();
    int TestCase = 1;
    cin >> TestCase; 
    int case_no = 1;
    while (TestCase--){
        // cout << "Case " << case_no++ << ": ";
        solve();
        // cout << '\n';
    }
    return 0;
}

void solve(){
    int r, c; cin >> r >> c;
    char grid[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++)
            cin >> grid[i][j];
    }
    vector<vint> lr(r, vint(c)), rl(r, vint(c)), ud(r, vint(c)), du(r, vint(c));
    
    //going left to right
    for(int i = 0; i < r; i++){
        for(int j = 1; j < c; j++){
            if(grid[i][j] == '+' and grid[i][j - 1] == '+'){
                lr[i][j] = lr[i][j - 1] + 1;
            }
        }
    }
    //going right to left
    for(int i = 0; i < r; i++){
        for(int j = c - 2; j >= 0; j--){
            if(grid[i][j] == '+' and grid[i][j + 1] == '+'){
                rl[i][j] = rl[i][j + 1] + 1;
            }
        }
    }
    //going up to down
    for(int i = 0; i < c; i++){
        for(int j = 1; j < r; j++){
            if(grid[j][i] == '+' and grid[j - 1][i] == '+'){
                ud[j][i] = ud[j - 1][i] + 1;
            }
        }
    }
    //going down to up
    for(int i = 0; i < c; i++){
        for(int j = r - 2; j >= 0; j--){
            if(grid[j][i] == '+' and grid[j + 1][i] == '+'){
                du[j][i] = du[j + 1][i] + 1;
            }
        }
    }
    int mx = 0;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(grid[i][j] == '-') continue;
            int mn = min(lr[i][j], min(rl[i][j], min(ud[i][j], du[i][j])));
            mx = max(mx, (mn * 4) + 1);
        }
    }
    cout << mx << '\n';
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-10 14:16:08
Judged At
2024-12-10 14:16:08
Judged By
Score
100
Total Time
267ms
Peak Memory
66.02 MiB