Submission #1128

#TimeUsernameProblemLanguageResultExecution timeMemory
1128tncks0121백신 (KOI13_vaccine)C++98
24 / 24
373 ms39992 KiB
#include <stdio.h> #include <algorithm> using namespace std; int n, k; int m[1000]; int str[1000][10000]; int failure[10000]; bool ans; void input () { FILE* fp = stdin; fscanf (fp, "%d%d", &n, &k); n*=10; for (int i=0; i<n; i+=10) { fscanf (fp, "%d", &m[i]); for (int j=0; j<m[i]; j++) fscanf (fp, "%d", &str[i][j]); for(int k=i+1; k<i+10; k++) { m[k]=m[i]; for(int j=0; j<m[k]; j++) str[k][j] = str[i][j]; } } } void reverse (int m, int* arr) { for (int i=0; i<m/2; i++) swap(arr[i], arr[m-i-1]); } // kmp algorithm void get_failure_func (int* arr) { int j=-1; failure[0] = -1; for (int i=1; i<k; i++) { while (j>=0 && arr[j+1] != arr[i]) j = failure[j]; if (arr[j+1] == arr[i]) j++; failure[i] = j; } } // kmp algorithm bool find_string (int* p1, int m, int* p2) { int j=-1; for (int i=0; i<m; i++) { while (j>=0 && p2[j+1] != p1[i]) j = failure[j]; if (p2[j+1] == p1[i]) j++; if (j == k-1) return true; }return false; } bool check_answer (int* p) { for (int i=1; i<n; i++) { if (!find_string (str[i], m[i], p)) { reverse (m[i], str[i]); if (!find_string (str[i], m[i], p)) return false; } } return true; } bool solve () { if (m[0] < k) return false; for (int i=0; i<=m[0]-k; i++) { get_failure_func (str[0] + i); if (check_answer (str[0] + i)) return true; } reverse (m[0], str[0]); for (int i=0; i<=m[0]-k; i++) { get_failure_func (str[0] + i); if (check_answer (str[0] + i)) return true; } return false; } void output () { FILE* fp = stdout; if (ans) fprintf (fp, "YES\n"); else fprintf (fp, "NO\n"); } int main() { input (); ans = solve (); output (); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...