#include #define MAXN 1000 #define MAXM 1000 #define MAXW 1000 #define NONE -1 struct Node { int wordIdx; Node *children[26]; Node(); } nodes[MAXW*MAXN]; int nodeN=0; Node *root; Node :: Node () { wordIdx=NONE; for(int i=0; i<26; i++) children[i]=NULL; } Node *newNode () { return &nodes[nodeN++]; } void addWord(Node *cur, char *str, int wIdx) { for(int i=0; str[i]!='\0'; i++) { if(cur->children[str[i]-'A'] == NULL) cur->children[str[i]-'A'] = newNode(); cur = cur->children[str[i]-'A']; } cur->wordIdx = wIdx; } int N,M,W; char s[MAXN][MAXM+5]; char words[MAXW][MAXN+5]; void init() { root = newNode(); scanf("%d %d %d", &N, &M, &W); for(int i=0; i=0 and y=0 and xchildren[s[i+dy[d]*k][j+dx[d]*k] - 'A']; if(cur == NULL) break; if(cur->wordIdx != NONE) { foundAt[cur->wordIdx][0]=i; foundAt[cur->wordIdx][1]=j; foundDir[cur->wordIdx] = dirChr[d]; } } } } } for(int i=0; i