/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 13ms 540.0 KiB
#3 Wrong Answer 32ms 540.0 KiB
#4 Wrong Answer 35ms 540.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  long double
#define ull unsigned long long
#define PI acos(-1.0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define rev_str(str) reverse(str.begin(),str.end());
#define print(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i =a ;i<b;i++)
#define per(i,b,a) for(ll i=b;i>=a;i--)
#define all(a)  (a.begin(),a.end())
#define srt(a) sort(all(a))
#define rsrt(a) sort(a.rbegin(),a.rend())
bool sortByValue(const pair<int,int>& a,const pair<int,int>& b){
    return a.second > b.second;
}
const ll N=10e5+5;

ll gcd(ll a,ll b){
    return b == 0 ? a : gcd(b, a%b);
}

ll lcm(ll a,ll b){
    return (a / gcd(a, b)) * b;
}


void solve(){
    ll n,m;cin>>n>>m;
    char p[n][m];
    map<char,ll>mp;
    map<char,ll>f;
    rep(i,0,n){
        rep(j,0,m){
            cin>>p[i][j];
            if(p[i][j]=='+') f[p[i][j]]++;
        }
    }
    //cout<<f['+']<<endl;
    if(f['+']==(n*m)){
        ll ki = min(n,m);
        cout<<ki+(ki-1)<<endl;return;
    }
    //set<ll>q;
    ll mx =0;
    rep(i,0,n){
        rep(j,0,m){
            if(p[i][j]=='+'){
                ll left = i;
                ll right = m;
                ll up = 0;
                ll down = n;
                ll one=0;
                ll two=0;
                ll three=0;
                ll four=0;
                rep(k,i+1,n){
                    if(p[k][j]=='+'){
                        one++;
                    }
                    else{
                        break;
                    }
                }
                per(k,i-1,0){
                    if(p[k][j]=='+'){
                        two++;
                    }
                    else{
                        break;
                    }
                }
                rep(k,j+1,m){
                    if(p[i][k]=='+'){
                        three++;
                    }
                    else{
                        break;
                    }
                }
                per(k,j-1,0){
                    if(p[i][k]=='+'){
                        four++;
                    }
                    else{
                        break;
                    }
                }
                ll ki = min(one,two);
                ll ji = min(three,four);
                ki*=2;
                ki++;
                ji*=2;
                ji++;
                ll mn = min(ki,ji);
                mx = max(mn,mx);
                //cout<<ki<<" "<<ji<<endl;
            }
        }
    }
    cout<<max(0LL,mx+(mx-1))<<endl;

}

int main(){
    fast;
    ll t=1;cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 07:43:59
Judged At
2024-12-09 07:43:59
Judged By
Score
4
Total Time
35ms
Peak Memory
540.0 KiB