본문 바로가기

백준

12887 경로 게임

엇 최소 경로 구한 다음, 전체 칸 - (검은 칸 + 경로) 빼면 될 것 같았다. 최소 경로는 무조건 직진, 검은색 만나면 옆으로 비켜선 다음 직진하게 구현했다. 출발 위치가 두 가지가 있으니깐 두 가지 모든 경우 구해서 최소인 거 구했다. 쉬웠음 ~.~ 

 

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#include <stdio.h>
#include <math.h>

#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()

using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using iis = pair<int, string>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;

int getCourseLen(int n, vector<string> &v, int start){
    if (v[start][0] == '#')
        return 99999999;
    
    
    int courseLen = 0;
    for (int i = 0, j = start; i < n; courseLen++) {
        if (v[j][i + 1] == '#') {
            j = (j + 1) % 2;
            continue;
        }
        i++;
    }
    
    return courseLen;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n;
    cin >> n;
    
    vector<string> v(2);
    for (int i = 0; i < 2; i++) {
        cin >> v[i];
        v[i] += ".";
    }
    
    int black = 0;
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < n; j++)
            if (v[i][j] == '#')
                black++;
    
    int len1 = getCourseLen(n, v, 0);
    int len2 = getCourseLen(n, v, 1);
    
    
    cout << 2 * n - min(len1, len2) - black << "\n";
    
    return 0;
}

'백준' 카테고리의 다른 글

16114 화살표 연산자  (0) 2021.09.14
16565 N포커  (0) 2021.09.05
제 3회 소프트콘  (1) 2021.08.28
11558 The Game of Death  (0) 2021.08.28
10158 개미  (0) 2021.08.28