제출 #173655

#제출 시각아이디문제언어결과실행 시간메모리
173655NucleistPalindromes (APIO14_palindrome)C++14
23 / 100
1073 ms7760 KiB
#include<bits/stdc++.h> using namespace std; void expand(string str, int low, int high, auto &set) { // run till str[low.high] is a palindrome while (low >= 0 && high < str.length() && str[low] == str[high]) { // push all palindromes into the set set.insert(str.substr(low, high - low + 1)); // expand in both directions low--, high++; } } int ans=0; string a; vector<int> rabin_karp(string const& s, string const& t) { const int p = 31; const int m = 1e9 + 9; int S = s.size(), T = t.size(); vector<long long> p_pow(max(S, T)); p_pow[0] = 1; for (int i = 1; i < (int)p_pow.size(); i++) p_pow[i] = (p_pow[i-1] * p) % m; vector<long long> h(T + 1, 0); for (int i = 0; i < T; i++) h[i+1] = (h[i] + (t[i] - 'a' + 1) * p_pow[i]) % m; long long h_s = 0; for (int i = 0; i < S; i++) h_s = (h_s + (s[i] - 'a' + 1) * p_pow[i]) % m; vector<int> occurences; for (int i = 0; i + S - 1 < T; i++) { long long cur_h = (h[i+S] + m - h[i]) % m; if (cur_h == h_s * p_pow[i] % m) occurences.push_back(i); } return occurences; } void allPalindromicSubstrings(string str) { unordered_set<string> set; for (int i = 0; i < str.length(); i++) { expand(str, i, i, set); expand(str, i, i + 1, set); } for (auto i : set) ans=max(ans,(int)((rabin_karp(i,a).size())*i.size())); } int main() { cin>>a; allPalindromicSubstrings(a); cout<<ans; }

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

palindrome.cpp: In function 'void allPalindromicSubstrings(std::__cxx11::string)':
palindrome.cpp:47:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < str.length(); i++)
                   ~~^~~~~~~~~~~~~~
palindrome.cpp: In instantiation of 'void expand(std::__cxx11::string, int, int, auto:1&) [with auto:1 = std::unordered_set<std::__cxx11::basic_string<char> >; std::__cxx11::string = std::__cxx11::basic_string<char>]':
palindrome.cpp:49:26:   required from here
palindrome.cpp:6:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (low >= 0 && high < str.length()
                      ~~~~~^~~~~~~~~~~~~~
#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...