wordcraft(陈高远)

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <cstring>

#include <ctime>

#include <cctype>

#include <vector>

#include <map>

#include <set>

#include <algorithm>

#ifdef WIN32

#define fmt64 "%I64d"

#else

#define fmt64 "%lld"

#endif

#define PI M_PI

#define oo 0x13131313

#define iter iterator

#define fst first

#define snd second

#define PB push_back

#define MP make_pair

#define FOR(i, j, k) for (i = (j); i <= (k); ++i)

#define ROF(i, j, k) for (i = (j); i >= (k); --i)

#define FER(i, j, k) for (edge *i = j[k]; i; i = i->n)

#define FRE(i, a) for (i = a.begin(); i != a.end(); ++i)

using namespace std;

template<class T> inline bool minim(T &a, const T &b) {return b < a ? a = b, 1 : 0;}

template<class T> inline bool maxim(T &a, const T &b) {return b > a ? a = b, 1 : 0;}

template<class T> inline T sqr(const T &a) {return a * a;}

typedef unsigned int uint;

typedef long long int64;

typedef unsigned long long uint64;

typedef long double real;

#define maxn 100002

struct edge{int t; edge *n;}es[maxn], *adj = es, *lst[maxn];

void link(int i, int j)

{

    *(++adj) = (edge){j, lst[i]}, lst[i] = adj;

}

int sg[maxn], sgs[maxn]; bool ok[maxn];

struct function_get_sg

{

    int flag, f[maxn]; bool root;

    void dfs(int u, int sum)

    {

        if (u) {

            f[sum ^ sgs[u]] = flag;

            if (root && !(sum ^ sgs[u]))

                ok[u] = 1;

        }

        FER(e, lst, u) dfs(e->t, sum ^ sgs[u] ^ sg[e->t]);

    }

    void operator()(int u)

    {

        root = !u;

        FER(e, lst, u) sgs[u] ^= sg[e->t];

        ++flag, dfs(u, 0);

        for (int i = 0; ; ++i) if (f[i] != flag) {sg[u] = i; return;}

    }

} get_sg;

void dfs(int u)

{

    FER(e, lst, u)

        dfs(e->t);

    get_sg(u);

}

int n, maxLen; char st[maxn][105], *tt;

inline bool prefix(char *s, char *t)

{

    for (; *t; ++s, ++t) if (!*s || *s != *t) break;

    return !*s;

}

void input()

{

    int i, j; static int fa[maxn];

    scanf("%d%d\n", &n, &maxLen);

    FOR(i, 1, n) {

        char *c = st[i], *s = c;

        for (; ~(*c = getchar()) && *c != '\n'; ++c);

        *c = 0;

        for (j = i - 1; j && !prefix(st[j], s); j = fa[j]);

        link(j, i), fa[i] = j;

    }

}

void print()

{

    int i, j = 0;

    FOR(i, 1, n) if (ok[i]) {

        char *s = st[i];

        for (; *s; ++s)

            if (putchar(*s), ++j == 50) putchar('\n'), j = 0;

    }

}

int main()

{

    input();

    dfs(0);

    if (!sg[0]) puts("Can’t win at all!!"), exit(0);

    print();

}


你可能感兴趣的:(word)