제출 #22817

#제출 시각아이디문제언어결과실행 시간메모리
22817카시코이 (#40)Joyful KMP (KRIII5_JK)C++11
0 / 7
0 ms9968 KiB
#include <cstdio> #include <vector> #include <cstring> #include <map> using namespace std; const int MOD = 1000000007; char s[1000010]; int pi[1000010]; int par[1000010]; vector<int> neq[30]; int lst[30], lc, col[30]; map<int, int> lid; int ans; void dfs(int d, int cc, int k){ if(d == lc){ ans += k; if(ans >= MOD) ans -= MOD; return ; } int vs = 0; for(int y : neq[d]) vs |= (1 << col[lid[y]]); for(int i = 0; i < cc; i++){ if((vs & (1 << i)) == 0){ col[d] = i; dfs(d + 1, cc, k); } } // new color col[d] = cc; dfs(d + 1, cc + 1, 1LL * k * (26 - cc) % MOD); } int getpar(int x){ if(x == par[x]) return x; return (par[x] = getpar(par[x])); } void mer(int x, int y){ int px = getpar(x), py = getpar(y); par[py] = px; } int main(){ scanf("%s", s); int L = strlen(s); for(int i = 1; i <= L; i++) par[i] = i; pi[1] = 0; for(int k = 0, i = 2; i <= L; i++){ while(k > 0 && s[i - 1] != s[k]){ // printf("not equal: %d %d\n", i, k + 1); k = pi[k]; } if(s[i - 1] == s[k]){ // printf("equal: %d %d\n", i, k + 1); mer(i, k + 1); k++; } // else printf("not equal : %d %d\n", i, k + 1); pi[i] = k; } for(int i = 1; i <= L; i++){ if(i == par[i]){ lid[i] = lc; lst[lc++] = i; // printf("%d\n", i); } } for(int k = 0, i = 2; i <= L; i++){ while(k > 0 && s[i - 1] != s[k]){ int px = lid[getpar(i)], py = lid[getpar(k + 1)]; if(px < py) neq[py].push_back(px); else neq[px].push_back(py); k = pi[k]; } if(s[i - 1] == s[k]) k++; else{ int px = lid[getpar(i)], py = lid[getpar(k + 1)]; if(px < py) neq[py].push_back(px); else neq[px].push_back(py); } pi[i] = k; } dfs(0, 0, 1); printf("%d\n", ans); puts("OVER"); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

JK.cpp: In function 'int main()':
JK.cpp:51:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s); int L = strlen(s);
                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...