/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 8ms 540.0 KiB
#3 Accepted 28ms 992.0 KiB
#4 Accepted 31ms 948.0 KiB
#5 Accepted 21ms 772.0 KiB
#6 Accepted 29ms 984.0 KiB
#7 Accepted 195ms 1000.0 KiB
#8 Accepted 25ms 540.0 KiB
#9 Accepted 25ms 820.0 KiB
#10 Accepted 24ms 788.0 KiB
#11 Accepted 557ms 4.199 MiB
#12 Accepted 1690ms 19.645 MiB
#13 Accepted 16ms 1.527 MiB
#14 Accepted 15ms 1.527 MiB
#15 Accepted 15ms 1.277 MiB
#16 Accepted 15ms 1.5 MiB
#17 Accepted 15ms 1.5 MiB
#18 Accepted 1852ms 19.625 MiB
#19 Accepted 30ms 1.504 MiB
#20 Time Exceeded ≥2011ms ≥19.602 MiB
#21 Time Exceeded ≥2094ms ≥70.457 MiB

Code

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define pi 2*acos(0.0)



void solve() 
{
    int n,m;
    cin>>n>>m;

    char ch[n+1][m+1];
    bool have=false;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            cin>>ch[i][j];
            if(ch[i][j]=='+'){
                have=true;
            }
        }
    }
    if(!have){
        cout<<0<<endl;
        return;
    }

    vector<pair<int,int>> ps;
      
    for(int i=2; i<n; i++){
        for(int j=2; j<m; j++){
            if(ch[i][j]=='+'){
                if(ch[i][j+1]=='+' && ch[i][j-1]=='+' && ch[i-1][j]=='+' && ch[i+1][j]=='+'){
                    ps.push_back({i,j});
                }
            }
        }
    }

    // for(auto &it: ps){
    //     cout<<it.first<<" "<<it.second<<endl;
    // }
    if(ps.size()==0){
        cout<<1<<endl;
        return;
    }

    int maxi=-1,c1=0,c2=0,c3=0,c4=0;
    
    int mx = 2*min(n,m)-1;

    for(auto it: ps){
        int f=it.first,s=it.second;
        //cout<<f<<" "<<s<<endl;
        int i=s-1;
        while(i>=1 && ch[f][i]=='+'){ c1++,i--;}
        // for(int i=s-1; i>=1; i--){
        //     if(ch[f][i]=='+'){
        //         c1++;
        //     }
        //     else break;
        // }
        i=s+1;
        while(i<=m && ch[f][i]=='+'){ c2++,i++;}
        // for(int i=s+1; i<=m; i++){
        //     if(ch[f][i]=='+'){
        //         c2++;
        //     }
        //     else break;
        // }
        i=f-1;
        while(i>=1 && ch[i][s]=='+'){ c3++,i--;}
        // for(int i=f-1; i>=1; i--){
        //     if(ch[i][s]=='+'){
        //         c3++;
        //     }
        //     else break;
        // }
        i=f+1;
        while(i<=n && ch[i][s]=='+'){ c4++,i++;}
        // for(int i=f+1; i<=n; i++){
        //     if(ch[i][s]=='+'){
        //         c4++;
        //     }
        //     else break;
        // }
        //cout<<c1<<" "<<c2<<" "<<c3<<" "<<c4<<endl;
        int min1=min(c1,c2);
        int min2=min(c3,c4);

        int mini=min(min1,min2);
        //cout<<"mini "<<mini<<endl;
        maxi=max(maxi,((4*mini)+1));
        if(maxi==mx){
            cout<<maxi<<endl;
            return;
        }
        c1=0,c2=0,c3=0,c4=0;
    }
    cout<<maxi<<endl;

}

int32_t main () 
{

    ios::sync_with_stdio(false); cin.tie(nullptr);
    

    int 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:41:06
Judged At
2024-12-09 09:41:06
Judged By
Score
56
Total Time
≥2094ms
Peak Memory
≥70.457 MiB