# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28556 | 이제 내가 두목이다~ (#68) | Play Onwards (FXCUP2_onward) | C++11 | 29 ms | 2296 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 <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
vector<int> adj[202];
int dic[202];
string str[202];
bool flag = true;
void dfs(int x, int c)
{
if(dic[x] != c && dic[x] != 0)
{
flag = false;
return;
}
if(dic[x] == c) return;
if(!flag) return;
dic[x] = c;
for(int nxt : adj[x])
{
dfs(nxt, c == 1 ? 2 : 1);
}
}
int asdf(string s, string t, int k)
{
if(s.size() < k || t.size() < k) return 0;
for(int i=0; i<(int)s.size()-k+1; i++)
{
string a = s.substr(i, k);
if(t.find(a) != string::npos) return 1;
}
return 0;
}
int main()
{
int n, k; cin >> n >> k;
for(int i=0; i<n; i++)
{
cin >> str[i];
}
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(asdf(str[i], str[j], k) || asdf(str[j], str[i], k))
{
adj[j].push_back(i);
adj[i].push_back(j);
}
}
}
for(int i=0; i<n; i++)
{
if(dic[i] == 0) dfs(i, 1);
}
if(flag)
{
cout << "Yes\n";
if(count(dic, dic+n, 1) == n) dic[0] = 2;
for(int i=0; i<n; i++) cout << dic[i] << '\n';
}
else cout << "No\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |