1일1알

백준 10703번 유성 C++ 본문

알고리즘

백준 10703번 유성 C++

영춘권의달인 2022. 11. 26. 12:10

https://www.acmicpc.net/problem/10703

 

10703번: 유성

작고 특이한 모양의 유성 사진이 인터넷에 올라왔다. 사진에는 매우 높은 곳에서 떨어지고 있는 유성이 허공에 찍혀 있었다. 유성이 떨어지고 난 뒤의 사진도 있었지만 안타깝게도 소실돼버려

www.acmicpc.net

 

유성과 땅의 거리중 최소값을 찾아서 그만큼 밑으로 이동시켰다.

 

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>

using namespace std;
using int64 = long long;

int r, s;
vector<pair<int, int>> stars;
vector<int> starHeights;
vector<int> groundHeights;
vector<vector<char>> board;

const int BIGVALUE = 987654321;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> r >> s;
    starHeights = vector<int>(s, -1);
    groundHeights = vector<int>(s, BIGVALUE);
    board = vector<vector<char>>(r, vector<char>(s));
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < s; j++) {
            cin >> board[i][j];
            if (board[i][j] == 'X') {
                stars.push_back({ i,j });
                starHeights[j] = i;
                board[i][j] = '.';
            }
            else if (board[i][j] == '#') {
                groundHeights[j] = min(groundHeights[j], i);
            }
        }
    }
    int down = BIGVALUE;
    for (int i = 0; i < s; i++) {
        int starHeight = starHeights[i];
        int groundHeight = groundHeights[i];
        if (starHeight == -1) continue;
        if (groundHeight == BIGVALUE) continue;
        down = min(down, groundHeight - starHeight - 1);
    }
    if (down != BIGVALUE) {
        for (auto a : stars) {
            board[a.first + down][a.second] = 'X';
        }
    }
    for (auto a : board) {
        for (auto b : a) {
            cout << b;
        }
        cout << "\n";
    }
}