AcWing 5387. 词典
原题链接
困难
C++ 代码
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
int n, m;
int mn[maxn], mx[maxn];
char s[maxn];
int main() {
scanf("%d %d", &n, &m); // Read n and m
for (int i = 1; i <= n; i++) {
scanf("%s", s); // Read the string
mn[i] = mx[i] = s[0] - 'a';
for (int j = 1; j < m; j++) {
mn[i] = min(mn[i], s[j] - 'a');
mx[i] = max(mx[i], s[j] - 'a');
}
}
for (int i = 1; i <= n; i++) {
bool flag = true;
for (int j = 1; j <= n; j++) {
if (j != i && mx[j] <= mn[i]) {
flag = false;
break;
}
}
printf("%c", flag ? '1' : '0');
}
printf("\n");
return 0;
}