제출 #524403

#제출 시각아이디문제언어결과실행 시간메모리
524403AA_SurelyDango Maker (JOI18_dango_maker)C++17
13 / 100
1 ms332 KiB
#include <bits/stdc++.h>

#define FOR(i,x,n) 	for(int i=x; i<n; i++)
#define F0R(i,n) 	FOR(i,0,n)
#define ROF(i,x,n) 	for(int i=n-1; i>=x; i--)
#define R0F(i,n) 	ROF(i,0,n)

#define WTF 		cout << "WTF" << endl

#define IOS 		ios::sync_with_stdio(false); cin.tie(0)
#define F 			first
#define S	 		second
#define pb 			push_back

#define ALL(x) 		x.begin(), x.end()
#define RALL(x) 	x.rbegin(), x.rend()

using namespace std;
typedef long long 		LL;

typedef pair<int, int> 	PII;
typedef pair<LL, LL> 	PLL;

typedef vector<int> 	VI;
typedef vector<LL> 		VLL;
typedef vector<PII> 	VPII;
typedef vector<PLL> 	VPLL;

const int MAXN = 3e3 + 7;
const int ALPHA = 27;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int LOG = 22;

int n, m;
char grid[MAXN][MAXN];
int gs[MAXN][MAXN];

inline bool safe(int x, int y) {
    if (x < 0 || x >= n) return 0;
    if (y < 0 || y >= m) return 0;
    return 1;
}

int main() {
    IOS;
    
    cin >> n >> m;
    F0R(i, n) F0R(j, m) cin >> grid[i][j];
    int ans = 0;
    F0R(i, n) F0R(j, m) {
        if (grid[i][j] != 'G') continue;

        if (i && grid[i - 1][j] == 'R' && i < n - 1 && grid[i + 1][j] == 'W') gs[i][j] = 1;
        if (j && grid[i][j - 1] == 'R' && j < m - 1 && grid[i][j + 1] == 'W') gs[i][j] |= 2;
        ans += (gs[i][j] != 0);
    }
    //cout << ans << endl;
    /*
    F0R(i, n) {
        F0R(j, m) cout << gs[i][j];
        cout << endl;
    }
    */
    F0R(j, m) {
        int x = 0, y = j, cnt = 0;
        while(safe(x, y)) {
            if (gs[x][y] == 3) {
                x++; y--; 
                continue;
            }
            
            if (gs[x][y] == 0 || !x || y + 1 >= m || gs[x][y] == gs[x - 1][y + 1]) {
                ans -= (cnt >> 1);
                cnt = 0;
            }
            cnt += (gs[x][y] != 0);

            x++; y--;
        }
        ans -= (cnt >> 1);
    }

    FOR(i, 1, n) {
        int x = i, y = m - 1, cnt = 0;
        while(safe(x, y)) {
            if (gs[x][y] == 3) {
                x++; y--; 
                continue;
            }
            
            if (gs[x][y] == 0 || !x || y + 1 >= m || gs[x][y] == gs[x - 1][y + 1]) {
                ans -= (cnt >> 1);
                cnt = 0;
            }
            cnt += (gs[x][y] != 0);

            x++; y--;
        }
        ans -= (cnt >> 1);
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...