/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 9ms 588.0 KiB
#3 Accepted 38ms 784.0 KiB
#4 Accepted 41ms 812.0 KiB
#5 Accepted 26ms 748.0 KiB
#6 Accepted 45ms 956.0 KiB
#7 Accepted 255ms 968.0 KiB
#8 Accepted 28ms 588.0 KiB
#9 Accepted 28ms 768.0 KiB
#10 Accepted 29ms 776.0 KiB
#11 Accepted 624ms 4.16 MiB
#12 Time Exceeded ≥2071ms ≥19.621 MiB
#13 Accepted 16ms 1.496 MiB
#14 Accepted 14ms 1.5 MiB
#15 Accepted 15ms 1.277 MiB
#16 Accepted 15ms 1.324 MiB
#17 Accepted 15ms 1.277 MiB
#18 Accepted 1508ms 19.625 MiB
#19 Accepted 18ms 1.527 MiB
#20 Accepted 1365ms 19.637 MiB
#21 Time Exceeded ≥2093ms ≥70.602 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;
    

    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));
        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:18:25
Judged At
2024-12-09 09:18:25
Judged By
Score
56
Total Time
≥2093ms
Peak Memory
≥70.602 MiB