/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 768.0 KiB
#2 Accepted 19ms 844.0 KiB
#3 Accepted 35ms 608.0 KiB
#4 Accepted 38ms 556.0 KiB
#5 Accepted 30ms 612.0 KiB
#6 Accepted 5ms 588.0 KiB
#7 Accepted 16ms 328.0 KiB
#8 Accepted 68ms 540.0 KiB
#9 Accepted 66ms 796.0 KiB
#10 Accepted 66ms 852.0 KiB
#11 Accepted 15ms 796.0 KiB
#12 Accepted 16ms 1.57 MiB
#13 Accepted 369ms 1.676 MiB
#14 Accepted 18ms 1.52 MiB
#15 Accepted 468ms 1.676 MiB
#16 Accepted 20ms 1.5 MiB
#17 Accepted 21ms 1.562 MiB
#18 Accepted 1641ms 1.68 MiB
#19 Accepted 36ms 1.527 MiB
#20 Accepted 1440ms 1.676 MiB
#21 Accepted 58ms 4.543 MiB
#22 Time Exceeded ≥2092ms ≥4.617 MiB
#23 Time Exceeded ≥2099ms ≥4.617 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;
        }
        
    }
    map<ll,ll>bolo,koro;
    rep(i,0,n){
        ll an =0,nts =0;
        rep(j,0,m){
            if(p[i][j]=='+'){
                an++;
            }
            else{
                nts = max(nts,an);
                an =0;
            }
        }
        bolo[i]=nts;
    }
    rep(j,0,m){
        ll an =0,nts =0;
        rep(i,0,n){
            if(p[i][j]=='+'){
                an++;
            }
            else{
                nts = max(nts,an);
                an =0;
            }
        }
        koro[j]=nts;
    }
    //set<ll>q;
    vii a(bolo.begin(),bolo.end());
    vii b(koro.begin(),koro.end());
    sort(a.begin(),a.end(),sortByValue);
    sort(b.begin(),b.end(),sortByValue);
    vi kii,naruto;
    for(auto [x,y]:a){
        kii.push_back(x);
    }
    for(auto [x,y]:b){
        naruto.push_back(x);
    }
    ll mx =0;
    rep(lala,0,kii.size()){
        rep(lili,0,naruto.size()){
            ll i = kii[lala];
            ll j = naruto[lili];
                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 08:23:41
Judged At
2024-12-09 08:23:41
Judged By
Score
64
Total Time
≥2099ms
Peak Memory
≥4.617 MiB