이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#define printLn(n) cout << n << '\n'
using namespace std;
typedef long long ll;
const ll HORIZONTAL = 0;
const ll VERTICAL = 1;
const ll EMPTY = 2;
ll readLL();
string readStr();
void resolve();
bool check(const vector<string> &field, ll i, ll j, ll dir);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
resolve();
return 0;
}
void resolve() {
ll height = readLL();
ll width = readLL();
vector<string> field(height);
for (int i = 0; i < height; ++i) {
field[i] = readStr();
}
vector<vector<vector<ll>>> dp(height, vector<vector<ll>>(width, vector<ll>(3, 0)));
ll res = 0;
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
ll prevHor = 0;
ll prevEmp = 0;
ll prevVer = 0;
if (i > 0 && j > 0) {
prevHor = dp[i - 1][j - 1][HORIZONTAL];
prevVer = dp[i - 1][j - 1][VERTICAL];
prevEmp = dp[i - 1][j - 1][EMPTY];
}
dp[i][j][EMPTY] = max(prevEmp, max(prevHor, prevVer));
if (i > 0 && i < height - 1 && check(field, i, j, VERTICAL)) {
dp[i][j][VERTICAL] = 1 + max(prevVer, prevEmp);
}
if (j > 0 && j < width - 1 && check(field, i, j, HORIZONTAL)) {
dp[i][j][HORIZONTAL] = 1 + max(prevHor, prevEmp);
}
if (i == height - 1 || j == width - 1) {
res += max(dp[i][j][EMPTY], max(dp[i][j][HORIZONTAL], dp[i][j][VERTICAL]));
}
}
}
printLn(res);
}
bool check(const vector<string> &field, ll i, ll j, ll dir) {
if (dir == HORIZONTAL) {
return (field[i][j - 1] == 'R' && field[i][j] == 'G' && field[i][j + 1] == 'W');
} else if (dir == VERTICAL) {
return (field[i - 1][j] == 'R' && field[i][j] == 'G' && field[i + 1][j] == 'W');
}
return false;
}
ll readLL() {
ll num;
cin >> num;
return num;
}
string readStr() {
string num;
cin >> num;
return num;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |