Submission #28375

# Submission time Handle Problem Language Result Execution time Memory
28375 2017-07-16T05:05:37 Z 뚜루루뚜루(#1212, onjo0127) Play Onwards (FXCUP2_onward) C++
0 / 1
0 ms 2068 KB
#include <bits/stdc++.h>
using namespace std;

char str[209][22];
bool adj[209][209];
bool visited[209];
int res[209];
int n;

void dfs(int now, int cnt)
{
    visited[now] = 1;
    res[now] = cnt%2 + 1;
    for(int i=0; i<n; i++) {
        if(adj[now][i] == 0 || visited[i]) continue;
        dfs(i, cnt+1);
    }
}

int main()
{
    int k;
    scanf("%d %d",&n,&k);
    for(int i=0; i<n; i++) scanf(" %s",str[i]);
    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            int ilen = strlen(str[i]);
            int jlen = strlen(str[j]);
            for(int x=0; x<=ilen-k; x++) {
                for(int y=0; y<=jlen-k; y++) {
                    int p;
                    for(p=0; p<k; p++) if(str[i][x+p] != str[j][y+p]) break;
                    if(p==k) {
                        adj[i][j] = adj[j][i] = 1;
                        goto stop;
                    }
                }
            }
            stop:;
        }
    }
    for(int i=0; i<n; i++) if(!visited[i]) dfs(0,0);
    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            if(adj[i][j] && res[i] == res[j]) return !printf("No");
        }
    }
    puts("Yes");
    for(int i=0; i<n; i++) {
        printf("%d\n",res[i]);
    }
    return 0;
}

Compilation message

onward.cpp: In function 'int main()':
onward.cpp:23:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
                         ^
onward.cpp:24:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0; i<n; i++) scanf(" %s",str[i]);
                                               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2068 KB Output is correct
2 Incorrect 0 ms 2068 KB Integer 0 violates the range [1, 2]
3 Halted 0 ms 0 KB -