제출 #64131

#제출 시각아이디문제언어결과실행 시간메모리
64131patrikpavic2Dango Maker (JOI18_dango_maker)C++17
13 / 100
783 ms263168 KiB
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int N = 1e3 + 50;
const int M = 2 * N * N;

vector < int > v[M], k[N][N];

int ty[M], sl[M], bio[M];
char s[N][N];
int n, m;


void dfs(int x, int lst){
    sl[ty[x]]++;
    bio[x] = 1;
    for(int y : v[x])
        if(y != lst)
            dfs(y, x);
}

int main(){
    memset(s, '.', sizeof(s));
    scanf("%d%d", &n, &m);
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            scanf(" %c", &s[i][j]);
        }
    }
    int cnt = 1;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            if(s[i][j] != 'G') continue;
            if(s[i - 1][j] == 'R' && s[i + 1][j] == 'W'){
                k[i - 1][j].push_back(cnt);
                k[i + 1][j].push_back(cnt);
                k[i][j].push_back(cnt);
                cnt++;
            }
            if(s[i][j - 1] == 'R' && s[i][j + 1] == 'W'){
                k[i][j - 1].push_back(cnt);
                k[i][j + 1].push_back(cnt);
                k[i][j].push_back(cnt);
                ty[cnt] = 1;
                cnt++;
            }
        }
    }
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            if(k[i][j].size() == 2){
                v[k[i][j][0]].push_back(k[i][j][1]);
                v[k[i][j][1]].push_back(k[i][j][0]);
            }
        }
    }
    int sol = 0;
    //printf("CNT = %d\n", cnt);
    for(int i = 1;i<cnt;i++){
        if(bio[i]) continue;
        sl[0] = 0, sl[1] = 0;
        dfs(i, i);
        //printf("X : %d, %d %d\n", sl[0], sl[1]);
        sol += max(sl[0], sl[1]);
    }
    printf("%d\n", sol);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
dango_maker.cpp:30:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c", &s[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...