/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 10ms 336.0 KiB
#3 Accepted 53ms 668.0 KiB
#4 Accepted 59ms 732.0 KiB
#5 Accepted 31ms 684.0 KiB
#6 Accepted 66ms 692.0 KiB
#7 Accepted 338ms 780.0 KiB
#8 Accepted 36ms 576.0 KiB
#9 Accepted 34ms 724.0 KiB
#10 Accepted 33ms 712.0 KiB
#11 Accepted 973ms 2.402 MiB
#12 Time Exceeded ≥2047ms ≥11.609 MiB
#13 Accepted 27ms 1.5 MiB
#14 Accepted 26ms 1.5 MiB
#15 Accepted 23ms 1.492 MiB
#16 Accepted 27ms 1.504 MiB
#17 Accepted 26ms 1.508 MiB
#18 Time Exceeded ≥2050ms ≥11.613 MiB

Code

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

#define ll 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.empty()){
        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;

}

int main () 
{

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

    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:04:16
Judged At
2024-12-09 09:04:16
Judged By
Score
44
Total Time
≥2050ms
Peak Memory
≥11.613 MiB