/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 584.0 KiB
#2 Accepted 13ms 492.0 KiB
#3 Accepted 31ms 328.0 KiB
#4 Accepted 52ms 564.0 KiB
#5 Accepted 25ms 540.0 KiB
#6 Accepted 5ms 540.0 KiB
#7 Accepted 20ms 556.0 KiB
#8 Accepted 47ms 540.0 KiB
#9 Accepted 45ms 848.0 KiB
#10 Accepted 45ms 660.0 KiB
#11 Accepted 15ms 540.0 KiB
#12 Accepted 16ms 1.277 MiB
#13 Accepted 314ms 1.492 MiB
#14 Accepted 16ms 1.277 MiB
#15 Accepted 516ms 1.496 MiB
#16 Accepted 17ms 1.57 MiB
#17 Accepted 23ms 1.539 MiB
#18 Accepted 1588ms 1.527 MiB
#19 Accepted 25ms 1.277 MiB
#20 Accepted 1405ms 1.508 MiB
#21 Accepted 59ms 4.371 MiB
#22 Time Exceeded ≥2096ms ≥4.32 MiB
#23 Time Exceeded ≥2096ms ≥4.277 MiB

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);
        if(ki&1){
            cout<<ki+(ki-1)<<endl;return;
        }
        else{
            ki--;
            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:49:57
Judged At
2024-12-09 07:49:57
Judged By
Score
64
Total Time
≥2096ms
Peak Memory
≥4.371 MiB