Submission #28254

#TimeUsernameProblemLanguageResultExecution timeMemory
28254Sorry AcornCkiGuiziTeam (#68)Play Onwards (FXCUP2_onward)C++14
1 / 1
29 ms1448 KiB
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

char a[202][24];
int b[202];
vector<int> g[202];
int v[202], c[202];

int f(int x, int z) {
	if (v[x]) return c[x] != z;
	v[x] = 1;
	c[x] = z;
	for (auto t : g[x]) if (f(t, z ^ 1)) return 1;
	return 0;
}

int main() {
	int i, j, k, l, n, m, t;
	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%s", a[i]);
		b[i] = strlen(a[i]);
	}
	for (i = 0; i < n; i++) for (j = 0; j < i; j++) {
		for (k = -20; k <= 20; k++) {
			t = 0;
			for (l = 0; l < b[i]; l++) {
				if (l + k >= 0 && l + k < b[j] && a[i][l] == a[j][l + k]) t++;
				else t = 0;
				if (t >= m) break;
			}
			if (l < b[i]) break;
		}
		if (k <= 20) {
			g[i].push_back(j);
			g[j].push_back(i);
		}
	}
	j = 1;
	for (i = 0; i < n; i++) {
		if (!v[i] && f(i, 0)) {
			puts("No");
			return 0;
		}
		if (c[i]) j = 0;
	}
	puts("Yes");
	for (i = 0; i < n; i++) printf("%d\n", (j ? i == 0 : c[i]) + 1);
	return 0;
}

Compilation message (stderr)

onward.cpp: In function 'int main()':
onward.cpp:22:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
onward.cpp:24:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", a[i]);
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...