/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 12ms 600.0 KiB
#3 Wrong Answer 7ms 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);
        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;
            }
        }
        nts = max(nts,an);
        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;
            }
        }
        nts = max(nts,an);
        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);
    // for(auto [x,y]:bolo){
    //     cout<<x<<" "<<y<<endl;
    // }
    vi kii,naruto;
    for(auto [x,y]:a){
        kii.push_back(x);
    }
    for(auto [x,y]:b){
        naruto.push_back(x);
    }
    ll mx =0,cnt=0;
    ll pookie = min(n,m);
    bool ok = false;
    //cout<<naruto[0]<<' '<<kii[0]<<endl;
    rep(lala,0,kii.size()){
        rep(lili,0,naruto.size()){
            ll i = kii[lala];
            ll j = naruto[lili];
                if(p[i][j]=='+'){
                    ok= true;
                    cnt++;
                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;
            }
            if(cnt==(pookie)){
                cout<<max(0LL,mx+(mx-1))<<endl;
                return;
            }
        }
    }
    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 09:05:40
Judged At
2024-12-09 09:05:40
Judged By
Score
2
Total Time
12ms
Peak Memory
600.0 KiB