| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 524494 | Jarif_Rahman | Necklace (Subtask 1-3) (BOI19_necklace1) | C++17 | 1584 ms | 108884 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
vector<str> lex(str s){
int n = s.size();
char a = *min_element(s.begin(), s.end());
vector<int> c;
for(int i = 0; i < n; i++) if(s[i] == a) c.pb(i);
vector<str> rt;
auto startswith = [&s, &n](int k){
str rt = "";
for(int i = k; i < n; i++) rt+=s[i];
for(int i = 0; i < k; i++) rt+=s[i];
return rt;
};
if(c.size() == 1) return {startswith(c[0])};
int mn = 1e9, k = -1;
for(int i = 0; i < c.size(); i++){
int ii = (i+1)%c.size();
int cur = c[i]+1;
cur+=n-c[ii];
if(cur < mn) mn = cur, k = ii;
}
if(s.size()%2 == 0 && s.size()/2 == mn-1){
return {startswith(c[k]), startswith(c[(k-1+c.size())%c.size()])};
}
else return {startswith(c[k])};
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
str s1, s2; cin >> s1 >> s2;
int n = s1.size(), m = s2.size();
unordered_map<str, pair<int, int>> mp;
for(int i = 0; i < n; i++) for(int j = i; j < n; j++){
str ss = "";
for(int k = i; k <= j; k++) ss+=s1[k];
for(str h: lex(ss)){
if(mp.find(h) == mp.end() || mp[h].f < j-i+1) mp[h] = {j-i+1, i};
}
reverse(ss.begin(), ss.end());
for(str h: lex(ss)){
if(mp.find(h) == mp.end() || mp[h].f < j-i+1) mp[h] = {j-i+1, i};
}
}
int ans = 0, a = 0, b = 0;
for(int i = 0; i < m; i++) for(int j = i; j < m; j++){
str ss = "";
for(int k = i; k <= j; k++) ss+=s2[k];
for(auto h: lex(ss)){
if(mp[h].f > ans) ans = mp[h].f, a = mp[h].sc, b = i;
}
reverse(ss.begin(), ss.end());
for(auto h: lex(ss)){
if(mp[h].f > ans) ans = mp[h].f, a = mp[h].sc, b = i;
}
}
cout << ans << "\n";
cout << a << " " << b << "\n";
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
