/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 7ms 540.0 KiB
#3 Accepted 28ms 988.0 KiB
#4 Accepted 31ms 1.117 MiB
#5 Accepted 21ms 972.0 KiB
#6 Accepted 29ms 1008.0 KiB
#7 Accepted 190ms 1.027 MiB
#8 Accepted 24ms 540.0 KiB
#9 Accepted 24ms 844.0 KiB
#10 Accepted 24ms 1012.0 KiB
#11 Accepted 530ms 4.16 MiB
#12 Accepted 1642ms 19.457 MiB
#13 Accepted 16ms 1.504 MiB
#14 Accepted 14ms 1.508 MiB
#15 Accepted 15ms 1.504 MiB
#16 Accepted 15ms 1.277 MiB
#17 Accepted 15ms 1.277 MiB
#18 Accepted 1601ms 19.434 MiB
#19 Accepted 19ms 1.527 MiB
#20 Accepted 1464ms 19.625 MiB
#21 Time Exceeded ≥2073ms ≥70.605 MiB
#22 Time Exceeded ≥2063ms ≥70.516 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;
        for(int i=s-1; i>=1; i--){
            if(ch[f][i]=='+'){
                c1++;
            }
            else break;
        }
        for(int i=s+1; i<=m; i++){
            if(ch[f][i]=='+'){
                c2++;
            }
            else break;
        }
        for(int i=f-1; i>=1; i--){
            if(ch[i][s]=='+'){
                c3++;
            }
            else break;
        }
        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:26:44
Judged At
2024-12-09 09:26:44
Judged By
Score
60
Total Time
≥2073ms
Peak Memory
≥70.605 MiB