답안 #1082676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1082676 2024-09-01T06:15:02 Z Grothendieck_505 Tracks in the Snow (BOI13_tracks) C++14
컴파일 오류
0 ms 0 KB
#include "bits/stdc++.h"
#define v(x) vector<int> 
#define p(x,y) pair<x,y>

using namespace std;

vector<int> dx = {0, 0, 1, -1};
vector<int> dy = {1, -1, 0, 0};

int h, w;

void dfs(int x, int y, int comp, vector<vector<int>> &visited, vector<vector<char>> &v, set<char> &s, int &animal) {
    if (x < 0 || x >= h || y < 0 || y >= w || visited[x][y] || v[x][y] == '.') {
        return;
    }

    visited[x][y] = comp;
    s.insert(v[x][y]);
    animal = max(animal, (int)s.size());

    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        dfs(nx, ny, comp, visited, v, s, animal);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> h >> w;
    vector<vector<int>> visited(h, vector<int>(w, 0));
    vector<vector<char>> v(h, vector<char>(w));

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> v[i][j];
        }
    }

    int comp = 0;
    int ans = 0;  // To store the total sum of distinct animals in all components

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!visited[i][j] && v[i][j] != '.') {
                set<char> s;
                int animal = 0;
                dfs(i, j, ++comp, visited, v, s, animal);
                ans += animal;  // Summing up the distinct animals in each component
            }
        }
    }

    cout << comp << " " << ans << "\n";

    return 0;
}

Compilation message

tracks.cpp:34:46: error: macro "v" passed 2 arguments, but takes just 1
   34 |     vector<vector<char>> v(h, vector<char>(w));
      |                                              ^
tracks.cpp:2: note: macro "v" defined here
    2 | #define v(x) vector<int>
      |