제출 #857123

#제출 시각아이디문제언어결과실행 시간메모리
857123hgglmaoNecklace (Subtask 4) (BOI19_necklace4)C++17
15 / 15
220 ms852 KiB
#include <bits/stdc++.h> #define TASK "necklace" using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ll> ill; typedef pair<ll, int> lli; typedef pair<ll, ll> pll; const int MAX = 6001; const int MOD = 1e9 + 7; string a, b; int na, nb; int rs, ra, rb; int k1[MAX], k2[MAX]; void KYS(string s, int *kys) { kys[0] = 0; for (int i = 1; i < s.size(); ++i) { int j = kys[i - 1]; while (j > 0 && s[i] != s[j]) j = kys[j - 1]; if (s[i] == s[j]) kys[i] = j + 1; else kys[i] = 0; } } void SOLVE(bool revb) { for (int i = 0; i < na; ++i) { string al = a.substr(0, i), ar = a.substr(i, na - i); string bl = b, br = b; reverse(al.begin(), al.end()); reverse(br.begin(), br.end()); KYS(al + "!" + bl, k1); KYS(ar + "!" + br, k2); for (int j = 1; j <= nb; ++j) if (rs < k1[i + j] + k2[na + nb - i - j]) { rs = k1[i + j] + k2[na + nb - i - j]; ra = i - k1[i + j]; if (revb) rb = nb - j - k2[na + nb - i - j]; else rb = j - k1[i + j]; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } cin >> a >> b; na = a.size(), nb = b.size(); SOLVE(0); reverse(b.begin(), b.end()); SOLVE(1); cout << rs << '\n' << ra << ' ' << rb; }

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

necklace.cpp: In function 'void KYS(std::string, int*)':
necklace.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int i = 1; i < s.size(); ++i)
      |                         ~~^~~~~~~~~~
necklace.cpp: In function 'int main()':
necklace.cpp:68:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |                 freopen(TASK ".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
necklace.cpp:69:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |                 freopen(TASK ".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...