diff --git a/YIM2UL2ET/README.md b/YIM2UL2ET/README.md index 81be847..5a91848 100644 --- a/YIM2UL2ET/README.md +++ b/YIM2UL2ET/README.md @@ -2,5 +2,7 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| -| 1차시 | 2023.10.27 | 그리디 | [BOJ 18310](https://www.acmicpc.net/problem/18310) | [BOJ 18310 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/3) | +| 1차시 | 2024.02.12 | 그리디 | [BOJ 18310](https://www.acmicpc.net/problem/18310) | [BOJ 18310 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/3) | +| 2차시 | 2024.02.15 | 그리디 | [BOJ 1263](https://www.acmicpc.net/problem/1263) | [BOJ 1449 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/7) | +| 3차시 | 2024.02.18 | 자료구조 | [BOJ 2504](https://www.acmicpc.net/problem/2504) | [BOJ 2504 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/9) | --- diff --git "a/YIM2UL2ET/\352\267\270\353\246\254\353\224\224/2\354\260\250\354\213\234- BOJ 1263 .cpp" "b/YIM2UL2ET/\352\267\270\353\246\254\353\224\224/2\354\260\250\354\213\234- BOJ 1263 .cpp" new file mode 100644 index 0000000..fe2c22f --- /dev/null +++ "b/YIM2UL2ET/\352\267\270\353\246\254\353\224\224/2\354\260\250\354\213\234- BOJ 1263 .cpp" @@ -0,0 +1,41 @@ +#include +#include +#include + +bool compare(std::vector &vec1, std::vector &vec2); + +int main(void) +{ + int n, result, end_time; + std::cin >> n; + + std::vector > vec(n); + for (int i = 0; i < n; i++) { + int t, s; + std::cin >> t >> s; + vec[i].push_back(t); + vec[i].push_back(s); + } + + std::sort(vec.begin(), vec.end(), compare); + + result = vec[0][1] - vec[0][0], end_time = vec[0][1]; + for (int i = 1; i < n; i++) { + if (end_time + vec[i][0] > vec[i][1]) { + result -= end_time + vec[i][0] - vec[i][1]; + end_time = vec[i][1]; + } + else end_time += vec[i][0]; + } + + if (result < 0) std::cout << "-1"; + else std::cout << result; + + return 0; +} + +bool compare(std::vector &vec1, std::vector &vec2) +{ + if (vec1[1] == vec2[1]) return vec1[0] < vec2[0]; + else return vec1[1] < vec2[1]; +} \ No newline at end of file diff --git "a/YIM2UL2ET/\354\212\244\355\203\235/3\354\260\250\354\213\234 - BOJ 2504.cpp" "b/YIM2UL2ET/\354\212\244\355\203\235/3\354\260\250\354\213\234 - BOJ 2504.cpp" new file mode 100644 index 0000000..af345fa --- /dev/null +++ "b/YIM2UL2ET/\354\212\244\355\203\235/3\354\260\250\354\213\234 - BOJ 2504.cpp" @@ -0,0 +1,41 @@ +#include +#include +#include + +int main(void) +{ + bool is_Cstr = true; + std::string str; + std::stack stk; + std::vector vec; + + std::cin >> str; + + for (int i = 0; i < str.size(); i++) { + if (str[i] == '(' || str[i] == '[') { + stk.push(str[i]); + if (stk.size() > vec.size()) vec.push_back(0); + } + else if (!stk.empty() && ((str[i] == ')' && stk.top() == '(') || (str[i] == ']' && stk.top() == '['))){ + int value; + if (stk.top() == '(') value = 2; + else value = 3; + + if (stk.size() < vec.size()) { + vec[vec.size()-2] += vec.back() * value; + vec.pop_back(); + } + else vec[vec.size()-1] += value; + + stk.pop(); + } + else { + is_Cstr = false; + break; + } + } + + if (!is_Cstr || !stk.empty()) std::cout << 0; + else std::cout << vec[0]; + return 0; +} \ No newline at end of file