이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
inline void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
ll n, m, dp[1010][1010][5], ans, h[4][4], p;
char s[1010][1010], joi[3][3];
ll dx[] = {0, 0, -1, -1}, dy[] = {0, -1, 0, -1};
int main() {
fastio();
cin >> m >> n;
for (ll i = 0; i < m; i++) {
cin >> s[i];
}
cin >> joi[0] >> joi[1];
for (ll i = 0; i < 2; i++) {
for (ll j = 0; j < 2; j++) {
h[i][j] = 2 * (joi[i][j] == 'I') + (joi[i][j] == 'O');
}
}
for (ll i = 1; i < m; i++) {
for (ll j = 1; j < n; j++) {
ll cnt = 0, x, y;
for (ll k = 0; k < 4; k++) {
ll nx = i + dx[k], ny = j + dy[k];
if (joi[1 + dx[k]][1 + dy[k]] == s[nx][ny]) {
cnt++;
} else {
x = nx, y = ny;
}
}
if (cnt == 4) {
ans++;
for (ll k = 0; k < 4; k++) {
ll nx = i + dx[k], ny = j + dy[k];
for (ll l = 0; l < 3; l++) {
if (l != h[1 + dx[k]][1 + dy[k]]) {
dp[nx][ny][l]--;
}
}
}
} else if (cnt == 3) {
dp[x][y][h[x - i + 1][y - j + 1]]++;
}
}
}
for (ll i = 0; i < m; i++) {
for (ll j = 0; j < n; j++) {
for (ll k = 0; k < 3; k++) {
p = max(p, dp[i][j][k]);
}
}
}
cout << ans + p;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
2014_ho_t1.cpp: In function 'int main()':
2014_ho_t1.cpp:61:50: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
61 | dp[x][y][h[x - i + 1][y - j + 1]]++;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
2014_ho_t1.cpp:61:50: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |