답안 #1005417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005417 2024-06-22T12:20:33 Z anango Kitchen (BOI19_kitchen) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

int INF = 1LL<<60;

string a;
string b;
int n,m;

vector<vector<int>> match;
vector<vector<int>> smallest;


vector<pair<int,int>> solve() {
    match=vector<vector<int>>(n,vector<int>(m,0));
    smallest=vector<vector<int>>(n+1,vector<int>(m+1,INF));
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            int ct=0;
            for (int t=0; t<min(n-i, m-j); t++) {
                if (a[i+t]!=b[j+t]) {
                    break;
                }
                ct++;
            }
            match[i][j] = ct;
        }
    }
    for (int x=0; x<n; x++) {
        for (int t=0; t<m; t++) {
            for (int r=t; r<=t+match[x][t]; r++) {
                smallest[x][r] = min(smallest[x][r],t);
            }
        }
    }
    int ans = 0;
    pair<int,int> xpos,ypos;
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            int M = match[i][j];
            int x = i+M;
            int tau = smallest[x][j];
            //cout << i << " " << j << " " << M <<" " << x << " " << tau << endl;
            if (tau==INF) {
                continue;
            }
            int subans = j-tau+M;
            if (subans>ans) {
                xpos={i,i+subans-1};
                ypos={tau,j+M-1};
            }
            ans=max(ans,subans);
        }
    }
    //cout << a <<" " << b <<" " << ans <<" " << ans <<" " << xpos.first <<" " << xpos.second <<" " << ypos.first <<" " << ypos.second << endl;
    return {{ans,ans},xpos,ypos};

    
}

signed main() {
    freopen("input.txt","r", stdin);
    freopen("output.txt","w",stdout);
    cin >> a;
    cin >> b;
    n=a.size();
    m=b.size();
    vector<pair<int,int>> ans2;
    vector<int> ans(3);
    ans2=solve();
    ans[0] = ans2[0].first;
    ans[1] = ans2[1].first;
    ans[2] = ans2[2].first;
    reverse(b.begin(), b.end());
    ans2 = solve();
    if (ans2[0].first>ans[0]) {
        ans[0] = ans2[0].first;
        ans[1] = ans2[1].first;
        ans[2] = m-ans2[2].second-1;
    }
    reverse(a.begin(), a.end());
    ans2 = solve();
    if (ans2[0].first>ans[0]) {
        ans[0] = ans2[0].first;
        ans[1] = n-ans2[1].second-1;
        ans[2] = m-ans2[2].second-1;
    }
    reverse(b.begin(), b.end());
    ans2 = solve();
    if (ans2[0].first>ans[0]) {
        ans[0] = ans2[0].first;
        ans[1] = n-ans2[1].second-1;
        ans[2] = ans2[2].first;
    }
    cout << ans[0] << endl;
    cout << ans[1] <<" " << ans[2] << endl;


    //want to store for each x and j, the smallest t such that match[x][t]+t = j
    

}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:63:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |     freopen("input.txt","r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen("output.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -