답안 #28361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28361 2017-07-16T04:59:54 Z ㅁㄴㅇㄹ호(#1227, gs13105) Play Onwards (FXCUP2_onward) C++14
0 / 1
0 ms 1180 KB
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <tuple>

using namespace std;

vector<int> adj[200];

char arr[200][21];
int len[200];
int col[200];

bool dfs(int x, int c)
{
    col[x] = c;
    for(int y : adj[x])
    {
        if(col[y] == c)
            return 1;
        if(col[y] == 0)
        {
            if(dfs(y, 3-c))
                return 1;
        }
    }
    return 0;
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    bool u, v;
    int n, k, i, j, a, b, c;
    scanf("%d%d", &n, &k);
    for(i = 0; i<n; i++)
        scanf("%s", arr[i]);

    for(i = 0; i<n; i++)
        len[i] = strlen(arr[i]);

    for(i = 0; i<n; i++)
    {
        for(j = i+1; j<n; j++)
        {
            if(len[i] == len[j])
            {
                v = 1;
                for(a = 0; a<len[i]; a++)
                {
                    if(arr[i][a] != arr[j][a])
                    {
                        v = 0;
                        break;
                    }
                }
                if(v)
                    continue;
            }
            v = 1;
            for(a = 0; a<len[i]-k+1; a++)
            {
                for(b = 0; b<len[j]-k+1; b++)
                {
                    u = 1;
                    for(c = 0; c<k; c++)
                    {
                        if(arr[i][a+c] != arr[j][b+c])
                        {
                            u = 0;
                            break;
                        }
                    }
                    if(u)
                    {
                        adj[i].push_back(j);
                        adj[j].push_back(i);
                        v = 0;
                        break;
                    }
                }
                if(!v)
                    break;
            }
        }
    }

    for(i = 0; i<n; i++)
    {
        if(col[i] == 0)
        {
            if(dfs(i, 1))
            {
                printf("NO");
                return 0;
            }
        }
    }

    printf("Yes\n");
    for(i = 0; i<n; i++)
        printf("%d\n", col[i]);
    return 0;
}

Compilation message

onward.cpp: In function 'int main()':
onward.cpp:41:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
                          ^
onward.cpp:43:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", arr[i]);
                            ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 1180 KB Output isn't correct
2 Halted 0 ms 0 KB -