/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 13ms 3.047 MiB
#3 Accepted 34ms 3.293 MiB
#4 Accepted 37ms 3.402 MiB
#5 Accepted 29ms 3.047 MiB
#6 Accepted 39ms 3.238 MiB
#7 Accepted 177ms 3.305 MiB
#8 Accepted 50ms 2.859 MiB
#9 Accepted 55ms 10.852 MiB
#10 Accepted 53ms 6.551 MiB
#11 Accepted 461ms 6.75 MiB
#12 Accepted 1336ms 36.609 MiB
#13 Accepted 298ms 28.926 MiB
#14 Accepted 18ms 20.602 MiB
#15 Accepted 406ms 28.617 MiB
#16 Accepted 20ms 18.812 MiB
#17 Accepted 21ms 20.824 MiB
#18 Accepted 1326ms 34.906 MiB
#19 Accepted 29ms 22.879 MiB
#20 Accepted 1201ms 37.02 MiB
#21 Time Exceeded ≥2083ms ≥101.328 MiB
#22 Time Exceeded ≥2094ms ≥99.164 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define nl << "\n"
#define yes << "YES\n"
#define no << "NO\n"
#define sp " "
ll n, k;
const int N = 20000, K = 20000;
char a[N][K];
ll clk(ll x, ll y)
{
    ll val, mn = 0;
    ll left = 0, right = 0, up = 0, down = 0;

    for (int i = y - 1; i >= 0; i--)
    {

        if (a[x][i] == '+')
        {
            left++;
        }
        else
        {

            break;
        }
    }
    for (int i = y + 1; i < k; i++)
    {

        if (a[x][i] == '+')
        {
            right++;
        }
        else
        {
            break;
        }
    }
    for (int i = x - 1; i >= 0; i--)
    {

        if (a[i][y] == '+')
        {
            up++;
        }
        else
        {

            break;
        }
    }

    for (int i = x + 1; i < n; i++)
    {

        if (a[i][y] == '+')
        {
            down++;
        }
        else
        {

            break;
        }
    }

    val = min({left, right, up, down});

    return (4 * val) + 1;
    // else return 0;
}
void solve()
{

    cin >> n >> k;
    int c = 0;
    vector<pair<ll, ll>> v;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < k; j++)
        {
            cin >> a[i][j];
            if (a[i][j] == '+')
                v.push_back({i, j});
        }
    }
    ll mx = 0, cnt = 0;
    for (auto i : v)
    {
        mx = max(mx, clk(i.first, i.second));
    }

    // // clk(2,3);
    // int i = 0, j = 0;
    // while (i < n)

    // {

    //     if (a[i][j] == '+')
    //     {
    //     }
    //     if (j == k - 1)
    //     {
    //         i++, j = 0;
    //     }
    //     else
    //         j++;
    // }

    cout << mx nl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll t;
    cin >> t;
    for (ll i = 0; i < t; i++)
        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:22:43
Judged At
2024-12-09 09:22:43
Judged By
Score
60
Total Time
≥2094ms
Peak Memory
≥101.328 MiB