Time Exceeded
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
char arr[n][m];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> arr[i][j];
}
}
int highest_pluses = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(arr[i][j] =='+') {
int curr_pluses = 1;
int top = 0, bottom = 0, left = 0, right = 0;
// top
for(int k = i - 1; k >= 0; k--) {
if(arr[k][j] == '+') {
top++;
}
else {
break;
}
}
// bottom
for(int k = i + 1; k < n; k++) {
if(arr[k][j] == '+') {
bottom++;
}
else {
break;
}
}
// left
for(int k = j - 1; k >= 0; k--) {
if(arr[i][k] == '+') {
left++;
}
else {
break;
}
}
// right
for(int k = j + 1; k < m; k++) {
if(arr[i][k] == '+') {
right++;
}
else {
break;
}
}
curr_pluses += 4 * min({top, bottom, left, right});
highest_pluses = max(curr_pluses, highest_pluses);
}
}
}
cout << highest_pluses << endl;
}
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 08:25:11
- Judged At
- 2024-12-09 08:25:11
- Judged By
- Score
- 60
- Total Time
- ≥2099ms
- Peak Memory
- ≥4.574 MiB