제출 #524674

#제출 시각아이디문제언어결과실행 시간메모리
524674fcwNecklace (Subtask 4) (BOI19_necklace4)C++17
0 / 15
379 ms452 KiB
#include <bits/stdc++.h> #define st first #define nd second using lint = int64_t; constexpr int MOD = int(1e9) + 7; constexpr int INF = 0x3f3f3f3f; constexpr int NINF = 0xcfcfcfcf; constexpr lint LINF = 0x3f3f3f3f3f3f3f3f; const long double PI = acosl(-1.0); // Returns -1 if a < b, 0 if a = b and 1 if a > b. int cmp_double(double a, double b = 0, double eps = 1e-9) { return a + eps > b ? b + eps > a ? 0 : 1 : -1; } using namespace std; template<typename T> struct kmp_t { vector<T> word; vector<int> failure; template<typename I> kmp_t(I begin, I end) { for (I iter = begin; iter != end; ++iter) word.push_back(*iter); int n = int(size(word)); failure.resize(n+1, 0); for (int s = 2; s <= n; ++s) { failure[s] = failure[s-1]; while (failure[s] > 0 && word[failure[s]] != word[s-1]) failure[s] = failure[failure[s]]; if (word[failure[s]] == word[s-1]) failure[s] += 1; } } }; array<int, 3>solve(string s, string t){ array<int, 3>ans = {0, -1, -1}; int n = (int)s.size(), m = (int)t.size(); string rt = t; reverse(rt.begin(), rt.end()); for(int i=1;i<n;i++){ string l = s.substr(0, i), r = s.substr(i, n-i); int nl = i, nr = n-i; reverse(l.begin(), l.end()); l += rt, r += t; vector<int>fl = kmp_t<int>(l.begin(), l.end()).failure; vector<int>fr = kmp_t<int>(r.begin(), r.end()).failure; fl.erase(fl.begin()); fr.erase(fr.begin()); for(int j=0;j<m-1;j++){ int k = m-j-2; if(fr[nr+j] + fl[nl+k] > ans[0]){ ans = {fr[nr+j] + fl[nl+k], i-fl[nl+k], j-fr[nr+j]+1}; } } } return ans; } int main() { cin.tie(nullptr)->sync_with_stdio(false); string s, t; cin>>s>>t; int n = (int)s.size(), m = (int)t.size(); array<int, 3>ans = solve(s, t); reverse(t.begin(), t.end()); array<int, 3>rans = solve(s, t); if(ans[0] >= rans[0]){ cout<<ans[0]<<"\n"<<ans[1]<<" "<<ans[2]<<"\n"; } else{ cout<<rans[0]<<"\n"<<rans[1]<<" "<<m-(rans[2]+rans[0])<<"\n"; } return 0; } /* [ ]Leu o problema certo??? [ ]Ver se precisa de long long [ ]Viu o limite dos fors (é n? é m?) [ ]Tamanho do vetor, será que é 2e5 em vez de 1e5?? [ ]Testar sample [ ]Testar casos de borda [ ]1LL no 1LL << i [ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?) */

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

necklace.cpp: In function 'int main()':
necklace.cpp:58:6: warning: unused variable 'n' [-Wunused-variable]
   58 |  int n = (int)s.size(), m = (int)t.size();
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...