답안 #874167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874167 2023-11-16T11:37:11 Z vjudge1 Necklace (Subtask 1-3) (BOI19_necklace1) C++17
25 / 85
1500 ms 444 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define ONLINE_JUDGE
void solve() {
    string a, b;
    cin >> a >> b;

    int n = int(a.size()), m = int(b.size());
    for(int len = min(n, m); len >= 1; len--) {
        for(int l = 0; l + len -1 < n; l++) {
            for(int r = 0; r + len -1 < m; r++) {
                for(int k = 0; k <= len; k++) {
                    string x = a.substr(l, len);
                    reverse(x.begin(), x.end());

                    //cerr << len << " -> " << x.substr(0, k) << " " << b.substr(r + len - k, k) << " :: " << x.substr(k, len - k) << " " << b.substr(r, len - k) << "\n";
                    if(x.substr(0, k) == b.substr(r + len - k, k) && x.substr(k, len - k) == b.substr(r, len - k)) {
                        cout << len << "\n";
                        cout << l << " " << r << "\n";
                        return;
                    }

                    //cerr << len << " -> " << a.substr(l, k) << " " << b.substr(r + len - k, k) << " :: " << a.substr(l + k, len - k) << " " << b.substr(r, len - k) << "\n";
                    if(a.substr(l, k) == b.substr(r + len - k, k) && a.substr(l + k, len - k) == b.substr(r, len - k)) {
                        cout << len << "\n";
                        cout << l << " " << r << "\n";
                        return;
                    }
                }
            }
        }
    }

    cout << 0 << "\n";
    cout << 0 << " " << 0 << "\n";
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 330 ms 348 KB Output is correct
4 Correct 455 ms 444 KB Output is correct
5 Correct 830 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 330 ms 348 KB Output is correct
4 Correct 455 ms 444 KB Output is correct
5 Correct 830 ms 432 KB Output is correct
6 Execution timed out 1548 ms 348 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 330 ms 348 KB Output is correct
4 Correct 455 ms 444 KB Output is correct
5 Correct 830 ms 432 KB Output is correct
6 Execution timed out 1548 ms 348 KB Time limit exceeded
7 Halted 0 ms 0 KB -