답안 #824474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824474 2023-08-14T06:45:04 Z 반딧불(#10358) Sirtet (CCO19_day1problem2) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int xx[]={0, 1, 0, -1}, yy[]={1, 0, -1, 0};

int n, m;
int board[1000002], ccnt;

inline int get(int x, int y){
    return (x-1)*m+y;
}

void dfs(int x, int y, int c){
    board[get(x, y)] = c;
    for(int d=0; d<4; d++){
        int tx = x+xx[d], ty=y+yy[d];
        if(board[get(tx, ty)] != -1) continue;
        dfs(tx, ty, c);
    }
}

vector<pair<int, int> > link[1000002]; /// x번 집합이 k칸 내려갔을 때 y번 집합이 k+d칸까지 내려갈 수 있다면 (y, d) 삽입
int dist[1000002];
bool visited[1000002];

int ans[1000002];

struct dat{
    int x, d;
    dat(){}
    dat(int x, int d): x(x), d(d){}
    bool operator<(const dat &r)const{
        return d>r.d;
    }
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            char c;
            scanf(" %c", &c);
            if(c=='#') board[get(i, j)] = -1;
        }
    }

    for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) if(board[get(i, j)] == -1) dfs(i, j, ++ccnt);

    for(int j=1; j<=m; j++){
        int lastI = n+1, lastC = 0;
        for(int i=n; i>=1; i--){
            if(!board[get(i, j)]) continue;
            if(lastC == board[get(i, j)]) lastI = i;
            else{
                link[lastC].push_back(make_pair(board[get(i, j)], i-lastI-1));
                lastC = board[get(i, j)], lastI = i;
            }
        }
    }

    priority_queue<dat> pq;
    pq.push(dat(0, 0));
    while(!pq.empty()){
        dat tmp = pq.top(); pq.pop();
        if(visited[tmp.x]) continue;
        visited[tmp.x] = 1;
        dist[tmp.x] = tmp.d;
        for(auto p: link[tmp.x]){
            pq.push(dat(p.first, tmp.d + p.second));
        }
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(!board[get(i, j)]) continue;
            int c = board[get(i, j)];
            ans[get(i+dist[c], j)] = c;
        }
    }

//    for(int i=1; i<=n; i++){
//        for(int j=1; j<=m; j++){
//            printf("%d", ans[get(i, j)]);
//        }
//        puts("");
//    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++) printf("%c", ans[get(i, j)] ? '#' : '.');
        puts("");
    }
}

Compilation message

Main.cpp:37:2: error: expected ';' after struct definition
   37 | }
      |  ^
      |  ;
Main.cpp: In function 'int main()':
Main.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:44:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |             scanf(" %c", &c);
      |             ~~~~~^~~~~~~~~~~