# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28687 | :thinking_face: (#68) | Play Onwards (FXCUP2_onward) | C++98 | 0 ms | 2028 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n, k;
vector<string> v;
vector<int> graph[200];
int color[200];
bool check(int i, int j)
{
if(v[i].size() < k || v[j].size() < k) return false;
for(int ii = 0; ii <= v[i].size()-k; ii++)
for(int jj = 0; jj <= v[j].size()-k; jj++)
if(v[i].substr(ii, k) == v[j].substr(jj, k))
return true;
return false;
}
void dfs(int idx, int c)
{
color[idx] = c;
for(int it: graph[idx])
{
if(color[it] == c)
{
printf("No\n");
exit(0);
}
if(color[it] == -1)
dfs(it, !c);
}
}
int main()
{
cin >> n >> k;
for(int i = 0; i < n; i++)
{
string str;
cin >> str;
v.push_back(str);
}
for(int i = 0; i < n; i++)
for(int j = i+1; j < n; j++)
if(check(i, j))
{
graph[i].push_back(j);
graph[j].push_back(i);
}
memset(color, -1, sizeof(color));
for(int i = 0; i < n; i++)
if(color[i] == -1)
dfs(i, 0);
bool check = false;
for(int i = 0; i < n; i++)
if(color[i] == 1)
check = true;
if(!check)
color[0] = 1;
printf("Yes\n");
for(int i = 0; i < n; i++)
printf("%d\n", color[i]+1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |