이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MOD = 1e9 + 7;
//~ void calc(int i, int j, vector<vector<char>>& table, vector<vector<vector<int>>>& v, vector<vector<bool>>& done){
//~ if(i < n - 2 && table[i + 1][j] == 'G' && table[i+2][j] == 'W' && done[i][j] == 0 && done[i+1][j] == 0 && done[i+2][j] == 0){
//~ }else if(j < m - 2 && table[i][j + 1] == 'G' && table[i][j + 2] == 'W' && done[i][j] == 0 && done[i][j+1] == 0 && done[i][j+2] == 0){
//~ int cnt = 0;
//~ else{
//~ ans++;
//~ done[i][j] = 1;
//~ done[i][j+1] = 1;
//~ done[i][j+2] = 1;
//~ }
//~ }
//~ }
void solve(){
int n, m; cin >> n >> m;
vector<vector<char>> table(n, vector<char>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++) cin >> table[i][j];
}
vector<vector<int>> v(n, vector<int>(m, 0));
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(table[i][j] != 'R') continue;
if(i < n - 2){
if(table[i + 1][j] == 'G' && table[i+2][j] == 'W'){
v[i+1][j]++;
v[i+2][j]++;
}
}
if(j < m - 2){
if(table[i][j + 1] == 'G' && table[i][j + 2] == 'W'){
v[i][j + 1]++;
v[i][j + 2]++;
}
}
}
}
vector<vector<bool>> done(n, vector<bool>(m, 0));
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(table[i][j] == 'R' && done[i][j] == 0){
if(j < m - 2 && table[i][j + 1] == 'G' && table[i][j + 2] == 'W' && done[i][j] == 0 && done[i][j+1] == 0 && done[i][j+2] == 0){
ans++;
done[i][j] = 1; done[i][j+1] = 1; done[i][j+2] = 1;
}else if(i < n - 2 && table[i + 1][j] == 'G' && table[i+2][j] == 'W' && done[i][j] == 0 && done[i+1][j] == 0 && done[i+2][j] == 0){
if(v[i+1][j] == 2 && v[i+2][j] == 2){
ans++;
done[i+1][j-1] = 1; done[i+1][j] = 1; done[i+1][j+1] = 1;
//~ done[i+2][j-2] = 1; done[i+2][j-1] = 1; done[i+2][j] = 1;
}else{
ans++;
done[i][j] = 1; done[i+1][j] = 1; done[i+2][j] = 1;
}
}
}
}
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//~ int tt; cin >> tt;
int tt = 1;
for(int t = 1; t <= tt; t++){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |