https://www.acmicpc.net/problem/1195
생각 흐름
- 보자마자 슬라이딩 윈도우가 떠올랐다.
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
using namespace std;
string a,b;
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin>>a>>b;
string tmp = b;
if(a.size()<b.size()){
b=a;
a=tmp;
}
int idx = (int)b.size()-1;
string now = "";
now+=b[idx--];
int answer = 987654321;
while(now.size()!=a.size()+b.size()){
bool ok = true;
for(int i = 0; i<min(a.size(), now.size()); i++){
if(a[i]==now[i] && now[i]=='2'){
ok=false;
break;
}
}
if(ok){
int m;
if(idx<0){
m=(int)max(a.size(), now.size());
}else{
m=(int)a.size()+idx+1;
}
answer = min(answer, m);
}
if(idx>-1){
now=b[idx--]+now;
}else{
now='1'+now;
}
}
if(answer==987654321){
answer=a.size()+b.size();
}
cout<<answer<<endl;
return 0;
}
'코딩테스트 > C++' 카테고리의 다른 글
[ 백준 BOJ ] 14595번 - 동방 프로젝트 (Large)(C++) (0) | 2025.05.30 |
---|---|
[ 백준 BOJ ] 2343번 - 기타 레슨(C++) (0) | 2025.05.28 |
[ 백준 BOJ ] 1194번 - 달이 차오른다, 가자.(C++) (0) | 2025.05.25 |
[ 백준 BOJ ] 1148번 - 단어 만들기(C++) (0) | 2025.05.12 |
[ 백준 BOJ ] 1141번 - 접두사 (C++) (0) | 2025.05.08 |