| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 28541 | 흐훗흐흐훗핫 (#68) | Play Onwards (FXCUP2_onward) | C++98 | 0 ms | 2044 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 <string>
#include <vector>
#include <queue>
using namespace std;
string tmp[333];
int dp[333];
vector<int> arr[333];
int main(void)
{
	int n,m;
	cin >> n >> m;
	for(int e=0;e<n;e++) cin >> tmp[e];
	for(int e=0;e<n;e++)
	{
		for(int p=e+1;p<n;p++)
		{
			int mm=0,qq=0,rr=0;
			for(int q=0;q<tmp[e].size();q++)
			{
				for(int r=0;r<tmp[p].size();r++)
				{
					if(tmp[e][q]==tmp[p][r])
					{
						rr=0;
						qq=0;
						for(int ee=r;ee<tmp[p].size()&&q+qq<tmp[e].size();ee++,qq++)
						{
							if(tmp[e][q+qq]==tmp[p][ee])
							{
								rr++;
								mm=max(mm,rr);
							}
							else
							{
								break;
							}
						}
					}
				}
			}
			if(mm>=m)
			{
				arr[e].push_back(p);
				arr[p].push_back(e);
			}
		}
	}
	queue<int> q;
	for(int e=0;e<n;e++)
	{
		if(arr[e].size())
		{
			dp[e]=1;
			q.push(e);
			break;
		}
	}
	while(!q.empty())
	{
		int now=q.front();q.pop();
		for(int e=0;e<arr[now].size();e++)
		{
			int next=arr[now][e];
			if(dp[next]==1)
			{
				if(dp[now]==1)
				{
					cout << "No";
					return 0;
				}
			}
			if(dp[next]==2)
			{
				if(dp[now]==2)
				{
					cout << "No";
					return 0;
				}
			}
			if(dp[next]==0)
			{
				if(dp[now]==1) dp[next]=2;
				if(dp[now]==2) dp[next]=1;
				q.push(next);
			}
		}
	}
	int pp=0;
	for(int e=0;e<n;e++) if(dp[e]==1) pp++;
	if(pp==0) dp[0]=1;
	if(pp==n) dp[0]=2;
	cout << "Yes\n";
	for(int e=0;e<n;e++) cout << dp[e] << "\n";
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
