답안 #28542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28542 2017-07-16T07:09:16 Z Shocking Hot(#1200, khsoo01) Play Onwards (FXCUP2_onward) C++14
0 / 1
0 ms 2032 KB
#include<bits/stdc++.h>
using namespace std;
int n, k, c1[26], c2[26], mat, l[205], vis[205];
char a[205][25];

vector<int> adj[205];

void upd (int P, int V, int C1[], int C2[]) {
	if(C1[P] == C2[P]) mat--;
	C1[P] += V;
	if(C1[P] == C2[P]) mat++;
}

void solve (int I, int C) {
	if(vis[I]) return;
	vis[I] = C;
	for(auto &T : adj[I]) solve(T, ((C-1)^1)+1);
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) {
		scanf("%s",a[i]+1);
		l[i] = strlen(a[i]+1);
	}
	for(int i=1;i<=n;i++) {
		for(int j=i+1;j<=n;j++) {
			if(l[i] < k || l[j] < k) continue;
			bool flag = 0;
			for(int A=k;A<=l[i];A++) {
				for(int i=0;i<26;i++) {c1[i] = 0; c2[i] = 0;}
				mat = 26;
				for(int X=A-k+1;X<=A;X++) upd(a[i][X]-'a', 1, c1, c2);
				for(int X=1;X<k;X++) upd(a[j][X]-'a', 1, c2, c1);
				for(int X=k;X<=l[j];X++) {
					upd(a[j][X]-'a', 1, c2, c1);
					if(mat == 26) {flag = true; break;}
					upd(a[j][X-k+1]-'a', -1, c2, c1);
				}
				if(flag) break;
			}
			if(flag) {
				adj[i].push_back(j);
				adj[j].push_back(i);
			}
		}
	}
	for(int i=1;i<=n;i++) solve(i, 1);
	for(int i=1;i<=n;i++) {
		for(auto &T : adj[i]) if(vis[i] == vis[T]) {puts("No"); return 0;}
	}
	puts("Yes");
	for(int i=1;i<=n;i++) printf("%d\n",vis[i]);
}

Compilation message

onward.cpp: In function 'int main()':
onward.cpp:22:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
                     ^
onward.cpp:24:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",a[i]+1);
                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2032 KB Output is correct
2 Correct 0 ms 2032 KB Output is correct
3 Correct 0 ms 2032 KB Output is correct
4 Incorrect 0 ms 2032 KB Output isn't correct
5 Halted 0 ms 0 KB -