Wrong Answer
Code
/*
Author : MishkatIT
Created : Tuesday 10-12-2024 16:27:09
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
const int inf = 1e9;
const ll linf = 1e18;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
int n, m;
cin >> n >> m;
int f = 0;
vector<vector<char>> v(n, vector<char>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> v[i][j];
f |= (v[i][j] == '+');
}
}
vector<vector<pair<int, int>>> ans(n, vector<pair<int, int>>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] == '+') {
int cnt = 0;
for (int k = j; k < m; k++) {
if (v[i][k] == '-') {
int rcnt = cnt;
for (int l = k; l >= j; l--) {
ans[i][l].second = cnt - rcnt;
rcnt--;
}
cnt = 0;
j = k;
break;
} else {
ans[i][k].first = cnt++;
}
if (k == m - 1) j = m;
}
int l = m - 1;
int rcnt = cnt;
while (l >= 0 && rcnt >= 0) {
ans[i][l--].second = cnt - rcnt;
rcnt--;
}
}
}
}
vector<vector<pair<int, int>>> bns(n, vector<pair<int, int>>(m));
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (v[i][j] == '+') {
int cnt = 0;
for (int k = i; k < n; k++) {
if (v[k][j] == '-') {
int rcnt = cnt;
for (int l = k; l >= i; l--) {
bns[l][j].second = cnt - rcnt;
rcnt--;
}
cnt = 0;
i = k;
break;
// debug("lskdjf"); return 0;
} else {
bns[k][j].first = cnt++;
}
if (k == n - 1) i = n;
}
int l = n - 1;
int rcnt = cnt;
while (l >= 0 && rcnt >= 0) {
bns[l][j].second = cnt - rcnt;
rcnt--;
l--;
}
}
}
}
// debug(bns);
int mx = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
mx= max (mx, min({ans[i][j].first, ans[i][j].second, bns[i][j].first, bns[i][j].second}));
}
}
cout << mx * 4 + f << '\n';
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1143 Plus of Pluses
- Contest
- LU IUJPC : Sylhet Division 2024 Replay Contest
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-12-10 12:34:41
- Judged At
- 2024-12-10 12:34:41
- Judged By
- Score
- 4
- Total Time
- 11ms
- Peak Memory
- 796.0 KiB