# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
976355 | 2024-05-06T13:18:11 Z | roctes7 | Necklace (Subtask 1-3) (BOI19_necklace1) | C++17 | 244 ms | 82712 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); const double eps = 1e-6; const int MAX = 3e3+3; int pi[3003][7003]; int n; string s; void kmp(int sta){ for (int i = 1; i < n; i++){ int j = pi[sta][i-1]; while (j > 0 && s[i] != s[j]) j = pi[sta][j-1]; if (s[i] == s[j]) j++; pi[sta][i] = j; } } string t1,t2; pair<int,pair<int,int>> solve(){ for(int i=0;i<t1.size();i++){ s = ""; for(int j=i;j<t1.size();j++)s+=t1[j]; for(int j=0;j<i;j++)s+="$"; s+="#"; s+=t2; n = s.size(); kmp(i); //cout<<s<<endl; } int ans = -1; int ansl = -1; int ansr = -1; for(int i=0;i<t1.size();i++){ for(int j=t1.size()+1;j<n;j++){ int cur = pi[i][j]; if(cur>ans){ ans = cur; ansl = i; ansr = j-(t1.size()+1)-ans+1; } if(i+cur>=t1.size()||j-cur<t1.size()+1)continue; int cur2 = pi[i+cur][j-cur]; if(cur+cur2>ans){ ans = cur+cur2; ansl = i; ansr = j-(t1.size()+1)-ans+1; } } } return {ans,{ansl,ansr}}; } int main(){ fastio; cin>>t1>>t2; auto ans1 = solve(); reverse(t2.begin(),t2.end()); auto ans2 = solve(); ans2.se.se = ans2.se.se + ans2.fi-1; ans2.se.se = t2.size()-ans2.se.se-1; assert(ans2.se.se>=0); //if(ans2.se.se<0)ans2.se.se = t2.size()+ans2.se.se; pair<int,pair<int,int>> ans = max({ans1,ans2}); cout<<ans.fi<<endl<<ans.se.fi<<" "<<ans.se.se; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 860 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 860 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
6 | Correct | 6 ms | 4696 KB | Output is correct |
7 | Correct | 5 ms | 4700 KB | Output is correct |
8 | Partially correct | 5 ms | 3084 KB | Output is partially correct |
9 | Correct | 5 ms | 4444 KB | Output is correct |
10 | Correct | 5 ms | 4700 KB | Output is correct |
11 | Correct | 5 ms | 4700 KB | Output is correct |
12 | Correct | 5 ms | 4444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 860 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
3 | Correct | 1 ms | 604 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 1 ms | 860 KB | Output is correct |
6 | Correct | 6 ms | 4696 KB | Output is correct |
7 | Correct | 5 ms | 4700 KB | Output is correct |
8 | Partially correct | 5 ms | 3084 KB | Output is partially correct |
9 | Correct | 5 ms | 4444 KB | Output is correct |
10 | Correct | 5 ms | 4700 KB | Output is correct |
11 | Correct | 5 ms | 4700 KB | Output is correct |
12 | Correct | 5 ms | 4444 KB | Output is correct |
13 | Correct | 244 ms | 82712 KB | Output is correct |
14 | Correct | 215 ms | 82712 KB | Output is correct |
15 | Partially correct | 238 ms | 80208 KB | Output is partially correct |
16 | Partially correct | 227 ms | 82672 KB | Output is partially correct |
17 | Correct | 192 ms | 82516 KB | Output is correct |
18 | Correct | 198 ms | 82704 KB | Output is correct |
19 | Correct | 205 ms | 82704 KB | Output is correct |
20 | Correct | 226 ms | 82548 KB | Output is correct |
21 | Correct | 231 ms | 82560 KB | Output is correct |