Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
tle了什么鬼……#include<cstring> #include<cstdio> const int NN = 805000; int wa[NN], wb[NN], flag[4000], sa[NN], height[NN], rank[NN], num[NN], s[NN], w[NN], wv[NN]; char str1[4000]; int *x, *t, *y; int p, count1, l1, xx, k, m, n, mid, l, r, ans, anss; bool aa; int check(int x, int f){ int count = 0; memset(flag, 0, sizeof flag); flag[s[sa[0]]] = 1; for (int i = 1; i < n; i++){ if (height[i] >= x){ if (!flag[s[sa[i]]]) count++; flag[s[sa[i]]] = 1; } else{ if (count >= f) { anss = sa[i - 1]; return 1; } count = 0; memset(flag, 0, sizeof flag); flag[s[sa[i]]] = 1; } } if (count >= f) { anss = sa[n - 1]; return 1; } else return 0; } int main(){ freopen("poj3450.in","r", stdin); freopen("poj3450.out","w", stdout); while (1){ scanf("%d", &xx); if (!xx) break; m = 27; n = 0; for (int i = 0; i < xx; i++){ scanf("%s", str1); l1 = strlen(str1); for (int j = 0; j < l1; j++){ num[n] = str1[j] - 'a' + 1; s[n++] = i+1; } num[n] = m++; s[n++] = 0; } //printf("%d %d\n", n, m); //for (int i = 0; i < n; i++) printf("%d ", num[i]); //printf("\n"); //for (int i = 0; i < n; i++) printf("%d ", s[i]); //printf("\n"); x = wa; y = wb; memset(w, 0, sizeof w); for (int i = 0; i < n; i++) w[x[i] = num[i]]++; for (int i = 1; i < m; i++) w[i] += w[i - 1]; for (int i = n - 1; i >= 0; i--) sa[--w[num[i]]] = i; for (int j = 1; j <= n; j+=j){ p = 0; for (int i = n - j; i < n; i++) y[p++] = i; for (int i = 0; i < n; i++) if (sa[i] >= j) y[p++] = sa[i] - j; for (int i = 0; i < n; i++) wv[i] = x[y[i]]; memset(w, 0, sizeof w); for (int i = 0; i < n; i++) w[wv[i]]++; for (int i = 1; i < m; i++) w[i] += w[i - 1]; for (int i = n - 1; i >= 0;i--) sa[--w[wv[i]]] = y[i]; t = x; x = y; y = t; x[sa[0]] = 0; m = 1; for (int i = 1; i < n; i++) x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + j] == y[sa[i - 1] + j])? m - 1:m++; if (m == n) break; } for (int i = 0; i < n; i++) rank[sa[i]] = i; //for (int i = 0; i < n; i++) printf("%d ", sa[i]); //printf("\n"); k = 0; for (int i = 0; i < n; i++){ if (!rank[i]) k = 0; else{ if (k) k--; while (num[i + k] == num[sa[rank[i] - 1] + k]) k++; } height[rank[i]] = k; } //for (int i = 0; i < n; i++) printf("%d ", height[i]); //printf("\n"); //for (int i = 0; i < n; i++) printf("%d ", s[sa[i]]); //printf("\n"); l = 0; r = n; ans = 0; while (l <= r){ mid = (l + r) >> 1; if (check(mid, xx - 1)){ ans = mid; l = mid + 1; } else r = mid - 1; //printf("%d %d\n", check(mid, xx - 1), mid); } if (ans == 0) printf("IDENTITY LOST\n"); else{ for (int i = anss; i < anss + ans; i++) printf("%c", num[i] - 1 + 'a'); printf("\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator