알고리즘

백준 1195번 킥다운 C++

영춘권의달인 2022. 4. 12. 11:40

출처 : https://www.acmicpc.net/problem/1195

 

왼쪽 끝에서 아예 만나지 않을때부터 오른쪽 끝에서 만나지 않을때까지 비교하면서 

서로 이가 모두 만나지 않는 부분 중에서 가로 너비의 최솟값을 구하였다.

 

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>

using namespace std;
using ll = long long;

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

	string str1, str2;
	cin >> str1 >> str2;
	int ans = str1.length() + str2.length();
	int offset = str1.length();
	for (int i = -offset; i <= int(str2.length()); i++) {
		bool isAllInterloakced = true;
		for (int j = 0; j < str1.length(); j++) {
			if (i + j >= 0 && i + j < str2.length()) {
				if (str1[j] == '2' && str2[i + j] == '2')isAllInterloakced = false;
			}
		}
		if (isAllInterloakced)
			ans = min(int((max(str2.length(), i + str1.length()) - min(0, i))), ans);
			
	}
	cout << ans;
};