이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//cf meowcneil; t.me/macneilbot
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <random>
#include <cassert>
using namespace std;
#define int long long
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define f(a) for(int i = 0; i<a; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;
typedef vector<str> vestr;
typedef vector<int> vei;
typedef vector<vector<int>> veve;
void solve() {
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
vector<vector<int>> ct(n, vector<int>(m));
vector<vector<int>> ok1(n, vector<int>(m));
vector<vector<int>> ok2(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] != 'G') {
ct[i][j] = 1e9;
continue;
}
if (i && i < n - 1 && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') ct[i][j]++;
if (i && i < n - 1 && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') ok1[i][j] = 1;
if (j && j < m - 1 && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') ct[i][j]++;
if (j && j < m - 1 && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') ok2[i][j] = 1;
}
}
set<pair<int, pair<int, int>>> cur;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cur.insert({ct[i][j], {i, j}});
}
}
int ans = 0;
for (int s = 0; s < n + m; ++s) {
bool curr = 0;
for (int i = s; i >= 0; --i) {
int j = s - i;
if (i >= n || j >= m) continue;
if (a[i][j] != 'G') continue;
if (ct[i][j] == 1) {
if (ok1[i][j]) {
if (a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
a[i - 1][j] = 'Q';
a[i + 1][j] = 'Q';
ans++;
}
}
else {
if (a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
a[i][j - 1] = 'Q';
a[i][j - 1] = 'Q';
ans++;
}
}
}
else if (ct[i][j] == 2) {
if (a[i - 1][j] != 'R' || a[i + 1][j] != 'W') {
if (a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
a[i][j - 1] = 'Q';
a[i][j - 1] = 'Q';
ans++;
}
continue;
}
if (a[i][j - 1] != 'R' || a[i][j + 1] != 'W') {
if (a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
a[i - 1][j] = 'Q';
a[i + 1][j] = 'Q';
ans++;
}
continue;
}
ans++;
}
}
}
cout << ans << '\n';
}
signed main() {
int tc = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
// cin >> tc;
#else
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// cin >> tc;
#endif
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
dango_maker.cpp: In function 'void solve()':
dango_maker.cpp:67:14: warning: unused variable 'curr' [-Wunused-variable]
67 | bool curr = 0;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |