본문 바로가기

Facebook Hacker Cup

[Facebook Hacker Cup] Problem A: Travel Restrictions

어렵지는 않은데 요즘에 영어 지문이 너무 읽기 힘들어서 시간이 많이 걸렸다. I, O 따라 배열이 어떻게 달라지는지 판단한 다음 배열에 Y, N을 채워넣으면 된다. 

 

 

채워 넣는 과정은 아래와 같다. 정말 정성이다..

 

 

돌려볼 수 없으니 맞는지 아닌지 애매하다. 

 

1 Y Y, 1 Y N, 1 N N 같은 것들 넣어서 확인은 해봤는데 찜찜하네. 기도해야겠다.

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
 
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

void print(vector<vector<bool>> &v, int n)
{
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if(v[i][j])
                printf("%c", 'Y');
            else
                printf("%c", 'N');
        }
        printf("\n");
    }
}

void solve()
{
    int n;
    scanf("%d", &n);
    
    string I, O;
    cin >> I >> O;
    
    vector<vector<bool> > v(n+1, vector<bool>(n+1, true));
    
    for (int i = 0; i < n; i++)
    {
        if (I[i] == 'Y')
            continue ;
        
        for (int j = 1; j <= n; j++)
        {
            if (j == i+1)
                continue ;
            v[j][i+1] = false;
        }
        
        if (i + 2 > n)
            break ;
        
        for (int j = 1; j < i+2; j++)
        {
            v[i+2][j] = false;
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        if (O[i] == 'Y')
            continue ;

        for (int j = 1; j <= n; j++)
        {
            if (j == i+1)
                continue ;
            v[i+1][j] = false;
        }
        
        if (i + 2 > n)
            break ;
        
        for (int j = 1; j < i+2; j++)
        {
            v[j][i+2] = false;
        }
    }
    
    for (int i = 1; i <= n; i++)
    {
        bool isN = false;
        
        for (int j = i+1; j <= n; j++)
        {
            if (!v[j][i])
                isN = true;
            if (isN)
               v[j][i] = false; 
        }
        
        isN = false;
        for (int j = i+1; j <= n; j++)
        {
            if (!v[i][j])
                isN = true;
            if (isN)
               v[i][j] = false; 
        }
    }
    
    print(v, n);
    
}

int main() {
    int t;
    scanf("%d", &t);
    
    for (int i = 1; i <= t; i++)
    {
        printf("Case #%d:\n", i);
        solve();
    }
    
    return 0;
}

 

맞았다!

'Facebook Hacker Cup' 카테고리의 다른 글

[Facebook Hacker Cup] Problem B: Alchemy  (0) 2020.07.27