Submission #28263

# Submission time Handle Problem Language Result Execution time Memory
28263 2017-07-16T04:15:48 Z 볼빨간 승관이(#1152, sys7961, deneb2016, hyorothy) Play Onwards (FXCUP2_onward) C++
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>

int n, k;
char str[210][25];
long long B = 255;
bool connect(int a, int b) {
	std::unordered_set<long long> set;
	for (int i = 0; str[a][i + k -1] != '\0'; i++) {
		long long h = 0;
		for (int j = 0; j < k; j++) {
			h *= B;
			h += str[a][i+j];
		}
		set.insert(h);
	}
	for (int i = 0; str[b][i + k -1] != '\0'; i++) {
		long long h = 0;
		for (int j = 0; j < k; j++) {
			h *= B;
			h += str[b][i+j];
		}
		if (set.count(h))return true;
	}
	return false;

}
using std::vector;
vector<int> G[210];
int color[210];
bool dfs(int idx) {
	for (int to : G[idx]) {
		if (color[to] == 0) {
			color[to] = -color[idx];
			if (!dfs(to)) {
				return false;
			}
		}
		else if (color[to] == color[idx]) {
			return false;
		}
	}
	return true;
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%s", str[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (connect(i, j)) {
				G[i].push_back(j);
				G[j].push_back(i);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (color[i] == 0) {
			color[i] = 1;
			if (!dfs(i)) {
				printf("No");
				return 0;
			}
		}
	}
	printf("Yes\n");
	for (int i = 0; i < n; i++) {
		if (color[i] == -1) {
			printf("2\n");
		}
		else {
			printf("1\n");
		}
	}

}

Compilation message

onward.cpp: In function 'bool connect(int, int)':
onward.cpp:7:2: error: 'unordered_set' is not a member of 'std'
  std::unordered_set<long long> set;
  ^
onward.cpp:7:21: error: expected primary-expression before 'long'
  std::unordered_set<long long> set;
                     ^
onward.cpp:14:3: error: 'set' was not declared in this scope
   set.insert(h);
   ^
onward.cpp:14:3: note: suggested alternative:
In file included from /usr/include/c++/5/set:61:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:86,
                 from onward.cpp:1:
/usr/include/c++/5/bits/stl_set.h:90:11: note:   'std::set'
     class set
           ^
onward.cpp:22:7: error: 'set' was not declared in this scope
   if (set.count(h))return true;
       ^
onward.cpp:22:7: note: suggested alternative:
In file included from /usr/include/c++/5/set:61:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:86,
                 from onward.cpp:1:
/usr/include/c++/5/bits/stl_set.h:90:11: note:   'std::set'
     class set
           ^
onward.cpp: In function 'bool dfs(int)':
onward.cpp:31:16: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
  for (int to : G[idx]) {
                ^
onward.cpp: In function 'int main()':
onward.cpp:45:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
onward.cpp:47:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", str[i]);
                      ^