# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
28687 | :thinking_face: (#68) | Play Onwards (FXCUP2_onward) | C++98 | 0 ms | 2028 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |