Submission #235727

#TimeUsernameProblemLanguageResultExecution timeMemory
235727AutoratchDango Maker (JOI18_dango_maker)C++14
13 / 100
7 ms512 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 3002;

int m,n,ans;
string c[N];
bool visited[N][N];

void solve(int x,int y)
{
    int hor = 0,ver = 0;
    for(int i = x,j = y;i>=1 and j>=1 and i<=m and j<=n;i++,j--)
    {
        if(c[i][j]!='G') break;
        visited[i][j] = true;
        int ov = ver,oh = hor;
        if(c[i-1][j]=='R' and c[i+1][j]=='W') ver++;
        if(c[i][j-1]=='R' and c[i][j+1]=='W') hor++;
        if(ver==ov and hor==oh) break;
    }
    for(int i = x-1,j = y+1;i>=1 and j>=1 and i<=m and j<=n;i--,j++)
    {
        if(c[i][j]!='G') break;
        visited[i][j] = true;
        int ov = ver,oh = hor;
        if(c[i-1][j]=='R' and c[i+1][j]=='W') ver++;
        if(c[i][j-1]=='R' and c[i][j+1]=='W') hor++;
        if(ver==ov and hor==oh) break;
    }
    ans+=max(hor,ver);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> m >> n;
    for(int i = 1;i <= m;i++) cin >> c[i],c[i] = " "+c[i];
    for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) if(!visited[i][j] and c[i][j]=='G') solve(i,j);
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...