제출 #362034

#제출 시각아이디문제언어결과실행 시간메모리
362034dolphingarlicNecklace (Subtask 4) (BOI19_necklace4)C++14
15 / 15
375 ms752 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; int p1[6002], p2[6002]; void fill_p(string s, int *p) { for (int i = 1; i < s.size(); i++) { int j = p[i - 1]; while (j && s[i] != s[j]) j = p[j - 1]; if (s[i] == s[j]) j++; p[i] = j; } } tuple<int, int, int> solve(string s, string t, bool rev) { tuple<int, int, int> ans = {0, 0, 0}; for (int i = 0; i < s.size(); i++) { string s1 = s.substr(0, i), s2 = s.substr(i, s.size() - i); reverse(s1.begin(), s1.end()); string t1 = t, t2 = t; reverse(t2.begin(), t2.end()); fill_p(s1 + "#" + t1, p1), fill_p(s2 + "#" + t2, p2); for (int j = 1; j <= t.size(); j++) ans = max(ans, { p1[i + j] + p2[s.size() + t.size() - i - j], i - p1[i + j], rev ? t.size() - j - p2[s.size() + t.size() - i - j] : j - p1[i + j] }); } return ans; } int main() { cin.tie(0)->sync_with_stdio(0); string s, t; cin >> s >> t; tuple<int, int, int> ans = solve(s, t, false); reverse(t.begin(), t.end()); ans = max(ans, solve(s, t, true)); cout << get<0>(ans) << '\n' << get<1>(ans) << ' ' << get<2>(ans); return 0; }

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

necklace.cpp: In function 'void fill_p(std::string, int*)':
necklace.cpp:8:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for (int i = 1; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
necklace.cpp: In function 'std::tuple<int, int, int> solve(std::string, std::string, bool)':
necklace.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for (int i = 0; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
necklace.cpp:24:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for (int j = 1; j <= t.size(); j++)
      |                   ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...