diff --git a/extra/10816.cpp b/extra/10816.cpp new file mode 100644 index 0000000..5c9b396 --- /dev/null +++ b/extra/10816.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int N, M; +map m; +vector v; + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> N; + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + if (m.find(num) != m.end()) + { + m[num]++; + } + else + { + m.insert({num, 1}); + v.push_back(num); // 중복없이 저장 + } + } + + sort(v.begin(), v.end()); + + cin >> M; + for (int i = 0; i < M; i++) + { + int num; + cin >> num; + if (binary_search(v.begin(), v.end(), num)) + { + cout << m[num]; + } + else + { + cout << 0; + } + + if (i != M - 1) + { + cout << " "; + } + } +} \ No newline at end of file diff --git a/extra/10870.cpp b/extra/10870.cpp new file mode 100644 index 0000000..4285172 --- /dev/null +++ b/extra/10870.cpp @@ -0,0 +1,27 @@ +#include + +using namespace std; + +int n; + +int F[21] = { + 0, +}; + +void go() +{ + F[0] = 0; + F[1] = 1; + for (int i = 2; i <= n; i++) + { + F[i] = F[i - 1] + F[i - 2]; + } +} + +int main() +{ + cin >> n; + go(); + + cout << F[n]; +} \ No newline at end of file diff --git a/extra/1654.cpp b/extra/1654.cpp new file mode 100644 index 0000000..510e4aa --- /dev/null +++ b/extra/1654.cpp @@ -0,0 +1,60 @@ +#include + +using namespace std; + +int K, N; +vector v; +int max_len = 1; +long long sum = 0; + +void b_search() +{ + long long low = 0; + long long high = sum / N; + // 다 합한 뒤 필요한 개수로 나눔 = 최대 길이 + while (low <= high) + { + long long mid = (low + high) / 2; + if (mid == 0) + { + return; + } + // 각 랜선을 최대 길이로 나눈 몫의 합이 N과 같거나 클때 까지 연산 + int cnt = 0; + for (int i = 0; i < K; i++) + { + + cnt += v[i] / mid; + } + + if (cnt >= N) + { + if (max_len < mid) + max_len = mid; + low = mid + 1; + } + else if (cnt < N) + { + high = mid - 1; + } + } +} + +int main() +{ + + cin >> K >> N; + for (int i = 0; i < K; i++) + { + int a; + cin >> a; + v.push_back(a); + sum += a; + } + + b_search(); + + cout << max_len; + + return 0; +} \ No newline at end of file diff --git a/extra/17843.cpp b/extra/17843.cpp new file mode 100644 index 0000000..368d0e5 --- /dev/null +++ b/extra/17843.cpp @@ -0,0 +1,38 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin >> n; + while (n--) + { + int h, m, s; + cin >> h >> m >> s; + + // 시침: 1시간 30도 / 1분 0.5도 / 1초 0.008333 + double a = 30 * h + m * (0.5) + s * 0.008333333; + + // 분침: 1분 6도 / 1초 0.1도 + double b = m * 6 + s * 0.1; + + // 초침: 1초 6도 + double c = 6 * s; + + double temp1 = abs(a - b); + double temp2 = abs(a - c); + double temp3 = abs(b - c); + + if (temp1 > 180) + temp1 = 360 - temp1; + if (temp2 > 180) + temp2 = 360 - temp2; + if (temp3 > 180) + temp3 = 360 - temp3; + + double answer = min({temp1, temp2, temp3}); + + cout << fixed << setprecision(6) << answer << '\n'; + } +} \ No newline at end of file diff --git a/extra/181832.cpp b/extra/181832.cpp new file mode 100644 index 0000000..e82a69b --- /dev/null +++ b/extra/181832.cpp @@ -0,0 +1,55 @@ +#include + +using namespace std; +int a[30][30] = { + 0, +}; + +vector> solution(int n) +{ + int curr = 1; + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + if (!a[i][j]) + { + a[i][j] = curr; + curr++; + } + } + for (int j = 0; j < n; j++) + { + if (!a[j][n - i - 1]) + { + a[j][n - i - 1] = curr; + curr++; + } + } + for (int j = 0; j < n; j++) + { + if (!a[n - i - 1][n - 1 - j]) + { + a[n - i - 1][n - 1 - j] = curr; + curr++; + } + } + for (int j = 0; j < n; j++) + { + if (!a[n - 1 - j][i]) + { + a[n - 1 - j][i] = curr; + curr++; + } + } + } + vector> answer(n, vector(n, 0)); + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + answer[i][j] = a[i][j]; + } + } + return answer; +} \ No newline at end of file diff --git a/extra/1845.cpp b/extra/1845.cpp new file mode 100644 index 0000000..10bab42 --- /dev/null +++ b/extra/1845.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +map m; + +int solution(vector nums) +{ + for (int num : nums) + { + if (m.find(num) != m.end()) + { + m[num]++; + } + else + { + m.insert({num, 1}); + } + } + + // 가져갈 포켓몬 수 + int total = nums.size() / 2; + + int answer = m.size(); + if (answer > total) + return total; + return answer; +} \ No newline at end of file diff --git a/extra/1920.cpp b/extra/1920.cpp new file mode 100644 index 0000000..835a11d --- /dev/null +++ b/extra/1920.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int N, M; +vector a; + +int b_search(int target, int low, int high) +{ + while (low <= high) + { + int mid = (low + high) / 2; + if (a[mid] == target) + return 1; + + if (a[mid] > target) + { + high = mid - 1; + } + else if (a[mid] < target) + { + low = mid + 1; + } + } + + return 0; +} + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + cin >> N; + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + a.push_back(num); + } + + sort(a.begin(), a.end()); + + cin >> M; + for (int i = 0; i < M; i++) + { + int num; + cin >> num; + cout << b_search(num, 0, a.size() - 1) << '\n'; + } + return 0; +} \ No newline at end of file diff --git a/extra/2578.cpp b/extra/2578.cpp new file mode 100644 index 0000000..1667383 --- /dev/null +++ b/extra/2578.cpp @@ -0,0 +1,94 @@ +#include + +using namespace std; + +int a[5][5] = { + 0, +}; + +vector> v(26, {0, 0}); + +int cnt = 0; +int answer = 0; + +bool check(int y, int x) +{ + // 당장 바뀐 부분만 체크 + bool w = true; + bool h = true; + bool c1 = true; + bool c2 = true; + + // 가로, 세로, 대각선 + for (int i = 0; i < 5; i++) + { + if (a[y][i] != 1) + w = false; + + if (a[i][x] != 1) + h = false; + + if (y == x) + { + if (a[i][i] != 1) + c1 = false; + } + else + { + c1 = false; + } + + if (y + x == 4) + { + if (a[4 - i][i] != 1) + c2 = false; + } + else + { + c2 = false; + } + } + + if (w) + cnt++; + if (h) + cnt++; + if (c1) + cnt++; + if (c2) + cnt++; + + if (cnt >= 3) + return true; + + return false; +} + +int main() +{ + for (int i = 0; i < 5; i++) + { + for (int j = 0; j < 5; j++) + { + int num; + cin >> num; + v[num] = {i, j}; + } + } + + for (int i = 0; i < 25; i++) + { + int num, y, x; + cin >> num; + tie(y, x) = v[num]; + a[y][x] = 1; + if (check(y, x)) + { + if (answer == 0) + answer = i + 1; + } + } + + cout << answer; + return 0; +} \ No newline at end of file diff --git a/extra/2579.cpp b/extra/2579.cpp new file mode 100644 index 0000000..70842b2 --- /dev/null +++ b/extra/2579.cpp @@ -0,0 +1,41 @@ +#include + +using namespace std; + +int A[301] = { + 0, +}; + +int DP[301] = { + 0, +}; + +int answer = 0; +int n; + +void go() +{ + DP[1] = A[1]; + DP[2] = A[1] + A[2]; + DP[3] = max(A[1] + A[3], A[2] + A[3]); + for (int i = 4; i <= n; i++) + { + DP[i] = max(DP[i - 2] + A[i], DP[i - 3] + A[i - 1] + A[i]); + } +} + +int main() +{ + cin >> n; + + for (int i = 1; i <= n; i++) + { + int a; + cin >> a; + A[i] = a; + } + + go(); + + cout << DP[n]; +} \ No newline at end of file diff --git a/extra/2805.cpp b/extra/2805.cpp new file mode 100644 index 0000000..4a20bb4 --- /dev/null +++ b/extra/2805.cpp @@ -0,0 +1,46 @@ +#include + +using namespace std; + +int N, M; +vector v; + +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + v.push_back(num); + } + + sort(v.begin(), v.end()); + + int start = 0; + int end = v[N - 1]; // 가장 큰 나무 + int max = -1; + + while (start <= end) + { + long long sum = 0; + int mid = (start + end) / 2; + + for (int i = 0; i < N; i++) + { + if (v[i] - mid > 0) + sum += v[i] - mid; // 자른 나무 길이 + } + + if (sum >= M) + { + start = mid + 1; + if (mid > max) + max = mid; + } + else + end = mid - 1; + } + + cout << max; +} \ No newline at end of file diff --git a/extra/42578.cpp b/extra/42578.cpp new file mode 100644 index 0000000..e28c878 --- /dev/null +++ b/extra/42578.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +map m; + +int solution(vector> clothes) +{ + int a = clothes.size(); + for (int i = 0; i < a; i++) + { + if (m.find(clothes[i][1]) != m.end()) + { + m[clothes[i][1]]++; + } + else + { + m.insert({clothes[i][1], 1}); + } + } + int answer = 1; + for (auto it = m.begin(); it != m.end(); it++) + { + answer *= (it->second + 1); + } + + return answer - 1; +} \ No newline at end of file diff --git a/extra/42859.cpp b/extra/42859.cpp new file mode 100644 index 0000000..6ee2831 --- /dev/null +++ b/extra/42859.cpp @@ -0,0 +1,81 @@ +#include + +using namespace std; +const int MAX = 10000000; +int a[MAX] = {0}; +vector arr[9]; + +int getException(int i, int n) +{ + int val = n; + for (int j = 0; j < i - 1; j++) + { + val = val * 10 + n; + } + return val; +} + +int solution(int N, int number) +{ + arr[1].push_back(N); + a[N] = 1; + + for (int i = 2; i < 9; i++) + { + int exceptionVal = getException(i, N); + if (exceptionVal < MAX) + { // getException 값이 MAX 이하인지 확인 + arr[i].push_back(exceptionVal); + a[exceptionVal] = i; // 배열에 접근하기 전 확인 + } + long long temp1, temp2, temp3, temp4; + for (int j = 1; j < i; j++) + { + for (int k = 0; k < arr[j].size(); k++) + { + for (int l = 0; l < arr[i - j].size(); l++) + { + // 곱셈 연산 + temp1 = arr[j][k] * arr[i - j][l]; + if (temp1 > 0 && temp1 < MAX && a[temp1] == 0) + { + arr[i].push_back(temp1); + a[temp1] = i; + } + + // 나눗셈 연산 (0으로 나누기 방지) + if (arr[i - j][l] != 0) + { + temp2 = arr[j][k] / arr[i - j][l]; + if (temp2 > 0 && temp2 < MAX && a[temp2] == 0) + { + arr[i].push_back(temp2); + a[temp2] = i; + } + } + + // 더하기 연산 + temp3 = arr[j][k] + arr[i - j][l]; + if (temp3 > 0 && temp3 < MAX && a[temp3] == 0) + { + arr[i].push_back(temp3); + a[temp3] = i; + } + + // 빼기 연산 + temp4 = arr[j][k] - arr[i - j][l]; + if (temp4 > 0 && temp4 < MAX && a[temp4] == 0) + { + arr[i].push_back(temp4); + a[temp4] = i; + } + } + } + } + } + + int answer = a[number]; + if (answer == 0) + return -1; + return answer; +} diff --git a/extra/43105-1.cpp b/extra/43105-1.cpp new file mode 100644 index 0000000..935755d --- /dev/null +++ b/extra/43105-1.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +using namespace std; + +int n = 0; + +int solution(vector> triangle) +{ + n = triangle.size(); + vector> dp = triangle; + dp[0][0] = triangle[0][0]; + dp[1][0] = triangle[0][0] + triangle[1][0]; + dp[1][1] = triangle[0][0] + triangle[1][1]; + + for (int i = 2; i < n; i++) + { + dp[i][0] = dp[i - 1][0] + triangle[i][0]; + for (int j = 1; j < i; j++) + { + dp[i][j] = max(dp[i - 1][j - 1] + triangle[i][j], dp[i - 1][j] + triangle[i][j]); + } + dp[i][i] = dp[i - 1][i - 1] + triangle[i][i]; + } + + int answer = dp[n - 1][0]; + for (int i = 1; i < n; i++) + { + answer = max(answer, dp[n - 1][i]); + } + + return answer; +} \ No newline at end of file diff --git a/extra/43105.-2.cpp b/extra/43105.-2.cpp new file mode 100644 index 0000000..5af7b3e --- /dev/null +++ b/extra/43105.-2.cpp @@ -0,0 +1,16 @@ +#include + +using namespace std; + +int solution(vector> triangle) +{ + int h = triangle.size(); + for (int i = h - 2; i >= 0; i--) + { + for (int j = 0; j <= i; j++) + { + triangle[i][j] = max(triangle[i][j] + triangle[i + 1][j], triangle[i][j] + triangle[i + 1][j + 1]); + } + } + return triangle[0][0]; +} \ No newline at end of file diff --git a/extra/43162.cpp b/extra/43162.cpp new file mode 100644 index 0000000..f30c325 --- /dev/null +++ b/extra/43162.cpp @@ -0,0 +1,32 @@ +#include + +using namespace std; +vector visited(200, 0); +vector> computer; +int N; + +void dfs(int here) +{ + visited[here] = 1; + for (int i = 0; i < N; i++) + { + if (visited[i] == 0 && computer[here][i]) + dfs(i); + } +} + +int solution(int n, vector> computers) +{ + computer = computers; + N = n; + int answer = 0; + for (int i = 0; i < n; i++) + { + if (visited[i] == 0) + { + dfs(i); + answer++; + } + } + return answer; +} \ No newline at end of file diff --git a/extra/43163.cpp b/extra/43163.cpp new file mode 100644 index 0000000..a8b4fd3 --- /dev/null +++ b/extra/43163.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +queue q; +map visited; + +int solution(string begin, string target, vector words) +{ + for (string i : words) + { + visited.insert({i, 0}); + } + int wordlen = begin.length(); + + q.push(begin); + while (!q.empty()) + { + begin = q.front(); + q.pop(); + + if (begin == target) + break; + for (int i = 0; i < words.size(); i++) + { + int cnt = 0; + for (int j = 0; j < wordlen; j++) + { + if (begin[j] != words[i][j]) + cnt++; + } + if (cnt == 1 && !visited[words[i]]) + { + q.push(words[i]); + visited[words[i]] = visited[begin] + 1; + } + } + } + return visited[target]; +} \ No newline at end of file diff --git a/extra/49189.cpp b/extra/49189.cpp new file mode 100644 index 0000000..b7211f6 --- /dev/null +++ b/extra/49189.cpp @@ -0,0 +1,50 @@ +#include + +using namespace std; + +vector adj[20001]; +vector visited(20001, 0); +queue q; + +int solution(int n, vector> edge) +{ + for (int i = 0; i < edge.size(); i++) + { + adj[edge[i][0]].push_back(edge[i][1]); + adj[edge[i][1]].push_back(edge[i][0]); + } + + q.push(1); + visited[1] = 1; + while (!q.empty()) + { + int here = q.front(); + q.pop(); + for (int there : adj[here]) + { + if (!visited[there]) + { + q.push(there); + visited[there] = visited[here] + 1; + } + } + } + + sort(visited.begin(), visited.end(), greater<>()); + int max = visited[0]; + int answer = 0; + + for (int i : visited) + { + if (i == max) + { + answer++; + } + else + { + return answer; + } + } + + return answer; +} \ No newline at end of file diff --git a/week1/10808.cpp b/week1/10808.cpp new file mode 100644 index 0000000..dcedf1f --- /dev/null +++ b/week1/10808.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +vector alphabet(26, 0); + +int main() +{ + string str; + cin >> str; + + for (char i : str) + { + int idx = i - 'a'; + alphabet[idx] = alphabet[idx] + 1; + } + + // 출력 + for (int i : alphabet) + { + cout << i << " "; + } +} \ No newline at end of file diff --git a/week1/10988.cpp b/week1/10988.cpp new file mode 100644 index 0000000..3983f17 --- /dev/null +++ b/week1/10988.cpp @@ -0,0 +1,20 @@ +#include + +using namespace std; +int main() +{ + string str; + cin >> str; + + for (int i = 0; i < str.length(); i++) + { + if (str[i] != str[str.length() - 1 - i]) + { + cout << 0; + return 0; + } + } + + cout << 1; + return 0; +} \ No newline at end of file diff --git a/week1/1159.cpp b/week1/1159.cpp new file mode 100644 index 0000000..7da4fc7 --- /dev/null +++ b/week1/1159.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + +vector v(26, 0); +int main() +{ + int n; + cin >> n; + + for (int i = 0; i < n; i++) + { + string name; + cin >> name; + int idx = name[0] - 'a'; + v[idx] = v[idx] + 1; + } + + // 출력 + bool isPredaja = true; + + for (int i = 0; i < v.size(); i++) + { + if (v[i] >= 5) + { + isPredaja = false; + cout << char('a' + i); + } + } + + if (isPredaja == true) + { + cout << "PREDAJA"; + } +} \ No newline at end of file diff --git a/week1/11655.cpp b/week1/11655.cpp new file mode 100644 index 0000000..8e04ae1 --- /dev/null +++ b/week1/11655.cpp @@ -0,0 +1,28 @@ +#include + +using namespace std; + +int main() +{ + string s; + getline(cin, s); + + for (int i : s) + { + if (i <= 'Z' && i >= 'A') + { + // 대문자 + cout << char('A' + (i - 'A' + 13) % 26); + } + else if ( + i <= 'z' && i >= 'a') + { + // 소문자 + cout << char('a' + (i - 'a' + 13) % 26); + } + else + { + cout << char(i); + } + } +} \ No newline at end of file diff --git a/week1/1213.cpp b/week1/1213.cpp new file mode 100644 index 0000000..d78a55e --- /dev/null +++ b/week1/1213.cpp @@ -0,0 +1,59 @@ +#include + +using namespace std; + +vector v(26, 0); + +string getAnswer() +{ + string pre = ""; + + char center; + int centerCnt = 0; + for (int i = 0; i < 26; i++) + { + while (v[i] > 1) + { + v[i] = v[i] - 2; + pre.push_back('A' + i); + } + if (v[i] == 1) + { + center = 'A' + i; + centerCnt++; + } + } + + string suf = pre; + reverse(suf.begin(), suf.end()); + + if (centerCnt > 1) + { + return "I'm Sorry Hansoo"; + } + else if (centerCnt == 1) + { + return pre + center + suf; + } + else + { + return pre + suf; + } +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + + string s; + cin >> s; + + for (char i : s) + { + int idx = int(i - 'A'); + v[idx] = v[idx] + 1; + } + + cout << getAnswer(); +} \ No newline at end of file diff --git a/week1/1629.cpp b/week1/1629.cpp new file mode 100644 index 0000000..f7e18fd --- /dev/null +++ b/week1/1629.cpp @@ -0,0 +1,29 @@ +#include + +using namespace std; +int main() +{ + int n; + while (cin >> n) + { + int a = 1; + int result = 1; + + while (true) + { + if (a % n == 0) + { + cout << result << "\n"; + break; + } + else + { + a = 10 * a + 1; + a %= n; + result++; + } + } + } + + return 0; +} diff --git a/week1/1940.cpp b/week1/1940.cpp new file mode 100644 index 0000000..3563c6e --- /dev/null +++ b/week1/1940.cpp @@ -0,0 +1,39 @@ +#include + +using namespace std; + +vector v(100001, 0); + +int main() +{ + int N, M; + cin >> N; + cin >> M; + + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + v[num] = 1; + } + + int cnt = 0; + for (int i = 1; i < 100001; i++) + { + if (v[i] == 1) + { + int gap = M - i; + if (gap != i && gap > 0 && gap < 100001) + { + if (v[gap] == 1) + { + cnt++; + v[i] = 0; + v[gap] = 0; + } + } + } + } + + cout << cnt; +} \ No newline at end of file diff --git a/week1/2309.cpp b/week1/2309.cpp new file mode 100644 index 0000000..497599e --- /dev/null +++ b/week1/2309.cpp @@ -0,0 +1,48 @@ +#include + +using namespace std; + +vector height(9); +int total = 0; + +pair combi() +{ + int gap = total - 100; + for (int i = 0; i < 9; i++) + { + for (int j = i + 1; j < 9; j++) + { + if (height[i] + height[j] == gap) + { + return make_pair(height[i], height[j]); + } + } + } +} + +void printAnswer() +{ + pair fake = combi(); + + for (int i : height) + { + + if (i != fake.first && i != fake.second) + cout << i << "\n"; + } +} + +int main() +{ + int num; + for (int i = 0; i < 9; i++) + { + cin >> num; + height[i] = num; + total += num; + } + + sort(height.begin(), height.end()); + + printAnswer(); +} \ No newline at end of file diff --git a/week1/2559.cpp b/week1/2559.cpp new file mode 100644 index 0000000..e2afa1a --- /dev/null +++ b/week1/2559.cpp @@ -0,0 +1,41 @@ +#include + +using namespace std; + +map m1; +map m; + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + + int N, M; + cin >> N >> M; + + for (int i = 1; i <= N; i++) + { + string key; + cin >> key; + + m1.insert({i, key}); + m.insert({key, i}); + } + + for (int i = 0; i < M; i++) + { + string s; + cin >> s; + + // 숫자이면 벡터에서 참조 + if (int(s[0] - '0') < 10) + { + cout << m1[stoi(s)] << "\n"; + } + else + { + // 문자열이면 맵에서 찾기 + cout << m[s] << "\n"; + } + } +} \ No newline at end of file diff --git a/week1/2979.cpp b/week1/2979.cpp new file mode 100644 index 0000000..b091b1d --- /dev/null +++ b/week1/2979.cpp @@ -0,0 +1,50 @@ +#include + +using namespace std; + +vector v(100, 0); + +void fillVec(int start, int end) +{ + for (int i = start; i < end; i++) + { + v[i] = v[i] + 1; + } +} + +int getAnswer(int A, int B, int C) +{ + int sum = 0; + for (int i : v) + { + if (i == 1) + { + sum += A; + } + else if (i == 2) + { + sum += B * 2; + } + else if (i == 3) + { + sum += C * 3; + } + } + + return sum; +} + +int main() +{ + int A, B, C; + cin >> A >> B >> C; + + for (int i = 0; i < 3; i++) + { + int start, end; + cin >> start >> end; + fillVec(start, end); + } + + cout << getAnswer(A, B, C); +} \ No newline at end of file diff --git a/week1/3986.cpp b/week1/3986.cpp new file mode 100644 index 0000000..5c9f033 --- /dev/null +++ b/week1/3986.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +int main() +{ + int cnt = 0; + int n; + cin >> n; + while (n--) + { + string s; + cin >> s; + + // 짝수일때만 고려 + if (s.length() % 2 == 0) + { + stack st; + for (char i : s) + { + + if (!st.empty() && st.top() == i) + { + st.pop(); + } + else + { + st.push(i); + } + } + + if (st.empty()) + { + cnt++; + } + } + } + + cout << cnt; +} \ No newline at end of file diff --git a/week1/9375.cpp b/week1/9375.cpp new file mode 100644 index 0000000..0960bb9 --- /dev/null +++ b/week1/9375.cpp @@ -0,0 +1,47 @@ +#include + +using namespace std; + +int combiCnt(map m) +{ + int mul = 1; + + for (auto it : m) + { + mul *= (it.second + 1); + } + + return mul - 1; +} +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + + int T, N; + cin >> T; + while (T--) + { + map m; + cin >> N; + + while (N--) + { + string a, b; + cin >> a >> b; + + if (m.find(b) != m.end()) + { + int temp = m[b]; + m.erase(b); + m.insert({b, temp + 1}); + } + else + { + m.insert({b, 1}); + } + } + + cout << combiCnt(m) << "\n"; + } +} \ No newline at end of file diff --git a/week1/9996.cpp b/week1/9996.cpp new file mode 100644 index 0000000..c85424c --- /dev/null +++ b/week1/9996.cpp @@ -0,0 +1,45 @@ +#include + +using namespace std; +int main() +{ + int n; + cin >> n; + + string pattern; + cin >> pattern; + + auto idx = pattern.find('*'); + + string prefix = pattern.substr(0, idx); + int prefixLen = prefix.length(); + string suffix = pattern.substr(idx + 1); + int suffixLen = suffix.length(); + + for (int i = 0; i < n; i++) + { + bool isDa = false; + string str; + cin >> str; + + if (str.length() >= prefixLen + suffixLen) + { + if (str.substr(0, prefixLen) == prefix) + { + if (str.substr(str.length() - suffixLen) == suffix) + { + isDa = true; + } + } + } + + if (isDa) + { + cout << "DA" << "\n"; + } + else + { + cout << "NE" << "\n"; + } + } +} \ No newline at end of file diff --git a/week2/1012.cpp b/week2/1012.cpp new file mode 100644 index 0000000..8688a33 --- /dev/null +++ b/week2/1012.cpp @@ -0,0 +1,68 @@ +#include + +using namespace std; +int T, N, M, K; + +int a[50][50]; +int visited[50][50]; + +vector dy = {-1, 0, 0, 1}; +vector dx = {0, 1, -1, 0}; + +void dfs(int y, int x) +{ + visited[y][x] = 1; + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= N || nx >= M) + continue; + if (a[ny][nx] == 0) + continue; + if (visited[ny][nx] == 1) + continue; + + dfs(ny, nx); + } +} + +int go() +{ + int cnt = 0; + for (int y = 0; y < N; y++) + { + for (int x = 0; x < M; x++) + { + if (a[y][x] == 1 && visited[y][x] == 0) + { + dfs(y, x); + cnt++; + } + } + } + + return cnt; +} +int main() +{ + // 입력 + cin >> T; + for (int i = 0; i < T; i++) + { + cin >> M >> N >> K; + + for (int j = 0; j < K; j++) + { + int X, Y; + cin >> X >> Y; + a[Y][X] = 1; + } + cout << go() << "\n"; + // 초기화 + memset(a, 0, sizeof(a)); + memset(visited, 0, sizeof(visited)); + } + return 0; +} \ No newline at end of file diff --git a/week2/1068.cpp b/week2/1068.cpp new file mode 100644 index 0000000..f06accd --- /dev/null +++ b/week2/1068.cpp @@ -0,0 +1,71 @@ +#include +using namespace std; + +vector child_list[50]; +int visited[50] = { + 0, +}; +int cnt = 0; + +int dfs(int here) +{ + if (visited[here] == 0) + { + visited[here] = 1; + + for (int there : child_list[here]) + { + if (!visited[there]) + dfs(there); + } + if (child_list[here].size() == 0) + { + cnt++; + } + if (child_list[here].size() == 1 && visited[child_list[here][0]] == 2) + { + cnt++; + } + } + return cnt; +} + +void removeChild(int remove) +{ + if (child_list[remove].size()) + for (int child : child_list[remove]) + { + + removeChild(child); + child_list[child].clear(); + } + + return; +} + +int main() +{ + int N; + cin >> N; + int root; + for (int i = 0; i < N; i++) + { + int p; + cin >> p; + if (p != -1) + { + child_list[p].push_back(i); + } + else + { + root = i; + } + } + int remove; + cin >> remove; + // 삭제한 노드는 이미 방문한 것으로 처리 + visited[remove] = 2; + + // 리프 노드 수 구하기 + cout << dfs(root); +} \ No newline at end of file diff --git a/week2/1325.cpp b/week2/1325.cpp new file mode 100644 index 0000000..a579879 --- /dev/null +++ b/week2/1325.cpp @@ -0,0 +1,68 @@ +#include + +using namespace std; + +vector adj[10001]; +int visited[10001] = { + 0, +}; + +int cnt = 0; + +vector result; + +void dfs(int here) +{ + visited[here] = 1; + cnt++; + + for (int there : adj[here]) + { + if (!visited[there]) + { + dfs(there); + } + } +} + +int main() +{ + int N, M; + cin >> N >> M; + for (int i = 0; i < M; i++) + { + int A, B; + cin >> A >> B; + + adj[B].push_back(A); + } + + int max = 0; + for (int j = 1; j <= N; j++) + { + dfs(j); + if (max < cnt) + { + result.clear(); + result.push_back(j); + max = cnt; + } + else if (max == cnt) + { + result.push_back(j); + } + // 초기화 + cnt = 0; + memset(visited, 0, sizeof(visited)); + } + + sort(result.begin(), result.end()); + + for (int i = 0; i < result.size() - 1; i++) + { + cout << result[i] << " "; + } + cout << result[result.size() - 1]; + + return 0; +} \ No newline at end of file diff --git a/week2/1436.cpp b/week2/1436.cpp new file mode 100644 index 0000000..5eec8f2 --- /dev/null +++ b/week2/1436.cpp @@ -0,0 +1,23 @@ +#include + +using namespace std; + +int MAX = 10000666; +vector a; + +int main() +{ + for (int i = 666; i < MAX; i++) + { + string str = to_string(i); + if (str.find("666") != string::npos) + { + a.push_back(stoi(str)); + } + } + + int N; + cin >> N; + cout << a[N - 1]; + return 0; +} \ No newline at end of file diff --git a/week2/1992.cpp b/week2/1992.cpp new file mode 100644 index 0000000..4f64971 --- /dev/null +++ b/week2/1992.cpp @@ -0,0 +1,59 @@ +#include + +using namespace std; + +string a[64]; +int N; +vector v; + +void go(pair p, int size) +{ + int y, x; + tie(y, x) = p; + int key = a[y][x]; + + if (size == 1) + { + v.push_back(char(key)); + return; + } + + for (int i = 0; i < size; i++) + { + for (int j = 0; j < size; j++) + { + if (key != a[y + i][x + j]) + { + v.push_back('('); + go({y, x}, size / 2); + go({y, x + size / 2}, size / 2); + go({y + size / 2, x}, size / 2); + go({y + size / 2, x + size / 2}, size / 2); + v.push_back(')'); + return; + } + } + } + + // 모두 같다면 + v.push_back(char(key)); + return; +} + +int main() +{ + cin >> N; + for (int i = 0; i < N; i++) + { + string s; + cin >> s; + a[i] = s; + } + + go({0, 0}, N); + + for (char a : v) + { + cout << a; + } +} \ No newline at end of file diff --git a/week2/2178.cpp b/week2/2178.cpp new file mode 100644 index 0000000..6d78cf6 --- /dev/null +++ b/week2/2178.cpp @@ -0,0 +1,63 @@ +#include + +using namespace std; + +int N, M; +string a[101]; +int cnt = 0; +int visited[101][101] = { + 0, +}; +int dy[] = {-1, 1, 0, 0}; +int dx[] = {0, 0, -1, 1}; + +queue> q; + +void bfs() +{ + // 최단거리 탐색 + //(1,1) ~(N,M) + int y = 1; + int x = 1; + + q.push(make_pair(y, x)); + visited[y][x] = 1; + + while (q.size()) + { + tie(y, x) = q.front(); + q.pop(); + + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 1 || nx < 1 || ny > N || nx > M) + continue; + if (visited[ny][nx] != 0) + continue; + if (a[ny][nx] == '0') + continue; + + q.push(make_pair(ny, nx)); + visited[ny][nx] = visited[y][x] + 1; + } + } +} +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + string str; + cin >> str; + str = '0' + str; + a[i + 1] = str; + } + + bfs(); + + cout << visited[N][M]; + return 0; +} \ No newline at end of file diff --git a/week2/2468.cpp b/week2/2468.cpp new file mode 100644 index 0000000..0aade1b --- /dev/null +++ b/week2/2468.cpp @@ -0,0 +1,86 @@ +#include + +using namespace std; + +int N; +int a[100][100] = { + 0, +}; +int visited[100][100] = { + 0, +}; + +int dy[] = {-1, 1, 0, 0}; +int dx[] = {0, 0, 1, -1}; + +int limit = 0; + +vector result; + +void dfs(int y, int x) +{ + visited[y][x] = 1; + + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= N || nx >= N) + continue; + if (visited[ny][nx]) + continue; + if (a[ny][nx] <= limit) + continue; + + dfs(ny, nx); + } +} + +void go() +{ + // 가능한 높이 = 0~100 + for (int k = 0; k < 101; k++) + { + limit = k; + int cnt = 0; + memset(visited, 0, sizeof(visited)); + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + { + if (a[i][j] > limit && visited[i][j] == 0) + { + dfs(i, j); + cnt++; + } + } + } + result.push_back(cnt); + } +} + +int main() +{ + // 입력 + cin >> N; + + for (int i = 0; i < N; i++) + { + for (int j = 0; j < N; j++) + { + int height; + cin >> height; + a[i][j] = height; + } + } + + // 높이 별 카운트 세기 + go(); + + // 최댓값 찾기 + sort(result.begin(), result.end(), greater<>()); + cout << result[0]; + + return 0; +} \ No newline at end of file diff --git a/week2/2583.cpp b/week2/2583.cpp new file mode 100644 index 0000000..5db218e --- /dev/null +++ b/week2/2583.cpp @@ -0,0 +1,92 @@ +#include + +using namespace std; +int M, N, K; + +int a[100][100] = { + 0, +}; + +int visited[100][100] = { + 0, +}; + +int cnt = 0; +int temp_width = 0; +vector width; + +const int dy[] = {-1, 1, 0, 0}; +const int dx[] = {0, 0, 1, -1}; + +void dfs(int y, int x) +{ + temp_width++; + visited[y][x] = 1; + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= M || nx >= N) + continue; + if (visited[ny][nx]) + continue; + if (a[ny][nx]) + continue; + + dfs(ny, nx); + } +} + +void go() +{ + + for (int i = 0; i < M; i++) + { + for (int j = 0; j < N; j++) + { + if (a[i][j] == 0 && !visited[i][j]) + { + dfs(i, j); + width.push_back(temp_width); + temp_width = 0; + cnt++; + } + } + } +} + +void fill(int xl, int yl, int xr, int yr) +{ + + for (int y = yl; y < yr; y++) + { + for (int x = xl; x < xr; x++) + { + a[y][x] = 1; + } + } +} +int main() +{ + cin >> M >> N >> K; + + for (int i = 0; i < K; i++) + { + int xl, yl, xr, yr; + cin >> xl >> yl >> xr >> yr; + fill(xl, yl, xr, yr); + } + + go(); + + sort(width.begin(), width.end()); + cout << cnt << '\n'; + + for (int i : width) + { + cout << i << " "; + } + + return 0; +} \ No newline at end of file diff --git a/week2/2636.cpp b/week2/2636.cpp new file mode 100644 index 0000000..c2e04d9 --- /dev/null +++ b/week2/2636.cpp @@ -0,0 +1,89 @@ +#include + +using namespace std; + +int N, M; + +int a[100][100] = { + 0, +}; + +int visited[100][100] = { + 0, +}; + +const int dy[] = {-1, 1, 0, 0}; +const int dx[] = {0, 0, 1, -1}; + +int remain = 0; +int border = 0; +int last_border = 0; +int total_time = 0; + +void dfs(int y, int x) +{ + visited[y][x] = 1; + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= N || nx >= M) + continue; + if (visited[ny][nx]) + continue; + + // 가장자리의 치즈라면 0으로 바꾸고 방문처리, 탐색은 이어서 X + if (a[ny][nx] == 1) + { + a[ny][nx] = 0; + visited[ny][nx] = 1; + border++; + } + else + { + // 빈 공간이라면 이어서 탐색 + dfs(ny, nx); + } + } +} + +void go() +{ + while (1) + { + if (remain == 0) + break; + + dfs(0, 0); + remain -= border; + last_border = border; + border = 0; + total_time++; + memset(visited, 0, sizeof(visited)); + } +} + +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + int num; + cin >> num; + a[i][j] = num; + if (num) + { + remain++; + } + } + } + + go(); + + cout << total_time << '\n'; + cout << last_border << '\n'; + return 0; +} \ No newline at end of file diff --git a/week2/2828.cpp b/week2/2828.cpp new file mode 100644 index 0000000..1ec1e03 --- /dev/null +++ b/week2/2828.cpp @@ -0,0 +1,45 @@ +#include + +using namespace std; +int N, M, J; + +int sum = 0; +pair bucket; + +pair go(int loc) +{ + + int temp = 0; + + if (loc < bucket.first) + { + temp = bucket.first - loc; + sum += temp; + bucket.first = loc; + bucket.second = bucket.second - temp; + } + else if (loc > bucket.second) + { + + temp = loc - bucket.second; + sum += temp; + bucket.first = bucket.first + temp; + bucket.second = loc; + } + + return bucket; +} +int main() +{ + cin >> N >> M; + cin >> J; + bucket = {1, M}; + for (int i = 0; i < J; i++) + { + int loc; + cin >> loc; + bucket = go(loc); + } + + cout << sum; +} \ No newline at end of file diff --git a/week2/2852.cpp b/week2/2852.cpp new file mode 100644 index 0000000..48b5b1c --- /dev/null +++ b/week2/2852.cpp @@ -0,0 +1,105 @@ +#include + +using namespace std; + +int a = 0; +int b = 0; + +int sum[3] = { + 0, +}; + +int present = 0; +string change_time = "00:00"; + +pair v[100]; +vector state; + +int calculator(string a, string b) +{ + int asec = stoi(a.substr(0, 2)) * 60 + stoi(a.substr(3, 2)); + int bsec = stoi(b.substr(0, 2)) * 60 + stoi(b.substr(3, 2)); + return abs(asec - bsec); +} + +string to_formatted_string(int num) +{ + if (num < 10) + { + return '0' + to_string(num); + } + else + { + return to_string(num); + } +} + +string format(int sum) +{ + if (sum == 0) + return "00:00"; + int min = sum / 60; + int sec = sum % 60; + + return to_formatted_string(min) + ':' + to_formatted_string(sec); +} + +int main() +{ + int n; + cin >> n; + for (int i = 0; i < n; i++) + { + pair p; + cin >> p.first >> p.second; + v[i] = p; + } + + for (pair p : v) + { + if (p.first == 1) + { + a++; + } + else if (p.first == 2) + { + b++; + } + + if (a > b) + { + state.push_back(1); + } + else if (b > a) + { + state.push_back(2); + } + else + { + state.push_back(0); + } + } + + // state가 1->0 || 2->0으로 바뀔때 저장 + // stack 1-> 1 / 2->2 일떈 누적 + for (int i = 0; i < state.size(); i++) + { + if (present != state[i]) + { + sum[present] += calculator(v[i].second, change_time); + change_time = v[i].second; + present = state[i]; + } + + // 마지막 요소 + if (i == state.size() - 1) + { + sum[present] += calculator("48:00", change_time); + } + } + + cout << format(sum[1]) << '\n'; + cout << format(sum[2]); + + return 0; +} \ No newline at end of file diff --git a/week2/2870.cpp b/week2/2870.cpp new file mode 100644 index 0000000..814b8a5 --- /dev/null +++ b/week2/2870.cpp @@ -0,0 +1,77 @@ +#include + +using namespace std; + +vector v; + +void go(string str) +{ + string num = ""; + for (char c : str) + { + if (c >= '0' && c <= '9') + { + // 숫자라면 + num += c; + } + else + { + // 문자라면 + if (num != "") + { + // 0제거 + while (num != "0" && num[0] == '0') + { + num.erase(0, 1); + } + + v.push_back(num); + } + num = ""; + } + } + + // 마지막요소라면 + if (num != "") + { + // 0제거 + while (num != "0" && num[0] == '0') + { + num.erase(0, 1); + } + v.push_back(num); + } +} + +bool cmp(string a, string b) +{ + // 문자열 길이로 비교 + if (a.length() != b.length()) + { + return a.length() < b.length(); + } + else + { + // 길이 같을 시엔 그냥 비교 + return a < b; + } +} + +int main() +{ + int n; + cin >> n; + for (int i = 0; i < n; i++) + { + string str; + cin >> str; + go(str); + } + + sort(v.begin(), v.end(), cmp); + + for (string s : v) + { + cout << s << '\n'; + } +} \ No newline at end of file diff --git a/week2/2910.cpp b/week2/2910.cpp new file mode 100644 index 0000000..7e84e70 --- /dev/null +++ b/week2/2910.cpp @@ -0,0 +1,55 @@ +#include + +using namespace std; + +int N, C; + +unordered_map> m; + +bool cmp(pair> a, pair> b) +{ + if (a.second.first == b.second.first) + return a.second.second < b.second.second; + + return a.second.first > b.second.first; +} + +int main() +{ + cin >> N >> C; + for (int i = 0; i < N; i++) + { + int num; + cin >> num; + + if (m.find(num) != m.end()) + { + m[num].first++; + } + else + { + m.insert({num, {1, i}}); + } + } + + vector>> v(m.begin(), m.end()); + + sort(v.begin(), v.end(), cmp); + + for (int i = 0; i < v.size(); i++) + { + for (int j = 0; j < v[i].second.first; j++) + { + if (i == v.size() - 1 && j == v[i].second.first - 1) + { + cout << v[i].first; + } + else + { + cout << v[i].first << " "; + } + } + } + + return 0; +} \ No newline at end of file diff --git a/week2/3474.cpp b/week2/3474.cpp new file mode 100644 index 0000000..a4a1959 --- /dev/null +++ b/week2/3474.cpp @@ -0,0 +1,40 @@ +#include + +using namespace std; + +int getCount(int num) +{ + int two = 0; + int five = 0; + + for (int i = 2; i <= num; i *= 2) + { + two += num / i; + } + for (int j = 5; j <= num; j *= 5) + { + five += num / j; + } + + return min(two, five); +} + +int main() +{ + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + int t; + cin >> t; + + for (int i = 0; i < t; i++) + { + int num; + cin >> num; + cout << getCount(num) << '\n'; + } + + return 0; +} \ No newline at end of file diff --git a/week2/4659.cpp b/week2/4659.cpp new file mode 100644 index 0000000..b3cee7f --- /dev/null +++ b/week2/4659.cpp @@ -0,0 +1,88 @@ +#include + +using namespace std; + +char a[] = {'a', 'e', 'i', 'o', 'u'}; +void check(string s) +{ + // first + bool first = false; + for (int i = 0; i < 5; i++) + { + if (s.find(a[i]) != string::npos) + first = true; + } + + if (!first) + { + cout << "<" << s << "> is not acceptable." << '\n'; + return; + } + + // 2nd + if (s.length() >= 3) + { + string copy = s; + + for (int i = 0; i < copy.length(); i++) + { + bool isA = false; + for (int j = 0; j < 5; j++) + { + if (copy[i] == a[j]) + { + isA = true; + } + } + + if (isA) + { + copy[i] = 'a'; + } + else + { + copy[i] = 'b'; + } + } + + if (copy.find("aaa") != string::npos || copy.find("bbb") != string::npos) + { + cout << "<" << s << "> is not acceptable." << '\n'; + return; + } + } + + // 3rd + if (s.length() >= 2) + { + for (int i = 0; i < s.length() - 1; i++) + { + if (s[i] == s[i + 1]) + { + if (s[i] != 'e' && s[i] != 'o') + { + cout << "<" << s << "> is not acceptable." << '\n'; + return; + } + } + } + } + + cout << "<" << s << "> is acceptable." << '\n'; + return; +} + +int main() +{ + while (1) + { + string s; + + cin >> s; + if (s == "end") + { + return 0; + } + check(s); + } +} \ No newline at end of file diff --git a/week3/1189.cpp b/week3/1189.cpp new file mode 100644 index 0000000..75d3674 --- /dev/null +++ b/week3/1189.cpp @@ -0,0 +1,72 @@ +#include + +using namespace std; + +int R, C, K; + +int a[5][5] = { + 0, +}; + +int visited[5][5] = { + 0, +}; + +int dy[] = {-1, 1, 0, 0}; +int dx[] = {0, 0, -1, 1}; + +int result = 0; + +void dfs(int y, int x, int cnt) +{ + if (cnt == K && y == 0 && x == C - 1) + { + result++; + return; + } + + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= R || nx >= C) + continue; + if (a[ny][nx] == 0) + continue; + if (visited[ny][nx] == 1) + continue; + + visited[ny][nx] = 1; + dfs(ny, nx, cnt + 1); + visited[ny][nx] = 0; // 방문해제 + } +} + +int main() +{ + + cin >> R >> C >> K; + for (int i = 0; i < R; i++) + { + for (int j = 0; j < C; j++) + { + char c; + cin >> c; + + // 갈 수 없는 곳은 0 있는 곳은 1 + if (c == 'T') + { + a[i][j] = 0; + } + else + { + a[i][j] = 1; + } + } + } + + visited[R - 1][0] = 1; + dfs(R - 1, 0, 1); + cout << result; +} \ No newline at end of file diff --git a/week3/2589.cpp b/week3/2589.cpp new file mode 100644 index 0000000..55fdc73 --- /dev/null +++ b/week3/2589.cpp @@ -0,0 +1,101 @@ +#include + +using namespace std; + +int N, M; +char a[50][50] = { + 'W', +}; + +const int dy[] = {-1, 1, 0, 0}; +const int dx[] = {0, 0, -1, 1}; + +queue> q; + +int finalMax = 0; + +int bfs(int y, int x) +{ + + int visited[50][50] = { + 0, + }; + int max = 0; + + visited[y][x] = 1; + q.push(make_pair(y, x)); + while (q.size()) + { + tie(y, x) = q.front(); + q.pop(); + + for (int i = 0; i < 4; i++) + { + int ny = y + dy[i]; + int nx = x + dx[i]; + + if (ny < 0 || nx < 0 || ny >= N || nx >= M) + continue; + if (visited[ny][nx]) + continue; + if (a[ny][nx] != 'L') + continue; + + q.push({ny, nx}); + visited[ny][nx] = visited[y][x] + 1; + } + } + + // 현 시작점에서 가장 먼 곳일때 최단 거리 찾기 + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + if (a[i][j] == 'L') + { + if (max < visited[i][j]) + max = visited[i][j]; + } + } + } + + return max - 1; +} + +void go() +{ + // 가능한 모든 시작점(육지)에서 모든 육지에 대한 최장거리를 찾기. + + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + if (a[i][j] == 'L') + { + int temp = bfs(i, j); + if (finalMax < temp) + { + finalMax = temp; + } + } + } + } +} + +int main() +{ + cin >> N >> M; + for (int i = 0; i < N; i++) + { + for (int j = 0; j < M; j++) + { + char c; + cin >> c; + a[i][j] = c; + } + } + + go(); + + cout << finalMax; +}