├── .github ├── labels.yml └── workflows │ ├── check_pr_solution.yml │ └── push_solution.yml ├── .gitignore ├── README.md ├── make_branch.sh ├── requirements.txt ├── scripts ├── check_pull_request_code.py ├── push_solution.py └── utils.py ├── solutions.json └── solutions ├── baekjoon ├── 1000 │ ├── Main.java │ ├── main.cpp │ ├── main.js │ └── main.py ├── 1001 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 1005 │ └── main.cpp ├── 1010 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 1012 │ ├── Main.java │ └── main.py ├── 1021 │ └── main.py ├── 1032 │ └── main.py ├── 1034 │ └── Main.java ├── 1038 │ └── main.py ├── 1043 │ └── main.cpp ├── 1052 │ └── Main.java ├── 1058 │ └── main.py ├── 1068 │ └── main.cpp ├── 1074 │ └── main.cpp ├── 1092 │ └── Main.java ├── 1106 │ └── Main.java ├── 1107 │ └── Main.java ├── 1110 │ ├── main.cpp │ └── main.py ├── 1135 │ └── main.py ├── 1145 │ └── main.py ├── 1152 │ └── main.py ├── 1158 │ ├── main.cpp │ └── main.py ├── 1181 │ ├── Main.java │ └── main.py ├── 1182 │ ├── Main.java │ └── main.py ├── 1189 │ └── main.cpp ├── 1197 │ └── main.cpp ├── 1212 │ ├── main.cpp │ └── main.py ├── 1229 │ └── Main.java ├── 1238 │ └── main.py ├── 1244 │ └── main.cpp ├── 1260 │ └── main.cpp ├── 1263 │ └── Main.java ├── 1269 │ └── main.py ├── 1302 │ ├── main.cpp │ └── main.py ├── 1312 │ └── main.cpp ├── 1316 │ ├── Main.java │ └── main.py ├── 1325 │ └── main.cpp ├── 1368 │ ├── main.cpp │ └── main.py ├── 1405 │ └── main.py ├── 1436 │ └── main.py ├── 1463 │ └── main.cpp ├── 1477 │ └── main.py ├── 1497 │ └── main.cpp ├── 1507 │ └── Main.java ├── 1516 │ └── main.cpp ├── 1520 │ ├── main.cpp │ └── main.py ├── 1541 │ └── Main.java ├── 1620 │ └── main.cpp ├── 1647 │ ├── main.cpp │ └── main.py ├── 1654 │ └── main.py ├── 1689 │ └── Main.java ├── 1697 │ └── main.py ├── 1707 │ └── main.py ├── 1717 │ ├── main.cpp │ └── main.py ├── 1719 │ └── main.py ├── 1726 │ └── main.py ├── 1747 │ └── main.cpp ├── 1749 │ └── main.cpp ├── 1758 │ └── main.py ├── 1764 │ └── Main.java ├── 1774 │ └── main.cpp ├── 1786 │ └── main.js ├── 1789 │ ├── Main.java │ └── main.cpp ├── 1802 │ └── main.py ├── 1806 │ └── main.py ├── 1817 │ └── main.py ├── 1822 │ └── Main.java ├── 1874 │ └── main.cpp ├── 1890 │ └── main.py ├── 1912 │ └── Main.java ├── 1913 │ └── main.cpp ├── 1918 │ ├── main.cpp │ └── main.py ├── 1920 │ └── main.cpp ├── 1922 │ ├── main.cpp │ └── main.py ├── 1927 │ └── main.py ├── 1931 │ └── main.py ├── 1934 │ └── main.cpp ├── 1935 │ └── main.py ├── 1940 │ └── main.py ├── 1949 │ └── main.cpp ├── 1966 │ └── main.py ├── 1967 │ └── Main.java ├── 1969 │ └── main.py ├── 1976 │ ├── main.cpp │ └── main.py ├── 1978 │ ├── main.cpp │ └── main.py ├── 1990 │ └── Main.java ├── 1991 │ └── main.cpp ├── 1992 │ └── main.cpp ├── 2015 │ ├── main.cpp │ └── main.py ├── 2018 │ └── main.py ├── 2026 │ └── main.py ├── 2075 │ └── main.cpp ├── 2110 │ └── Main.java ├── 2141 │ ├── Main.java │ └── main.py ├── 2143 │ └── main.cpp ├── 2156 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 2164 │ ├── main.cpp │ └── main.py ├── 2167 │ └── main.cpp ├── 2178 │ └── main.cpp ├── 2204 │ └── main.py ├── 2206 │ └── main.py ├── 2210 │ └── main.cpp ├── 2212 │ ├── main.cpp │ └── main.py ├── 2213 │ └── main.cpp ├── 2217 │ └── Main.java ├── 2230 │ └── Main.java ├── 2231 │ └── main.cpp ├── 2293 │ └── Main.java ├── 2294 │ └── main.py ├── 2309 │ └── main.py ├── 2346 │ └── main.py ├── 2407 │ └── Main.java ├── 2417 │ ├── Main.java │ └── main.cpp ├── 2422 │ └── main.cpp ├── 2438 │ └── main.cpp ├── 2447 │ └── main.cpp ├── 2448 │ └── main.cpp ├── 2470 │ ├── Main.java │ └── main.py ├── 2473 │ └── main.py ├── 2479 │ └── Main.java ├── 2493 │ ├── Main.java │ └── main.cpp ├── 2503 │ └── main.py ├── 2504 │ ├── main.cpp │ └── main.py ├── 2508 │ └── Main.java ├── 2512 │ └── main.py ├── 2533 │ └── main.cpp ├── 2559 │ └── main.py ├── 2573 │ └── Main.java ├── 2578 │ └── main.cpp ├── 2579 │ └── main.py ├── 2580 │ └── main.cpp ├── 2581 │ └── main.cpp ├── 2589 │ └── main.py ├── 2602 │ └── main.cpp ├── 2606 │ └── main.cpp ├── 2609 │ ├── main.cpp │ └── main.py ├── 2615 │ └── Main.java ├── 2630 │ └── main.cpp ├── 2636 │ └── main.cpp ├── 2637 │ └── Main.java ├── 2638 │ └── main.py ├── 2667 │ └── main.cpp ├── 2696 │ └── main.cpp ├── 2729 │ └── main.py ├── 2744 │ └── main.py ├── 2745 │ ├── Main.java │ └── main.cpp ├── 2748 │ └── main.cpp ├── 2753 │ ├── main.cpp │ └── main.py ├── 2776 │ └── main.py ├── 2798 │ ├── main.cpp │ └── main.py ├── 2800 │ ├── Main.java │ └── main.py ├── 2805 │ ├── Main.java │ └── main.py ├── 2812 │ └── main.py ├── 2839 │ └── main.cpp ├── 2887 │ └── main.py ├── 2960 │ └── main.cpp ├── 3025 │ └── main.cpp ├── 3029 │ ├── Main.java │ └── main.py ├── 3079 │ └── main.py ├── 3190 │ └── main.py ├── 3584 │ ├── Main.java │ └── main.cpp ├── 3687 │ └── main.cpp ├── 3986 │ └── main.py ├── 4096 │ └── main.py ├── 4134 │ └── main.cpp ├── 4179 │ └── main.py ├── 4195 │ └── main.cpp ├── 4256 │ └── main.cpp ├── 4354 │ └── main.js ├── 4358 │ └── main.cpp ├── 4386 │ └── main.py ├── 4396 │ └── main.cpp ├── 4659 │ └── Main.java ├── 4690 │ └── main.py ├── 4779 │ └── main.cpp ├── 4949 │ └── main.cpp ├── 4963 │ └── main.py ├── 5347 │ └── main.cpp ├── 5373 │ └── main.cpp ├── 5397 │ └── main.py ├── 5430 │ ├── Main.java │ └── main.py ├── 5547 │ └── main.cpp ├── 5557 │ └── main.py ├── 5568 │ └── main.py ├── 5597 │ ├── main.cpp │ └── main.py ├── 5618 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 5676 │ └── Main.java ├── 6236 │ └── main.py ├── 6497 │ └── main.py ├── 6550 │ └── Main.java ├── 7453 │ └── Main.java ├── 7568 │ └── main.py ├── 7569 │ ├── main.cpp │ └── main.py ├── 7576 │ └── main.cpp ├── 7579 │ └── main.cpp ├── 7662 │ ├── main.cpp │ └── main.py ├── 9012 │ ├── main.cpp │ └── main.py ├── 9024 │ └── Main.java ├── 9046 │ ├── Main.java │ └── main.py ├── 9079 │ └── main.cpp ├── 9094 │ └── main.py ├── 9095 │ ├── Main.java │ └── main.py ├── 9251 │ └── main.py ├── 9328 │ └── main.cpp ├── 9342 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 9461 │ └── main.py ├── 9465 │ └── main.py ├── 9506 │ └── main.cpp ├── 9613 │ └── main.cpp ├── 9655 │ ├── Main.java │ └── main.py ├── 9663 │ └── main.cpp ├── 10164 │ └── main.cpp ├── 10282 │ └── main.py ├── 10546 │ └── main.py ├── 10775 │ ├── main.cpp │ └── main.py ├── 10798 │ ├── Main.java │ └── main.py ├── 10799 │ └── main.cpp ├── 10815 │ ├── Main.java │ └── main.cpp ├── 10816 │ └── main.py ├── 10828 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 10845 │ └── main.py ├── 10866 │ ├── main.cpp │ └── main.py ├── 10870 │ └── main.cpp ├── 10974 │ └── main.py ├── 10986 │ └── main.cpp ├── 10994 │ └── main.cpp ├── 11000 │ └── main.py ├── 11048 │ └── main.cpp ├── 11053 │ ├── Main.java │ └── main.cpp ├── 11055 │ ├── Main.java │ └── main.cpp ├── 11256 │ └── main.py ├── 11279 │ ├── main.cpp │ └── main.py ├── 11286 │ ├── main.cpp │ └── main.py ├── 11365 │ ├── Main.java │ └── main.py ├── 11399 │ └── main.py ├── 11437 │ ├── main.cpp │ └── main.js ├── 11438 │ └── main.js ├── 11441 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 11508 │ └── main.py ├── 11653 │ ├── main.cpp │ └── main.py ├── 11659 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 11660 │ └── main.cpp ├── 11663 │ └── main.cpp ├── 11720 │ ├── Main.java │ └── main.py ├── 11722 │ └── main.py ├── 11724 │ └── main.py ├── 11725 │ └── main.cpp ├── 11726 │ ├── Main.java │ └── main.py ├── 11727 │ └── main.py ├── 11728 │ ├── Main.java │ └── main.py ├── 11909 │ ├── main.cpp │ └── main.py ├── 11985 │ └── main.py ├── 12015 │ └── main.cpp ├── 12026 │ └── Main.java ├── 12871 │ └── main.py ├── 12892 │ └── Main.java ├── 12931 │ └── Main.java ├── 12933 │ └── main.cpp ├── 13023 │ └── Main.java ├── 13140 │ └── main.cpp ├── 13164 │ └── main.py ├── 13265 │ └── Main.java ├── 13305 │ └── main.cpp ├── 13410 │ └── main.py ├── 13422 │ └── Main.java ├── 13549 │ └── main.cpp ├── 13699 │ └── main.py ├── 14247 │ └── main.py ├── 14284 │ ├── Main.java │ └── main.cpp ├── 14395 │ └── Main.java ├── 14425 │ ├── main.cpp │ ├── main.go │ └── main.py ├── 14467 │ └── main.cpp ├── 14499 │ └── main.py ├── 14500 │ └── main.py ├── 14502 │ ├── main.cpp │ └── main.py ├── 14503 │ └── Main.java ├── 14563 │ └── main.cpp ├── 14567 │ └── main.py ├── 14620 │ └── main.py ├── 14621 │ └── main.cpp ├── 14697 │ └── main.cpp ├── 14712 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 14716 │ └── main.py ├── 14719 │ └── main.py ├── 14722 │ └── main.cpp ├── 14889 │ └── main.cpp ├── 14891 │ └── main.py ├── 14916 │ ├── main.cpp │ └── main.py ├── 14929 │ ├── Main.java │ └── main.cpp ├── 14940 │ └── Main.java ├── 15486 │ └── Main.java ├── 15649 │ ├── main.cpp │ └── main.py ├── 15650 │ ├── main.cpp │ └── main.py ├── 15651 │ ├── main.cpp │ └── main.py ├── 15652 │ ├── main.cpp │ └── main.py ├── 15654 │ ├── main.cpp │ └── main.py ├── 15655 │ ├── main.cpp │ └── main.py ├── 15656 │ ├── main.cpp │ └── main.py ├── 15657 │ ├── main.cpp │ └── main.py ├── 15658 │ └── main.py ├── 15661 │ └── main.py ├── 15663 │ ├── main.cpp │ └── main.py ├── 15664 │ ├── main.cpp │ └── main.py ├── 15665 │ ├── main.cpp │ └── main.py ├── 15666 │ ├── main.cpp │ └── main.py ├── 15681 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 15721 │ └── main.cpp ├── 15787 │ └── main.py ├── 15806 │ └── main.py ├── 15886 │ └── main.py ├── 15961 │ └── main.py ├── 15989 │ └── main.cpp ├── 15990 │ └── main.cpp ├── 16171 │ ├── Main.java │ └── main.cpp ├── 16174 │ └── main.py ├── 16198 │ └── main.py ├── 16208 │ └── main.py ├── 16234 │ ├── main.cpp │ └── main.py ├── 16236 │ └── main.cpp ├── 16398 │ └── main.cpp ├── 16435 │ └── main.py ├── 16439 │ └── main.cpp ├── 16493 │ ├── Main.java │ ├── Main2.java │ ├── Main3.java │ └── Main4.java ├── 16562 │ └── main.cpp ├── 16918 │ └── main.cpp ├── 16926 │ └── main.cpp ├── 16935 │ └── main.py ├── 16953 │ └── main.py ├── 16954 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 16971 │ └── main.cpp ├── 17142 │ └── main.py ├── 17144 │ └── main.cpp ├── 17352 │ └── main.cpp ├── 17396 │ └── Main.java ├── 17413 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 17471 │ └── main.py ├── 17485 │ └── main.py ├── 17609 │ └── main.py ├── 17614 │ └── main.cpp ├── 17626 │ └── main.py ├── 17829 │ └── main.cpp ├── 17831 │ └── main.py ├── 17836 │ ├── Main.java │ └── main.cpp ├── 18115 │ └── main.cpp ├── 18116 │ └── main.cpp ├── 18222 │ └── main.cpp ├── 18232 │ └── Main.java ├── 18234 │ └── Main.java ├── 18258 │ ├── main.cpp │ └── main.py ├── 18312 │ └── main.cpp ├── 18427 │ └── main.py ├── 18430 │ └── main.cpp ├── 18436 │ └── Main.java ├── 18511 │ └── main.py ├── 18513 │ └── main.cpp ├── 18808 │ └── main.py ├── 19532 │ └── main.cpp ├── 19598 │ └── main.py ├── 19622 │ └── main.py ├── 19637 │ └── main.cpp ├── 19940 │ └── Main.java ├── 20007 │ └── Main.java ├── 20010 │ └── main.cpp ├── 20053 │ └── main.cpp ├── 20057 │ └── main.cpp ├── 20058 │ ├── main.cpp │ └── main.py ├── 20061 │ └── main.cpp ├── 20115 │ └── main.py ├── 20154 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 20157 │ └── main.js ├── 20165 │ └── main.cpp ├── 20207 │ └── main.cpp ├── 20291 │ ├── Main.java │ └── main.cpp ├── 20300 │ └── main.cpp ├── 20365 │ └── main.cpp ├── 20436 │ └── main.cpp ├── 20437 │ └── Main.java ├── 20438 │ └── main.cpp ├── 20440 │ └── main.cpp ├── 20444 │ └── Main.java ├── 20543 │ └── main.cpp ├── 20546 │ └── main.cpp ├── 20922 │ ├── Main.java │ └── main.cpp ├── 20924 │ └── main.py ├── 21180 │ └── Main.java ├── 21275 │ └── main.cpp ├── 21278 │ └── main.py ├── 21312 │ ├── main.cpp │ └── main.py ├── 21315 │ └── main.py ├── 21317 │ └── main.cpp ├── 21318 │ └── main.cpp ├── 21608 │ └── main.py ├── 21610 │ └── main.py ├── 21756 │ └── main.cpp ├── 21757 │ └── main.cpp ├── 21758 │ └── main.cpp ├── 21918 │ └── main.py ├── 21919 │ └── main.py ├── 21920 │ └── main.py ├── 21923 │ └── main.py ├── 21924 │ └── main.py ├── 21939 │ ├── Main.java │ ├── main.cpp │ └── main.py ├── 21942 │ └── main.py ├── 21944 │ └── main.py ├── 22856 │ ├── Main.java │ ├── main.cpp │ └── main.js ├── 22864 │ └── Main.java ├── 22869 │ └── main.py ├── 22942 │ └── main.cpp ├── 22944 │ └── main.py ├── 23059 │ └── Main.java ├── 24499 │ └── main.cpp ├── 25214 │ └── main.cpp ├── 25395 │ └── Main.java ├── 25427 │ ├── Main.java │ └── main.cpp ├── 26597 │ └── Main.java ├── 28070 │ ├── main.cpp │ └── main2.cpp ├── 28286 │ └── main.cpp ├── 30457 │ └── main.cpp └── 30979 │ └── main.cpp ├── hackerrank └── 8137 │ └── main.sql ├── leetcode ├── 9 │ ├── main.cpp │ └── main.py ├── 42 │ └── main.cpp ├── 977 │ └── main.cpp ├── 1609 │ └── main.cpp ├── 2709 │ ├── main.cpp │ └── main.py └── 2864 │ └── main.cpp └── programmers └── 181952 └── main.cpp /make_branch.sh: -------------------------------------------------------------------------------- 1 | git checkout main 2 | git pull 3 | git checkout -b $1-$2-$3 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.31.0 2 | python-dotenv==1.0.0 -------------------------------------------------------------------------------- /solutions/baekjoon/1000/Main.java: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/3b60c2a75fbc4c1cb0b1571046ceae36 4 | import java.util.*; 5 | import java.io.*; 6 | import java.lang.*; 7 | 8 | public class Main{ 9 | public static void main(String[] args){ 10 | Scanner sc = new Scanner(System.in); 11 | 12 | int a = sc.nextInt(); 13 | int b = sc.nextInt(); 14 | 15 | System.out.println(a+b); 16 | } 17 | } 18 | 19 | /* Solution Description 20 | 두 정수 A와 B를 입력받고 두 정수의 합의 결과를 출력하면 되는 문제 21 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/1000/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/cf8b6e4f63ac4660872340f614070175 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | int a, b; cin >> a >> b; 10 | cout << a + b; 11 | return 0; 12 | } 13 | 14 | /* Solution Description 15 | 두 정수 A와 B를 입력받고 두 정수의 합의 결과를 출력하면 되는 문제 16 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/1000/main.py: -------------------------------------------------------------------------------- 1 | # Authored by: tony9402 2 | # Co-authored by: - 3 | # Link: http://boj.kr/e94b3c2e8dce4332b75806ff58c2981d 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | a, b = map(int, input().split()) 10 | print(a + b) 11 | 12 | """ Solution Description 13 | 두 정수 A와 B를 입력받고 두 정수의 합의 결과를 출력하면 되는 문제 14 | """ -------------------------------------------------------------------------------- /solutions/baekjoon/1001/Main.java: -------------------------------------------------------------------------------- 1 | // Authored by: lms0806 2 | // Co-authored by: - 3 | // Link: http://boj.kr/fbea125ef3714da4b712fdbd4415d43f 4 | import java.io.BufferedReader; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.util.StringTokenizer; 8 | 9 | public class Main { 10 | public static void main(String[] args) throws IOException{ 11 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 12 | StringTokenizer st = new StringTokenizer(br.readLine()); 13 | 14 | int a = Integer.parseInt(st.nextToken()); 15 | int b = Integer.parseInt(st.nextToken()); 16 | 17 | System.out.print(a - b); 18 | } 19 | } 20 | 21 | /* Solution Description 22 | 두 정수 A와 B를 입력받고 두 정수의 차의 결과를 출력하면 되는 문제 23 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/1001/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/0f9b0c569a144394a24ff3e7df3a2fae 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int a, b; cin >> a >> b; 13 | cout << a - b; 14 | return 0; 15 | } 16 | 17 | /* Solution Description 18 | 두 정수 A와 B를 입력받고 두 정수의 차의 결과를 출력하면 되는 문제 19 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/1001/main.py: -------------------------------------------------------------------------------- 1 | # Authored by: tony9402 2 | # Co-authored by: - 3 | # Link: http://boj.kr/7a8867fd7d4141f09eb1ced81591d4b0 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | a, b = map(int, input().split()) 10 | print(a - b) 11 | 12 | """ Solution Description 13 | 두 정수 A와 B를 입력받고 두 정수의 차의 결과를 출력하면 되는 문제 14 | """ -------------------------------------------------------------------------------- /solutions/baekjoon/1010/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/4a2e9c2a7d9a44e7b0c4eda2c2cae10b 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | ll DP[33][33]; 10 | 11 | int main(){ 12 | ios::sync_with_stdio(false); 13 | cin.tie(0); 14 | 15 | int T; cin >> T; 16 | DP[0][0] = 1; 17 | for(int i=1;i<=30;i++) { 18 | DP[i][0] = 1; 19 | for(int j=1;j<=30;j++) { 20 | DP[i][j] = DP[i - 1][j] + DP[i - 1][j - 1]; 21 | } 22 | } 23 | while(T--) { 24 | int N, M; cin >> N >> M; 25 | cout << DP[M][N] << '\n'; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/1010/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gkgg123 2 | # Co-authored by : - 3 | # Link : https://www.acmicpc.net/source/share/6c285d8c7b9c44af971645f45c06d848 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | T = int(input()) 9 | 10 | dp = [[0 for _ in range(31)] for _ in range(31)] 11 | dp[0][0] = 1 12 | 13 | for num in range(1,31): 14 | dp[num][0] = 1 15 | for pick in range(1,31): 16 | dp[num][pick] = dp[num-1][pick] + dp[num-1][pick-1] 17 | 18 | for _ in range(T): 19 | N, M = map(int,input().split()) 20 | print(dp[M][N]) 21 | -------------------------------------------------------------------------------- /solutions/baekjoon/10164/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/17e87614b6d540ca996295b147a740d5 4 | #include 5 | 6 | using namespace std; 7 | 8 | int N, M, K; 9 | int DP[22][22]; 10 | 11 | int main(){ 12 | ios::sync_with_stdio(false); 13 | cin.tie(0); 14 | 15 | cin >> N >> M >> K; 16 | int y = N, x = M; 17 | if(K > 0) { 18 | --K; 19 | y = K / M + 1, x = K % M + 1; // 1 - based 20 | } 21 | DP[1][1] = 1; 22 | for(int i=1;i<=y; i++) { 23 | for(int j=1;j<=x;j++) { 24 | if(i == 1 && j == 1) continue; 25 | DP[i][j] = DP[i][j - 1] + DP[i - 1][j]; 26 | } 27 | } 28 | for(int i=y;i<=N;i++){ 29 | for(int j=x;j<=M;j++){ 30 | if(i == y && j == x) continue; 31 | DP[i][j] = DP[i][j - 1] + DP[i - 1][j]; 32 | } 33 | } 34 | cout << DP[N][M]; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /solutions/baekjoon/1021/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/71a5091026cf4a1b836dc46c812aeaca 4 | import sys 5 | from collections import deque 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = list(map(int, input().split())) 11 | queue = deque([i for i in range(1,N+1)]) 12 | ans = 0 13 | for i in arr: 14 | idx = queue.index(i) 15 | if idx == 0: 16 | queue.popleft() 17 | else: 18 | if idx <= len(queue)//2: 19 | queue.rotate(-idx) 20 | queue.popleft() 21 | ans += idx 22 | else: 23 | queue.rotate(len(queue) - idx) 24 | ans += len(queue) - idx 25 | queue.popleft() 26 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/1032/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/c400c0aa10ea40bc809ad78029ac721d 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | N = int(input()) 9 | arr = [] 10 | ans = '' 11 | for i in range(N): 12 | arr.append(input()) 13 | for i in range(len(arr[0])): 14 | ct = 0 15 | word = arr[0][i] 16 | for j in range(N): 17 | if word == arr[j][i]: 18 | ct += 1 19 | if ct == N: 20 | ans += word 21 | else: 22 | ans += '?' 23 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/1038/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gkgg123 2 | # Co-authored by : - 3 | # Link : http://boj.kr/ab9a5bb2d14943b3aefaf98f4648a469 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def bfs(N): 11 | queue = deque() 12 | for i in range(1, 10): 13 | queue.append((i, str(i))) 14 | while queue: 15 | if len(result) == N + 1: 16 | break 17 | cur_num,totol_num = queue.popleft() 18 | if cur_num != 0: 19 | for k in range(cur_num): 20 | next_num = totol_num + str(k) 21 | queue.append((k,next_num)) 22 | result.append(next_num) 23 | 24 | N = int(input()) 25 | result = [] 26 | for i in range(10): 27 | result.append(i) 28 | 29 | if N >=10: 30 | bfs(N) 31 | 32 | if len(result) > N: 33 | print(result[N]) 34 | else: 35 | print(-1) 36 | -------------------------------------------------------------------------------- /solutions/baekjoon/10546/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/bb59bafb8ef04d69a5ab5ade6d7cfeb9 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | dic = {} 11 | for i in range(N): 12 | name = input() 13 | dic[name] = dic.get(name, 0) + 1 14 | 15 | for i in range(N-1): 16 | name = input() 17 | dic[name] -= 1 18 | 19 | dic_list = list(dic.items()) 20 | dic_list.sort(key = lambda x : (-x[1], x[0])) 21 | print(dic_list[0][0]) 22 | -------------------------------------------------------------------------------- /solutions/baekjoon/1058/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gkgg123 2 | # Co-authored by : - 3 | # Link : https://www.acmicpc.net/source/share/a369084903d348d2966ab752ccb745ec 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | def dfs(idx): 9 | global N 10 | visited = [ True for _ in range(N) ] 11 | visited[idx] = False 12 | stack = [ (idx, 0) ] 13 | total = 0 14 | while stack: 15 | curent_x, p_cnt = stack.pop() 16 | for either_x in range(N): 17 | if arr[curent_x][either_x] == 'Y': 18 | if visited[either_x] and p_cnt <= 1: 19 | visited[either_x] = False 20 | stack.append((either_x, p_cnt+1)) 21 | total += 1 22 | return total 23 | 24 | N = int(input()) 25 | arr = [list(input()) for _ in range(N)] 26 | max_number = 0 27 | 28 | for i in range(N): 29 | cu_cnt = dfs(i) 30 | max_number = max(max_number,cu_cnt) 31 | 32 | print(max_number) 33 | -------------------------------------------------------------------------------- /solutions/baekjoon/1074/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/fba04fa859d540fab6cad5266780f137 4 | #include 5 | 6 | using namespace std; 7 | 8 | int solve(int y, int x, int s) { 9 | if(s == 2) return 2 * y + x; 10 | s >>= 1; 11 | int ny = y / s, nx = x / s; 12 | int nxt = ny * 2 + nx; 13 | return s * s * nxt + solve(y - ny * s, x - nx * s, s); 14 | } 15 | 16 | int main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int N, R, C; cin >> N >> R >> C; 21 | cout << solve(R, C, 1 << N); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/10775/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/f71cbcd7b21940189fe6db7f99852f09 4 | #include 5 | 6 | using namespace std; 7 | 8 | constexpr int MAXN = 100005; 9 | int uf[MAXN]; 10 | 11 | int find(int x) { 12 | if(uf[x] < 0) return x; 13 | return uf[x] = find(uf[x]); 14 | } 15 | 16 | bool merge(int a, int b){ 17 | a = find(a); 18 | b = find(b); 19 | if(a == b)return false; 20 | uf[b] = a; 21 | return true; 22 | } 23 | 24 | int main(){ 25 | ios::sync_with_stdio(false); 26 | cin.tie(0); 27 | 28 | int N, M; cin >> N >> M; 29 | for(int i=0;i<=N;i++) uf[i] = -1; 30 | int answer = 0; 31 | for(int i=0;i> x; 33 | int cur = find(x); 34 | if(cur == 0) break; 35 | merge(cur - 1, cur); 36 | answer ++; 37 | } 38 | cout << answer; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /solutions/baekjoon/10775/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/30c745d5f3c547c28e95b5c9a76647c1 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | G = int(input()) 10 | P = int(input()) 11 | gates = list(range(G + 1)) 12 | 13 | def find_max(x): 14 | if gates[x] != x: 15 | gates[x] = find_max(gates[x]) 16 | return gates[x] 17 | 18 | answer = 0 19 | for _ in range(P): 20 | plane = int(input()) 21 | gate_n = find_max(plane) 22 | if gate_n == 0: 23 | print(answer) 24 | sys.exit(0) 25 | answer += 1 26 | gates[gate_n] = gates[gate_n - 1] 27 | print(answer) 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/10798/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/a1c26275e6af44f5a080d54a61b4c677 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | arr = [] 10 | ans = '' 11 | max_len = 0 12 | for i in range(5): 13 | a = input() 14 | max_len = max(max_len, len(a)) 15 | arr.append(a) 16 | 17 | for i in range(max_len): 18 | for j in range(5): 19 | if len(arr[j]) <= i: 20 | continue 21 | ans += arr[j][i] 22 | 23 | print(ans) 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/10815/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/9e4cc6a176c6444d99cbc0379c5fd53a 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | vector V(N); 14 | for(auto &i: V) cin >> i; 15 | sort(V.begin(), V.end()); 16 | int Q; cin >> Q; 17 | for(int i=0;i> x; 19 | if(binary_search(V.begin(), V.end(), x)) cout << 1 << ' '; 20 | else cout << 0 << ' '; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/10816/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/3bcac4799e584285b9df8be8d69ab79a 4 | import sys 5 | from bisect import bisect_left, bisect_right 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | arr = list(map(int, input().split())) 11 | M = int(input()) 12 | arr2 = list(map(int, input().split())) 13 | arr.sort() 14 | for i in arr2: 15 | idx_left = bisect_left(arr,i) 16 | idx_right = bisect_right(arr,i) 17 | print(idx_right - idx_left, end=' ') -------------------------------------------------------------------------------- /solutions/baekjoon/10828/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/ab416f0794fc41cabc3d9ed46db29f60 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | 11 | stack = [] 12 | 13 | for i in range(N): 14 | cmd = input().split() 15 | X = 0 16 | if len(cmd) == 2: 17 | X = cmd[1] 18 | cmd = cmd[0] 19 | 20 | if cmd == "push": 21 | stack.append(X) 22 | elif cmd == "pop": 23 | if len(stack) == 0: 24 | print(-1) 25 | else: 26 | print(stack[-1]) 27 | stack.pop(-1) 28 | elif cmd == "size": 29 | print(len(stack)) 30 | elif cmd == "empty": 31 | print(0 if len(stack) else 1) 32 | elif cmd == "top": 33 | if len(stack) == 0: 34 | print(-1) 35 | else: 36 | print(stack[-1]) 37 | -------------------------------------------------------------------------------- /solutions/baekjoon/10845/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/89f5e4e54afb441bbf218b5e68a4160d 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | queue = deque() 12 | for i in range(N): 13 | command = input().split() 14 | if command[0] == "push": 15 | queue.append(command[1]) 16 | elif command[0] == "pop": 17 | if queue: 18 | print(queue.popleft()) 19 | else: 20 | print(-1) 21 | elif command[0] == "size": 22 | print(len(queue)) 23 | elif command[0] == "empty": 24 | if not queue: 25 | print(1) 26 | else: 27 | print(0) 28 | elif command[0] == "front": 29 | if queue: 30 | print(queue[0]) 31 | else: 32 | print(-1) 33 | elif command[0] == "back": 34 | if queue: 35 | print(queue[-1]) 36 | else: 37 | print(-1) -------------------------------------------------------------------------------- /solutions/baekjoon/10870/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/4c48767c6ca14f2fbef014b726303f33 4 | #include 5 | 6 | using namespace std; 7 | 8 | int DP[25]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | DP[0] = 0; 15 | DP[1] = 1; 16 | for(int i=2;i<=20;i++){ 17 | DP[i] = DP[i - 1] + DP[i - 2]; 18 | } 19 | 20 | int N; cin >> N; 21 | cout << DP[N]; 22 | } 23 | -------------------------------------------------------------------------------- /solutions/baekjoon/10974/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/f386e090dfe84518a7329d6f0a77f8c6 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def DFS(): 10 | if len(arr) == N: 11 | print(*arr) 12 | return 13 | for i in range(1, N+1): 14 | if visited[i] == 0: 15 | visited[i] = 1 16 | arr.append(i) 17 | DFS() 18 | arr.pop() 19 | visited[i] = 0 20 | 21 | N = int(input()) 22 | arr = [] 23 | visited = [0] * (N+1) 24 | DFS() -------------------------------------------------------------------------------- /solutions/baekjoon/10986/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/20743d7ff7ab44a3b917f45b8e064f16 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | ll mod[1000]; // 0 ~ 999 10 | 11 | int main(){ 12 | ios::sync_with_stdio(false); 13 | cin.tie(0); 14 | 15 | int N, M; cin >> N >> M; 16 | ll sum =0; 17 | mod[0] = 1; 18 | for(int i=1;i<=N;i++) { 19 | int x; cin >> x; 20 | x %= M; 21 | sum = (sum + x) % M; 22 | mod[sum] ++; 23 | } 24 | ll answer = 0; 25 | for(int i=0;i 5 | 6 | using namespace std; 7 | 8 | char stars[444][444]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int n; cin >> n; 15 | int N = 4 * (n - 1) + 1; 16 | for(int k=0;k<=N/2;k+=2){ 17 | int L = N - k * 2; 18 | for(int i=0;i= end_points[0]: 21 | heapq.heappop(end_points) 22 | heapq.heappush(end_points, l[1]) 23 | 24 | print(len(end_points)) 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/11048/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/4ff69fc575384408beee739a7904de45 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N, M; cin >> N >> M; 13 | vector> DP(N + 1, vector(M + 1)); 14 | for(int i=1;i<=N;i++) { 15 | for(int j=1;j<=M;j++) { 16 | int x; cin >> x; 17 | DP[i][j] = max({DP[i-1][j], DP[i][j-1], DP[i-1][j-1]}) + x; 18 | } 19 | } 20 | cout << DP[N][M]; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/11053/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/67f06494af394db6958644f6cb20e8fe 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | vector V(N), DP(N); 14 | for(auto &i: V) cin >> i; 15 | for(int i=0;i V[j]) { 19 | DP[i] = max(DP[i], DP[j] + 1); 20 | } 21 | } 22 | } 23 | cout << *max_element(DP.begin(), DP.end()); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/11055/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/038f38ed8c6f41149b051350cb3cabd1 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | vector V(N), DP(N); 14 | for(auto &i: V) cin >> i; 15 | for(int i=0;i V[j]) { 19 | DP[i] = max(DP[i], DP[j] + V[i]); 20 | } 21 | } 22 | } 23 | cout << *max_element(DP.begin(), DP.end()); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/1110/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/29790baf467142729acef15a2815b478 4 | #include 5 | 6 | using namespace std; 7 | 8 | int getNext(int x) { 9 | int tmp = x, ret = 0; 10 | while(x) { 11 | ret += x % 10; 12 | x /= 10; 13 | } 14 | return tmp % 10 * 10 + ret % 10; 15 | } 16 | 17 | int main(){ 18 | ios::sync_with_stdio(false); 19 | cin.tie(0); 20 | 21 | int N; cin >> N; 22 | int start = N; 23 | int cur = start; 24 | int ans = 0; 25 | 26 | while(true) { 27 | cur = getNext(cur); 28 | ans ++; 29 | if(start == cur) break; 30 | } 31 | cout << ans; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /solutions/baekjoon/1110/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gyeong_sun 2 | # Co-authored by : - 3 | # Link : http://boj.kr/8710e4702aa04dfa94ba38bd8cb271dd 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | origin_num = int(input()) 10 | num = origin_num 11 | cycle = 0 #반복 사이클 수 12 | 13 | while True: 14 | n1 = num//10 #십의 자리 15 | n2 = num%10 #일의 자리 16 | n3 = (n1+n2)%10 17 | num = n2*10+n3 18 | cycle += 1 19 | if origin_num == num: #원래 수로 돌아온 경우 20 | break #반복문 빠져나감 21 | 22 | print(cycle) 23 | -------------------------------------------------------------------------------- /solutions/baekjoon/11256/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gd30220 2 | # Co-authored by : - 3 | # Link : http://boj.kr/fb3874925c8049e58f475817595d442a 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | testcase = int(input()) 10 | for _ in range(testcase): 11 | j, n = map(int, input().split()) 12 | 13 | boxes = [] 14 | for _ in range(n): 15 | r, c = map(int, input().split()) 16 | boxes.append(r * c) 17 | 18 | boxes.sort(reverse=True) 19 | result = 0 20 | 21 | for box in boxes: 22 | j -= box 23 | result += 1 24 | if j <= 0: 25 | break 26 | 27 | print(result) 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/11279/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/53d07a6885b1412d93b53a1fe211e153 4 | #include 5 | 6 | using namespace std; 7 | 8 | priority_queue pq; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N; cin >> N; 15 | pq.push(0); 16 | for(int i=0;i> x; 18 | if(x == 0) { 19 | if(pq.empty()) cout << 0 << '\n'; 20 | else { 21 | cout << pq.top() << '\n'; 22 | pq.pop(); 23 | } 24 | } 25 | else pq.push(x); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/11279/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/2b2600bda1c447b7b7f2c2399b167716 4 | import sys 5 | import heapq 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | heap = [] 12 | for i in range(N): 13 | a = int(input()) 14 | if a == 0: 15 | if heap: 16 | print(-heapq.heappop(heap)) 17 | else: 18 | print(0) 19 | heapq.heappush(heap, -a) -------------------------------------------------------------------------------- /solutions/baekjoon/11286/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/3866a743ca954b6fa27922ed08da2b5e 4 | #include 5 | 6 | using namespace std; 7 | 8 | priority_queue, vector>, greater>> pq; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N; cin >> N; 15 | for(int i=0;i> x; 17 | if(x == 0) { 18 | if(pq.empty()) cout << 0 << '\n'; 19 | else { 20 | cout << pq.top().second << '\n'; 21 | pq.pop(); 22 | } 23 | } 24 | else pq.emplace(abs(x), x); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/11286/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/29a558ec778348f589fad5c627187638 4 | import sys 5 | import heapq 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | heap = [] 12 | for i in range(N): 13 | x = int(input()) 14 | if x == 0: 15 | if heap: 16 | print(heapq.heappop(heap)[1]) 17 | else: 18 | print(0) 19 | else: 20 | heapq.heappush(heap, [abs(x), x]) -------------------------------------------------------------------------------- /solutions/baekjoon/11365/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/d59f549a75a84dd28c01a0f9c08eb169 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | while True: 11 | 12 | password = input() 13 | 14 | if password == 'END': 15 | break 16 | else: 17 | print(password[::-1]) -------------------------------------------------------------------------------- /solutions/baekjoon/11399/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/f1c91eae2a2245c599c5d1bbc9cde9f5 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | arr = list(map(int, input().split())) 11 | arr.sort() 12 | total = 0 13 | waiting = 0 14 | 15 | for i in range(len(arr)): 16 | total += arr[i] + waiting 17 | waiting += arr[i] 18 | 19 | print(total) -------------------------------------------------------------------------------- /solutions/baekjoon/11441/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : ccocco0609 2 | // Co-authored by : tony9402 3 | // Link : http://boj.kr/de37b0fcab5b4d13a414abb3040ee3f5 4 | 5 | #include 6 | using namespace std; 7 | 8 | int main() { 9 | ios_base::sync_with_stdio(false); 10 | cin.tie(NULL); 11 | cout.tie(NULL); 12 | 13 | int n; cin >> n; 14 | vector sum_vector; 15 | 16 | sum_vector.push_back(0); 17 | 18 | for (int i = 0; i < n; i++) { 19 | int tmp = 0; 20 | cin >> tmp; 21 | sum_vector.push_back(sum_vector.back() + tmp); // 누적 합을 저장 22 | } 23 | 24 | int m; cin >> m; 25 | 26 | for (int k = 0; k < m; k++) { 27 | int i, j; 28 | cin >> i >> j; 29 | int result = sum_vector[j] - sum_vector[i - 1]; // 해당하는 범위의 누적합을 구함 30 | cout << result << '\n'; 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /solutions/baekjoon/11441/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : vswngjs 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/a2fb7c4e954d42f4bfabc04bbd2973ba 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline() 8 | 9 | n = int(input()) 10 | 11 | numbers = list(map(int, input().split(" "))) 12 | solve_list = [0] # 누적합을 저장하기 위한 리스트 13 | sum = 0 14 | 15 | for i in numbers: 16 | sum += i 17 | solve_list.append(sum) 18 | 19 | testcase = int(input()) 20 | for i in range(testcase): 21 | parts = list(map(int, input().split())) 22 | print(solve_list[parts[1]] - solve_list[parts[0] - 1]) # i ~ j 인덱스까지의 누적합 23 | -------------------------------------------------------------------------------- /solutions/baekjoon/1145/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/d16fad5335804ed3a30799f0cf9fdf11 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | arr = list(map(int, input().split())) 10 | for i in range(min(arr), 1000001): 11 | ct = 0 12 | for j in range(5): 13 | if i % arr[j] == 0: 14 | ct += 1 15 | if ct >= 3: 16 | print(i) 17 | break -------------------------------------------------------------------------------- /solutions/baekjoon/11508/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/09487b6e14e044f8a477a743e37bce94 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | arr = [] 11 | total = 0 12 | 13 | for i in range(N): 14 | arr.append(int(input())) 15 | 16 | arr.sort(reverse = True) 17 | 18 | ct = 1 19 | 20 | for i in range(N): 21 | if ct % 3 == 0: 22 | ct = 1 23 | continue 24 | 25 | total += arr[i] 26 | ct += 1 27 | 28 | print(total) -------------------------------------------------------------------------------- /solutions/baekjoon/1152/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/f95f97c2cdd74f5f9b832c2e394d4123 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | word = input().split() 9 | print(len(word)) -------------------------------------------------------------------------------- /solutions/baekjoon/1158/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/d29720a15b49470bb1ec3f405e4decdb 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N, K; cin >> N >> K; 13 | queue Q; 14 | for(int i=1;i<=N;i++) Q.push(i); 15 | cout << "<"; 16 | while(true) { 17 | for(int i=1;i"; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/1158/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : klm03025 2 | # Co-authored by : - 3 | # Link : http://boj.kr/1306fa8a1c5a4f4cab631f833d92636a 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N, K = map(int, input().split()) 11 | _list = [] 12 | q = deque([i + 1 for i in range(N)]) 13 | 14 | while len(q) != 0: 15 | q.rotate(-K) 16 | _list.append(q.pop()) 17 | 18 | print('<' + ', '.join(map(str, _list)) + '>') -------------------------------------------------------------------------------- /solutions/baekjoon/11653/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/ee2e1b1327414b35ad963676aae23a8b 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | int tmp = N; 14 | for(int i=2;i*i<=N;i++){ 15 | while(tmp % i == 0) { 16 | cout << i << '\n'; 17 | tmp /= i; 18 | } 19 | } 20 | if(tmp != 1) cout << tmp; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/11653/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/ebf75b738a784d6dad28494e18113b31 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | X = N 11 | for i in range(2, N + 1): 12 | if X == 1: 13 | break 14 | while X % i == 0: 15 | X //= i 16 | print(i) 17 | -------------------------------------------------------------------------------- /solutions/baekjoon/11659/main.cpp: -------------------------------------------------------------------------------- 1 | //Authored by : suin8 2 | //Co-authored by : - 3 | //Link : http://boj.kr/12a5a69bad604f3dbd054c028b3e2994 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | int num[100010], sum[100010]; 10 | 11 | int main() { 12 | ios::sync_with_stdio(false); 13 | cin.tie(nullptr); 14 | 15 | int N, M; cin >> N >> M; 16 | 17 | // 입력과 동시에 누적합을 구해놓습니다. 18 | for(int i = 1;i <= N;i++) { 19 | cin >> num[i]; 20 | sum[i] = sum[i - 1] + num[i]; 21 | } 22 | 23 | // end까지의 합 - begin전 까지의 합 = begin ~ end사이 합 24 | for(int i = 0;i < M;i++) { 25 | int begin, end; 26 | cin >> begin >> end; 27 | cout << sum[end] - sum[begin - 1] << '\n'; 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /solutions/baekjoon/11659/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/6ada03e306dd451fbea38bfb38db2a74 4 | 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | n, m = map(int, input().split()) 10 | lst = list(map(int, input().split())) 11 | prefix_sum = [lst[0]] 12 | for i in range(1, n): # 누적 합 구해두기 13 | prefix_sum.append(prefix_sum[i-1] + lst[i]) 14 | 15 | for _ in range(m): 16 | x, y = map(int, input().split()) 17 | x -= 1 18 | if x: print(prefix_sum[y-1] - prefix_sum[x-1]) 19 | else: print(prefix_sum[y-1]) 20 | -------------------------------------------------------------------------------- /solutions/baekjoon/11660/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/c28a9148cd334f45b6edcbc40ae7ec15 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[1033][1033], dp[1033][1033]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N, Q; cin >> N >> Q; 15 | for(int i=1;i<=N;i++) { 16 | for(int j=1;j<=N;j++) { 17 | cin >> arr[i][j]; 18 | dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + arr[i][j]; 19 | } 20 | } 21 | 22 | for(int i=0;i> x1 >> y1 >> x2 >> y2; 24 | cout << dp[x2][y2] - dp[x1-1][y2] - dp[x2][y1-1] + dp[x1-1][y1-1] << '\n'; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/11720/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/85503261a5b5492ca153ccbe74adf43d 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | num = input() 11 | total = 0 12 | for i in num: 13 | total += int(i) 14 | 15 | print(total) 16 | -------------------------------------------------------------------------------- /solutions/baekjoon/11722/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/6b74718335d14780a6213de8a6b33e42 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | arr = list(map(int, input().split())) 11 | dp = [1] * (N+1) 12 | for i in range(N): 13 | for j in range(i+1,N): 14 | if arr[i] > arr[j]: 15 | dp[j] = max(dp[i]+1, dp[j]) 16 | print(max(dp)) -------------------------------------------------------------------------------- /solutions/baekjoon/11724/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/e86763e30a974134ade5e3bdf6b7936d 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def DFS(now): 11 | visited[now] = 1 12 | for i in arr[now]: 13 | if visited[i] == 0: 14 | DFS(i) 15 | 16 | N, M = map(int, input().split()) 17 | arr = [[] for i in range(N+1)] 18 | visited = [0] * (N+1) 19 | ans = 0 20 | 21 | for i in range(M): 22 | u,v = map(int, input().split()) 23 | arr[u].append(v) 24 | arr[v].append(u) 25 | 26 | for i in range(1,N+1): 27 | if visited[i] == 0: 28 | DFS(i) 29 | ans += 1 30 | 31 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/11725/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : seastar105 2 | // Co-authored by : - 3 | // Link : http://boj.kr/c28e084e8adc4eb78851cc603e7f5b37 4 | #include 5 | using namespace std; 6 | int N; 7 | vector> G(100005); 8 | int parent[100005]; 9 | 10 | void dfs(int cur) { 11 | for (const int &nxt : G[cur]) { 12 | if (parent[cur] == nxt) continue; 13 | parent[nxt] = cur; 14 | dfs(nxt); 15 | } 16 | } 17 | 18 | int main() { 19 | cin.tie(nullptr); 20 | ios::sync_with_stdio(false); 21 | cin >> N; 22 | for (int i = 0; i < N - 1; ++i) { 23 | int u, v; 24 | cin >> u >> v; 25 | G[u].push_back(v); 26 | G[v].push_back(u); 27 | } 28 | dfs(1); 29 | for (int i = 2; i <= N; ++i) cout << parent[i] << '\n'; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /solutions/baekjoon/11726/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/120bee5ac7444d88ad6686eecd957cd2 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | MOD = 10007 10 | N = int(input()) 11 | dp = [0] * (N+2) 12 | dp[1] = 1 13 | dp[2] = 2 14 | 15 | for i in range(3,N+1): 16 | dp[i] = (dp[i-1] + dp[i-2]) % MOD 17 | 18 | print(dp[N] % MOD) 19 | -------------------------------------------------------------------------------- /solutions/baekjoon/11727/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/db4e4b38ee3c4264b672837fa8fff893 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | MOD = 10007 10 | N = int(input()) 11 | dp = [0] * (N+2) 12 | dp[1] = 1 13 | dp[2] = 3 14 | 15 | for i in range(3,N+1): 16 | dp[i] = (dp[i-1] + dp[i-2] * 2) % MOD 17 | 18 | print(dp[N] % MOD) 19 | -------------------------------------------------------------------------------- /solutions/baekjoon/11728/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : wassup37 2 | # Co-authored by : - 3 | # Link : http://boj.kr/160f85b47e1c4351b89ce2691c91fc6b 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | A = list(map(int, input().split())) 11 | B = list(map(int, input().split())) 12 | ans = [] 13 | a_pointer, b_pointer = 0, 0 # A, B list pointer 14 | 15 | while a_pointer != N or b_pointer != M: 16 | if a_pointer == N: 17 | ans.append(B[b_pointer]) 18 | b_pointer += 1 19 | elif b_pointer == M: 20 | ans.append(A[a_pointer]) 21 | a_pointer += 1 22 | else: 23 | if A[a_pointer] < B[b_pointer]: 24 | ans.append(A[a_pointer]) 25 | a_pointer += 1 26 | else: 27 | ans.append(B[b_pointer]) 28 | b_pointer += 1 29 | 30 | print(' '.join(map(str, ans))) # print(*ans) 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/1181/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/c540e6d57a39460eb360903623b90eec 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | arr = [] 12 | 13 | for i in range(N): 14 | arr.append(input()) 15 | 16 | arr = list(set(arr)) 17 | arr.sort(key = lambda x : (len(x), x)) 18 | 19 | for i in arr: 20 | print(i) -------------------------------------------------------------------------------- /solutions/baekjoon/1182/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/1938989c82c1488282cdb2c22d4a9e17 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def backTracking(idx): 10 | global ans 11 | if len(poc) >= N: 12 | if sum(poc) == S: 13 | ans += 1 14 | return 15 | else: 16 | if sum(poc) == S and poc: 17 | ans += 1 18 | for i in range(idx,N): 19 | poc.append(arr[i]) 20 | backTracking(i+1) 21 | poc.pop() 22 | 23 | N, S = map(int, input().split()) 24 | arr = list(map(int, input().split())) 25 | visited = [0] * N 26 | poc = [] 27 | ans = 0 28 | backTracking(0) 29 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/11909/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/ae5c8a4d54074ca1a2af053ecbad14a1 4 | #include 5 | 6 | using namespace std; 7 | 8 | const int INF = 0x3f3f3f3f; 9 | 10 | int main() { 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N; cin >> N; 15 | vector> V(N, vector(N)); 16 | vector> DP(N, vector(N, INF)); 17 | DP[0][0]=0; 18 | for(int i=0;i> V[i][j]; 21 | if(j > 0){ 22 | int d = max(0, V[i][j] - V[i][j-1] + 1); 23 | DP[i][j]=min(DP[i][j], DP[i][j-1] + d); 24 | } 25 | if(i > 0){ 26 | int d = max(0, V[i][j] - V[i-1][j] + 1); 27 | DP[i][j] = min(DP[i][j], DP[i-1][j] + d); 28 | } 29 | } 30 | } 31 | cout << DP[N-1][N-1]; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /solutions/baekjoon/11909/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/a7949813f6e74a918f1f18b458ea5f8c 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | inf = float('inf') 11 | n = int(input()) 12 | prison = [list(map(int, input().split())) for _ in range(n)] 13 | dp = [[inf] * n for _ in range(n)] 14 | dp[0][0] = 0 15 | dirx = [1, 0] 16 | diry = [0, 1] 17 | 18 | q = deque() 19 | q.append((0, 0)) 20 | while q: 21 | x, y = q.popleft() 22 | for dx, dy in zip(dirx, diry): 23 | nx, ny = x + dx, y + dy 24 | if 0 <= nx < n and 0 <= ny < n: 25 | cost = prison[nx][ny] - prison[x][y] + 1 26 | if cost < 1: 27 | cost = 0 28 | if dp[nx][ny] > dp[x][y] + cost: 29 | q.append((nx, ny)) 30 | dp[nx][ny] = dp[x][y] + cost 31 | 32 | print(dp[n - 1][n - 1]) -------------------------------------------------------------------------------- /solutions/baekjoon/12015/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/c74669b0329d4d59ad5145504275e7ac 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | vector V(N), DP; 14 | for(auto &i: V) cin >> i; 15 | for(int i=0;i 5 | 6 | using namespace std; 7 | 8 | string convert(char s, bool fillzero=false){ 9 | int n = s - 48; 10 | string ret = ""; 11 | while(n){ 12 | ret += (n % 2) + '0'; 13 | n /= 2; 14 | } 15 | while(fillzero && (int)ret.size() < 3) ret += '0'; 16 | reverse(ret.begin(), ret.end()); 17 | return ret; 18 | } 19 | 20 | int main(){ 21 | ios::sync_with_stdio(false); 22 | cin.tie(0); 23 | 24 | string s;cin >> s; 25 | if(s == "0") { 26 | cout << 0; 27 | return 0; 28 | } 29 | string ans=""; 30 | for(int i=0;i<(int)s.size();i++){ 31 | ans += convert(s[i], i != 0); 32 | } 33 | cout << ans; 34 | 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /solutions/baekjoon/1212/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/7d0d2bcb568d4c3d86770e520838ef65 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def change(num, first = False): 10 | ret = '' 11 | while num: 12 | ret += chr(num % 2 + 48) 13 | num //= 2 14 | while len(ret) < 3: 15 | ret += '0' 16 | 17 | idx = 3 18 | if first: 19 | while idx > 1 and ret[idx - 1] == '0': 20 | idx -= 1 21 | return ret[:idx][::-1] 22 | 23 | N = input() 24 | isFirst = True 25 | for i in range(len(N)): 26 | print(change(int(N[i]), isFirst),end='') 27 | isFirst = False 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/1244/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/f13978d7e3b8455c846f5825c6eca041 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[105]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int n; cin >> n; 15 | for(int i=1;i<=n;i++) cin >> arr[i]; 16 | int query; cin >> query; 17 | while(query--){ 18 | int type, idx; cin >> type >> idx; 19 | if(type == 1){ 20 | for(int i=idx;i<=n;i+=idx) arr[i] ^= 1; 21 | } 22 | else { 23 | int w = 0; 24 | while(1 <= idx - w - 1 && idx + w + 1 <= n && arr[idx - w - 1] == arr[idx + w + 1]) w++; 25 | for(int i=idx-w;i<=idx+w;i++) arr[i] ^= 1; 26 | } 27 | } 28 | for(int i=1;i<=n;i++) { 29 | cout << arr[i]; 30 | if(i % 20 == 0) cout << '\n'; 31 | else cout << " "; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /solutions/baekjoon/1269/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/73b320e09628425c8d29b3c81287a865 4 | import sys 5 | from collections import defaultdict 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | len_a, len_b = map(int, input().split()) 11 | dict_a = defaultdict(int) 12 | 13 | for number in map(int, input().split()): 14 | dict_a[number] = 1 15 | 16 | cnt = 0 17 | 18 | for number in map(int, input().split()): 19 | if dict_a[number]: 20 | cnt += 1 21 | 22 | answer = (len_a - cnt) + (len_b - cnt) 23 | print(answer) -------------------------------------------------------------------------------- /solutions/baekjoon/12871/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/7d4da3364b4d4735b5f99d946b785fff 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | def GCD(x,y): 9 | if y == 0: 10 | return x 11 | else: 12 | return GCD(y, x%y) 13 | 14 | s = input() 15 | t = input() 16 | gcd = GCD(len(s),len(t)) 17 | lcm = len(s) * len(t) // gcd 18 | s = s * (lcm // len(s)) 19 | t = t * (lcm // len(t)) 20 | if s == t: 21 | print(1) 22 | else: 23 | print(0) 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/1302/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/2ddf5f20f83c4c4e9cf3f2b415202e4b 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | map mp; 14 | string ans; 15 | int mx = 0; 16 | for(int i = 0; i < N; ++i) { 17 | string S; cin >> S; 18 | int x = ++mp[S]; 19 | if(x > mx) { 20 | mx = x; 21 | ans = S; 22 | } 23 | else if(x == mx) { 24 | ans = min(ans, S); 25 | } 26 | } 27 | cout << ans; 28 | 29 | return 0; 30 | } 31 | 32 | /* Solution Description 33 | std::map을 이용해서 문자열이 몇 번 나왔는지 개수를 세면서 가장 많이 등장한 문자열을 찾으면 됨. 34 | 가장 많이 등장한 문자열이 여러가지일 경우는 사전순으로 가장 먼저 오는 문자열을 찾아야한다는걸 놓치면 안됨. 35 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/1302/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/8adc986ae26b461eadd65abdff3cfba9 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | book = {} 11 | for i in range(N): 12 | name = input() 13 | if name not in book: 14 | book[name] = 1 15 | else: 16 | book[name] += 1 17 | 18 | book = list(book.items()) 19 | book.sort(key = lambda x : (-x[1],x[0])) 20 | print(book[0][0]) 21 | -------------------------------------------------------------------------------- /solutions/baekjoon/1312/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/f98baead51c347eb9f67565082701e07 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | long long A, B, N; cin >> A >> B >> N; 13 | A %= B; 14 | 15 | int ans = 0; 16 | for(int i = 0; i < N; ++i) { 17 | A *= 10; 18 | ans = A / B; 19 | A %= B; 20 | } 21 | cout << ans; 22 | 23 | return 0; 24 | } 25 | 26 | /* Solution Description 27 | A를 B로 나눈 나머지를 계속 유지해야함. 28 | N번동안 A에 10을 곱하고 B로 나누는 과정을 통해 N번째 숫자를 구할 수 있음. 29 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/1316/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/1649bc736d5e4692b067d78aa43b2edc 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | ans = N 11 | for i in range(N): 12 | a = input() 13 | dic = {} 14 | while True: 15 | flag = 0 16 | for j in range(len(a)-1): 17 | if a[j] == a[j+1]: 18 | a = a[:j] + a[j+1:] 19 | flag = 1 20 | break 21 | if flag == 0: 22 | break 23 | for j in a: 24 | if j not in dic: 25 | dic[j] = 1 26 | else: 27 | ans -=1 28 | break 29 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/13164/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/cfb369b6a5134cfa9c0859eab5464c47 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | n, k = map(int, input().split()) 9 | lst = list(map(int, input().split())) # 정렬된 상태로 들어옴 10 | sub = sorted([lst[i+1] - lst[i] for i in range(n-1)]) # 원생 간 키 차이 정렬 11 | print(sum(sub[:(n-k)])) # Greedy하게 n-k개만 선택 -------------------------------------------------------------------------------- /solutions/baekjoon/13305/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/bdcb1993d67a400c8293683e5c7dbf7d 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | vector cost, dis, prefix; 10 | 11 | int main(){ 12 | ios::sync_with_stdio(false); 13 | cin.tie(0); 14 | 15 | int N; cin >> N; 16 | cost.resize(N); 17 | dis.resize(N - 1); 18 | prefix.resize(N); 19 | for(int i=0;i> dis[i]; 20 | for(int i=0;i> cost[i]; 23 | } 24 | int R = 0; 25 | ll answer = 0; 26 | for(int i=0;i 5 | 6 | using namespace std; 7 | 8 | unordered_set st; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N, M; cin >> N >> M; 15 | for(int i=0;i> s; 17 | st.insert(s); 18 | } 19 | 20 | int answer = 0; 21 | for(int i=0;i> s; 23 | if(st.find(s) != st.end()) answer ++; 24 | } 25 | cout << answer; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/14425/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/efd53a96cfd04ca9ab21018162c3084d 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N, M = map(int, input().split()) 11 | ans = 0 12 | dic = {} 13 | for i in range(N): 14 | a = input() 15 | dic[a] = 1 16 | for i in range(M): 17 | a = input() 18 | if a in dic: 19 | ans += 1 20 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/14467/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/88f56047b85749c39427398cd19c31e9 4 | #include 5 | 6 | using namespace std; 7 | 8 | int used[105]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | for(int i=0;i<=100;i++) used[i] = -1; 15 | 16 | int n; cin >> n; 17 | int answer = 0; 18 | for(int i=0;i> num >> loc; 20 | 21 | if(used[num] < 0) used[num] = loc; 22 | else if(used[num] != loc){ 23 | used[num] = loc; 24 | answer ++; 25 | } 26 | } 27 | cout << answer; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/14563/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/4e383f17fcfa484cba0207093d4bc175 4 | #include 5 | 6 | using namespace std; 7 | 8 | string is_perfect_number(int x) { 9 | int ret = 0; 10 | for(int i = 1; i < x; ++i) { 11 | if(x % i == 0) { 12 | ret += i; 13 | } 14 | } 15 | 16 | if(x == ret) return "Perfect"; 17 | else if(x < ret) return "Abundant"; 18 | else return "Deficient"; 19 | } 20 | 21 | int main() { 22 | ios::sync_with_stdio(false); 23 | cin.tie(0); 24 | 25 | int T; cin >> T; 26 | for(int i = 0; i < T; ++i) { 27 | int x; cin >> x; 28 | cout << is_perfect_number(x) << '\n'; 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | /* Solution Description 35 | 1부터 x - 1까지 보면서 x의 약수들을 찾고 그 합이 x와 비교하여 답을 출력하면 된다. 36 | 시간복잡도 : O(TN) => 약 10^7이므로 1초 안에 돌아갈 수 있다. 37 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/14567/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : yj2221 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/563199054385492b8f7e25eca46a2696 4 | 5 | from collections import deque 6 | import sys 7 | 8 | def input(): 9 | return sys.stdin.readline().rstrip() 10 | 11 | n, m = map(int, input().split()) 12 | 13 | learning = {i:[] for i in range(1, n+1)} 14 | indegree = [0] * (n+1) 15 | dp = [1] * (n+1) 16 | 17 | for _ in range(m): 18 | a, b = map(int, input().split()) 19 | learning[a].append(b) 20 | indegree[b] += 1 21 | 22 | q = deque() 23 | for i in range(1,n+1): 24 | if indegree[i] == 0: 25 | q.append(i) 26 | 27 | while q: 28 | cur = q.popleft() 29 | for nxt in learning[cur]: 30 | indegree[nxt] -= 1 31 | if indegree[nxt] == 0: 32 | q.append(nxt) 33 | dp[nxt] = max(dp[nxt], dp[cur]+1) 34 | 35 | print(' '.join(map(str,dp[1:]))) 36 | -------------------------------------------------------------------------------- /solutions/baekjoon/1463/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tallua_y 2 | // Co-authored by : - 3 | // Link : http://boj.kr/96a171e5da7746c7a51d5d348bc759a8 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char** argv) 9 | { 10 | ios::sync_with_stdio(false); 11 | cin.tie(nullptr); 12 | 13 | size_t N; 14 | cin >> N; 15 | 16 | vector count(N + 1); 17 | count[1] = 0; 18 | 19 | for(int i = 2; i < N + 1; ++i) { 20 | count[i] = count[i - 1] + 1; 21 | if (i % 2 == 0) { 22 | count[i] = min(count[i], count[i / 2] + 1); 23 | } 24 | if (i % 3 == 0) { 25 | count[i] = min(count[i], count[i / 3] + 1); 26 | } 27 | } 28 | 29 | cout << count[N] << '\n'; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /solutions/baekjoon/14697/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/76974dc8cc4b4b4a849de1a3f1d91ee3 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int arr[3], N; 13 | for(int i = 0; i < 3; ++i) cin >> arr[i]; 14 | cin >> N; 15 | 16 | bool answer = false; 17 | for(int i = 0; arr[0] * i <= N; ++i) { 18 | for(int j = 0; arr[0] * i + arr[1] * j <= N; ++j) { 19 | int rem = N - arr[0] * i - arr[1] * j; 20 | if(rem % arr[2] == 0) answer = true; 21 | } 22 | } 23 | cout << answer; 24 | 25 | return 0; 26 | } 27 | 28 | /* Solution Description 29 | 가능한 모든 조합을 확인해서 Ax + By + Cz = N을 만족하는 (x, y, z)가 하나라도 있는지 보면 된다. 30 | 시간복잡도는 O(N^2)으로 충분히 돌 수 있다. 31 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/14712/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/1a1754c8c07c462e9d52af5ae146809c 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | int N, M, Map[33][33]; // 1-index 10 | int answer = 0; 11 | 12 | bool check(int y, int x) { 13 | return Map[y-1][x] && Map[y][x-1] && Map[y-1][x-1]; 14 | } 15 | 16 | void go(int usedCnt) { 17 | if(usedCnt == N * M) { 18 | answer ++; 19 | return ; 20 | } 21 | 22 | int y = usedCnt / M + 1; 23 | int x = usedCnt % M + 1; 24 | 25 | go(usedCnt + 1); 26 | if(!check(y, x)) { 27 | Map[y][x] = 1; 28 | go(usedCnt + 1); 29 | Map[y][x] = 0; 30 | } 31 | } 32 | 33 | int main(){ 34 | ios::sync_with_stdio(false); 35 | cin.tie(0); 36 | 37 | cin >> N >> M; 38 | go(0); 39 | cout << answer; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /solutions/baekjoon/14712/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/117634e91c71493787610c9e0406a605 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | 11 | # 1-index 12 | Map = [ [ 0 for _ in range(M + 1) ] for __ in range(N + 1) ] 13 | answer = 0 14 | 15 | def dfs(cnt): 16 | global answer 17 | if cnt == N * M: 18 | answer += 1 19 | return 20 | 21 | y = cnt // M + 1 22 | x = cnt % M + 1 23 | 24 | dfs(cnt + 1) 25 | if Map[y - 1][x] == 0 or Map[y][x - 1] == 0 or Map[y - 1][x - 1] == 0: # 만약 놓을 수 있는 곳이라면 26 | Map[y][x] = 1 27 | dfs(cnt + 1) 28 | Map[y][x] = 0 29 | 30 | dfs(0) 31 | print(answer) 32 | -------------------------------------------------------------------------------- /solutions/baekjoon/14716/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/b5d154fcfb1c46e6a99e702c35f4eb26 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | M, N = map(int, input().split()) 10 | banner = [list(map(int, input().split())) for _ in range(M)] 11 | dirx = (1, 0, -1, 0, 1, 1, -1, -1) 12 | diry = (0, 1, 0, -1, 1, -1, 1, -1) 13 | 14 | def find_string(row, col): 15 | stack = [(row, col)] 16 | banner[row][col] = 0 17 | while stack: 18 | x, y = stack.pop() 19 | for dx, dy in zip(dirx, diry): 20 | nx, ny = x + dx, y + dy 21 | if 0 <= nx < M and 0 <= ny < N and banner[nx][ny]: 22 | stack.append((nx, ny)) 23 | banner[nx][ny] = 0 24 | return 1 25 | 26 | string_cnt = 0 27 | for i in range(M): 28 | for j in range(N): 29 | if banner[i][j]: 30 | string_cnt += find_string(i, j) 31 | 32 | print(string_cnt) 33 | -------------------------------------------------------------------------------- /solutions/baekjoon/14719/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/5af0f7388d84485db221c368ce306c4b 4 | 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | h, w = map(int, input().split()) 10 | wall = list(map(int, input().split())) 11 | 12 | # Numpy 없이 argmax 13 | def argmax(a): 14 | return max(range(len(a)), key=lambda x: a[x]) 15 | max_idx = argmax(wall) 16 | 17 | sol, tmp_max = 0, 0 18 | # 가장 높은 벽 기준 왼쪽부터 벽+채울 수 있는 물 합한 면적 더하기 19 | for i in range(max_idx+1): 20 | tmp_max = max(tmp_max, wall[i]) 21 | sol += tmp_max 22 | 23 | tmp_max = 0 24 | # 가장 높은 벽 기준 오른쪽부터 벽+채울 수 있는 물 합한 면적 더하기 25 | for i in range(w-1, max_idx, -1): 26 | tmp_max = max(tmp_max, wall[i]) 27 | sol += tmp_max 28 | 29 | #벽이 차지하는 면적 빼주면 정답 30 | print(sol-sum(wall)) -------------------------------------------------------------------------------- /solutions/baekjoon/1477/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : yj2221 2 | # Co-authored by : - 3 | # Link : http://boj.kr/b93ed1e8f2a7413fa8fe39483692604f 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | n, m, l = map(int, input().split()) 11 | rests = sorted([0] + list(map(int, input().split())) + [l]) 12 | 13 | low = 1 14 | high = l 15 | answer = high 16 | while low <= high: 17 | mid = (low + high) // 2 18 | 19 | cnt = 0 20 | for i in range(n+1): 21 | cnt += (rests[i+1] - rests[i] - 1) // mid 22 | 23 | if cnt<=m: 24 | answer = mid 25 | high = mid - 1 26 | else: 27 | low = mid + 1 28 | 29 | print(answer) 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/14916/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/f274a6ac753440deb8c47de3ee127244 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | if N < 5: 12 | if N % 2 != 0: 13 | ans = -1 14 | else: 15 | ans = N // 2 16 | else: 17 | ct, N = divmod(N, 5) 18 | if N == 0: 19 | ans = ct 20 | else: 21 | if N % 2 == 0: 22 | ct += N // 2 23 | ans = ct 24 | else: 25 | ct += (N + 5) // 2 - 1 26 | ans = ct 27 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/14929/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/0351fb8839dd449cbdc10b9e78c47410 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | int main(){ 10 | ios::sync_with_stdio(false); 11 | cin.tie(0); 12 | 13 | int N; cin >> N; 14 | ll sum = 0, square_sum = 0; 15 | for(int i=0;i> x; 17 | sum += x; 18 | square_sum += x * x; 19 | } 20 | cout << (sum * sum - square_sum) / 2; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/1520/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/5c0cf17f207745eb899923dfc5881c26 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def DFS(x,y): 11 | if x == N-1 and y == M-1: 12 | return 1 13 | if dp[x][y] == -1: 14 | dp[x][y] = 0 15 | for i in range(4): 16 | dx = nx[i] + x 17 | dy = ny[i] + y 18 | if dx < 0 or dx >= N or dy < 0 or dy >= M: 19 | continue 20 | if arr[dx][dy] < arr[x][y]: 21 | dp[x][y] += DFS(dx,dy) 22 | return dp[x][y] 23 | 24 | N, M = map(int, input().split()) 25 | arr = [] 26 | nx = [-1, 0, 1, 0] 27 | ny = [0, -1, 0, 1] 28 | dp = [[-1 for i in range(M)] for j in range(N)] 29 | for i in range(N): 30 | arr.append(list(map(int, input().split()))) 31 | print(DFS(0,0)) -------------------------------------------------------------------------------- /solutions/baekjoon/15649/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/51963cf92cd741ea8bb67b164cc944f9 4 | #include 5 | 6 | using namespace std; 7 | 8 | int choose[10], N, M; 9 | bool used[10]; 10 | 11 | void dfs(int cnt) { 12 | if(cnt == M) { 13 | for(int i=0;i> N >> M; 34 | dfs(0); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /solutions/baekjoon/15649/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/69f68131effd4506a17fdac4b8569c6c 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | choose = [ 0 for _ in range(10) ] 11 | used = [ 0 for _ in range(10) ] 12 | 13 | def dfs(cnt): 14 | global N, M 15 | if cnt == M: 16 | for idx in range(cnt): 17 | print(choose[idx], end=' ') 18 | print() 19 | return 20 | 21 | for i in range(1, N + 1): 22 | if used[i]: 23 | continue 24 | used[i] = 1 25 | choose[cnt] = i 26 | dfs(cnt + 1) 27 | used[i] = 0 28 | 29 | dfs(0) 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/15650/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/dc4a2e040e7d406b875abaa4d969bd50 4 | #include 5 | 6 | using namespace std; 7 | 8 | int choose[10], N, M; 9 | bool used[10]; 10 | 11 | void dfs(int pre, int cnt) { 12 | if(cnt == M) { 13 | for(int i=0;i> N >> M; 34 | dfs(0, 0); 35 | 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /solutions/baekjoon/15650/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/afca9b0c42354f99a6578ab92e0de0a3 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | choose = [ 0 for _ in range(10) ] 11 | used = [ 0 for _ in range(10) ] 12 | 13 | def dfs(idx, cnt): 14 | global N, M 15 | if cnt == M: 16 | for idx in range(cnt): 17 | print(choose[idx], end=' ') 18 | print() 19 | return 20 | 21 | for i in range(idx, N + 1): 22 | if used[i]: 23 | continue 24 | used[i] = 1 25 | choose[cnt] = i 26 | dfs(i + 1, cnt + 1) 27 | used[i] = 0 28 | 29 | dfs(1, 0) 30 | 31 | 32 | -------------------------------------------------------------------------------- /solutions/baekjoon/15651/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/0a5ce31db1ff47cf8190b0275e74bef8 4 | #include 5 | 6 | using namespace std; 7 | 8 | int choose[10], N, M; 9 | 10 | void dfs(int cnt) { 11 | if(cnt == M) { 12 | for(int i=0;i> N >> M; 30 | dfs(0); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /solutions/baekjoon/15651/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/4631083fc0c04817af9b1020e2396ddc 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | choose = [ 0 for _ in range(10) ] 11 | 12 | def dfs(idx, cnt): 13 | global N, M 14 | if cnt == M: 15 | for idx in range(cnt): 16 | print(choose[idx], end=' ') 17 | print() 18 | return 19 | 20 | for i in range(1, N + 1): 21 | choose[cnt] = i 22 | dfs(i + 1, cnt + 1) 23 | 24 | dfs(1, 0) 25 | 26 | -------------------------------------------------------------------------------- /solutions/baekjoon/15652/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/a90bad59d92f4f87bbb056c9e643b330 4 | #include 5 | 6 | using namespace std; 7 | 8 | int choose[10], N, M; 9 | 10 | void dfs(int pre, int cnt) { 11 | if(cnt == M) { 12 | for(int i=0;i> N >> M; 30 | dfs(1, 0); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /solutions/baekjoon/15652/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/2a9874489cb74d7babd30d70501acff9 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | choose = [ 0 for _ in range(10) ] 11 | 12 | def dfs(idx, cnt): 13 | global N, M 14 | if cnt == M: 15 | for idx in range(cnt): 16 | print(choose[idx], end=' ') 17 | print() 18 | return 19 | 20 | for i in range(idx, N + 1): 21 | choose[cnt] = i 22 | dfs(i, cnt + 1) 23 | 24 | dfs(1, 0) 25 | 26 | 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/15654/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/3955b249d38d4c79851d4cf97d474c0b 4 | #include 5 | 6 | using namespace std; 7 | 8 | int choose[10]; 9 | int arr[10], N, M; 10 | bool used[10]; 11 | 12 | void dfs(int cnt) { 13 | if(cnt == M) { 14 | for(int i=0;i> N >> M; 34 | for(int i=0;i> arr[i]; 35 | sort(arr, arr + N); 36 | dfs(0); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /solutions/baekjoon/15654/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/fa5e88e6aac14dbabbbb8b5bc7037963 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = sorted(list(map(int, input().split()))) 11 | choose = [ 0 for _ in range(10) ] 12 | used = [ 0 for _ in range(10) ] 13 | 14 | def dfs(cnt): 15 | global N, M 16 | if cnt == M: 17 | for idx in range(cnt): 18 | print(arr[choose[idx]], end=' ') 19 | print() 20 | return 21 | 22 | for i in range(0,N): 23 | if used[i]: 24 | continue 25 | used[i] = 1 26 | choose[cnt] = i 27 | dfs(cnt + 1) 28 | used[i] = 0 29 | 30 | dfs(0) 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/15655/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/cb5e9a75972a4ac59cc7b4428d07f2fa 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[10], choose[10], N, M; 9 | bool used[10]; 10 | 11 | void dfs(int idx, int cnt) { 12 | if(cnt == M){ 13 | for(int i=0;i> N >> M; 34 | for(int i=0;i> arr[i]; 35 | sort(arr, arr + N); 36 | dfs(0, 0); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /solutions/baekjoon/15655/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/d4f609a8ba2e40e8b578c37f3d21d344 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = sorted(list(map(int, input().split()))) 11 | choose = [ 0 for _ in range(10) ] 12 | used = [ 0 for _ in range(10) ] 13 | 14 | def dfs(idx, cnt): 15 | global N, M 16 | if cnt == M: 17 | for idx in range(cnt): 18 | print(arr[choose[idx]], end=' ') 19 | print() 20 | return 21 | 22 | for i in range(idx,N): 23 | if used[i]: 24 | continue 25 | used[i] = 1 26 | choose[cnt] = i 27 | dfs(i + 1, cnt + 1) 28 | used[i] = 0 29 | 30 | dfs(0, 0) 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/15656/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/83f80cd932d54d52bc8cd412a6ee3abc 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[10], choose[10], N, M; 9 | 10 | void dfs(int cnt) { 11 | if(cnt == M) { 12 | for(int i=0;i> N >> M; 29 | for(int i=0;i> arr[i]; 30 | sort(arr, arr + N); 31 | dfs(0); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /solutions/baekjoon/15656/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/dd28c9dd06a54efeb12b4f72e82e8c77 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().strip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = sorted(list(map(int, input().split()))) 11 | choose = [ 0 for _ in range(10) ] 12 | 13 | def dfs(cnt): 14 | global N, M 15 | if cnt == M: 16 | for idx in range(cnt): 17 | print(arr[choose[idx]], end=' ') 18 | print() 19 | return 20 | 21 | for i in range(0,N): 22 | choose[cnt] = i 23 | dfs(cnt + 1) 24 | 25 | dfs(0) 26 | -------------------------------------------------------------------------------- /solutions/baekjoon/15657/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/ba10084d78354aeabad7a57999d07356 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[10], choose[10], N, M; 9 | 10 | void dfs(int idx, int cnt) { 11 | if(cnt == M) { 12 | for(int i=0;i> N >> M; 29 | for(int i=0;i> arr[i]; 30 | sort(arr, arr + N); 31 | dfs(0, 0); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /solutions/baekjoon/15657/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/7bbdc54527b2456d9e1e829834a2ece2 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = sorted(list(map(int, input().split()))) 11 | choose = [ 0 for _ in range(10) ] 12 | 13 | def dfs(idx, cnt): 14 | global N, M 15 | if cnt == M: 16 | for idx in range(cnt): 17 | print(arr[choose[idx]], end=' ') 18 | print() 19 | return 20 | 21 | for i in range(idx,N): 22 | choose[cnt] = i 23 | dfs(i, cnt + 1) 24 | 25 | dfs(0, 0) 26 | 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/15661/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/946d652cbd7a4361aaeff5ff1f2612d5 4 | import sys 5 | from itertools import combinations 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | arr = [] 12 | num = [i for i in range(N)] 13 | MIN = 1e9 14 | for i in range(N): 15 | arr.append(list(map(int, input().split()))) 16 | comb_list = list(combinations(num, N//2)) 17 | for comb in comb_list: 18 | start = 0 19 | link = 0 20 | remain = [i for i in range(N) if i not in comb] 21 | for com in combinations(comb, 2): 22 | start += arr[com[0]][com[1]] 23 | for ar in combinations(remain, 2): 24 | link += arr[ar[0]][ar[1]] 25 | MIN = min(MIN, abs(start - link)) 26 | print(MIN) -------------------------------------------------------------------------------- /solutions/baekjoon/15663/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/07e0a7b8b518418d86ac107dcdf56a7e 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[10], choose[10], N, M; 9 | bool used[10]; 10 | 11 | void dfs(int cnt) { 12 | if(cnt == M) { 13 | for(int i=0;i> N >> M; 35 | for(int i=0;i> arr[i]; 36 | sort(arr, arr + N); 37 | dfs(0); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /solutions/baekjoon/15663/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/186f2997e3dd48859f2ef8b729d98bf3 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = sorted(list(map(int, input().split()))) 11 | choose = [ 0 for _ in range(10) ] 12 | used = [ 0 for _ in range(10) ] 13 | 14 | def dfs(cnt): 15 | global N, M 16 | if cnt == M: 17 | for idx in range(cnt): 18 | print(arr[choose[idx]], end=' ') 19 | print() 20 | return 21 | 22 | pre = -1 23 | for i in range(N): 24 | if used[i] or pre == arr[i]: 25 | continue 26 | pre = arr[i] 27 | used[i] = 1 28 | choose[cnt] = i 29 | dfs(cnt + 1) 30 | used[i] = 0 31 | 32 | dfs(0) 33 | -------------------------------------------------------------------------------- /solutions/baekjoon/15664/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/6b0fef4c57c541529fa7feb2b74cd385 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[10], choose[10], N, M; 9 | bool used[10]; 10 | 11 | void dfs(int idx, int cnt) { 12 | if(cnt == M) { 13 | for(int i=0;i> N >> M; 35 | for(int i=0;i> arr[i]; 36 | sort(arr, arr + N); 37 | dfs(0, 0); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /solutions/baekjoon/15664/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/e43bf55556be4bd19c0ae586bcf5d12a 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = sorted(list(map(int, input().split()))) 11 | choose = [ 0 for _ in range(10) ] 12 | used = [ 0 for _ in range(10) ] 13 | 14 | def dfs(idx, cnt): 15 | global N, M 16 | if cnt == M: 17 | for idx in range(cnt): 18 | print(arr[choose[idx]], end=' ') 19 | print() 20 | return 21 | 22 | pre = -1 23 | for i in range(idx, N): 24 | if used[i] or pre == arr[i]: 25 | continue 26 | pre = arr[i] 27 | used[i] = 1 28 | choose[cnt] = i 29 | dfs(i + 1, cnt + 1) 30 | used[i] = 0 31 | 32 | dfs(0, 0) 33 | 34 | -------------------------------------------------------------------------------- /solutions/baekjoon/15665/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/216c114645a74d2fa0bcba6ddec5370b 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[10], choose[10], N, M; 9 | 10 | void dfs(int cnt) { 11 | if(cnt == M) { 12 | for(int i=0;i> N >> M; 32 | for(int i=0;i> arr[i]; 33 | sort(arr, arr + N); 34 | dfs(0); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /solutions/baekjoon/15665/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/fc8e94e5fb3f4384a7272130a0624d8d 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = sorted(list(map(int, input().split()))) 11 | choose = [ 0 for _ in range(10) ] 12 | 13 | def dfs(cnt): 14 | global N, M 15 | if cnt == M: 16 | for idx in range(cnt): 17 | print(arr[choose[idx]], end=' ') 18 | print() 19 | return 20 | 21 | pre = -1 22 | for i in range(0, N): 23 | if pre == arr[i]: 24 | continue 25 | pre = arr[i] 26 | choose[cnt] = i 27 | dfs(cnt + 1) 28 | 29 | dfs(0) 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/15666/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/f952a2a2e4724f8981ff82ceccbdf854 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[10], choose[10], N, M; 9 | 10 | void dfs(int idx, int cnt) { 11 | if(cnt == M) { 12 | for(int i=0;i> N >> M; 32 | for(int i=0;i> arr[i]; 33 | sort(arr, arr + N); 34 | dfs(0, 0); 35 | 36 | return 0; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /solutions/baekjoon/15666/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/dbd389b484d4468990a877b205126f0f 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = sorted(list(map(int, input().split()))) 11 | choose = [ 0 for _ in range(10) ] 12 | 13 | def dfs(idx, cnt): 14 | global N, M 15 | if cnt == M: 16 | for idx in range(cnt): 17 | print(arr[choose[idx]], end=' ') 18 | print() 19 | return 20 | 21 | pre = -1 22 | for i in range(idx, N): 23 | if pre == arr[i]: 24 | continue 25 | pre = arr[i] 26 | choose[cnt] = i 27 | dfs(i, cnt + 1) 28 | 29 | dfs(0, 0) 30 | 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/15681/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/acc4b75def8e48d995163a01bcc23068 4 | #include 5 | 6 | using namespace std; 7 | 8 | vector> graph; 9 | vector siz; 10 | 11 | void dfs(int cur, int prv) { 12 | siz[cur] = 1; 13 | 14 | for(auto &nxt: graph[cur]) { 15 | if(nxt == prv) continue; 16 | dfs(nxt, cur); 17 | siz[cur] += siz[nxt]; 18 | } 19 | } 20 | 21 | int main(){ 22 | ios::sync_with_stdio(false); 23 | cin.tie(0); 24 | 25 | int N, R, Q; cin >> N >> R >> Q; 26 | graph.resize(N + 1); 27 | siz.resize(N + 1); 28 | for(int i=1;i> a >> b; 30 | graph[a].push_back(b); 31 | graph[b].push_back(a); 32 | } 33 | dfs(R, R); 34 | 35 | while(Q--) { 36 | int x;cin >> x; 37 | cout << siz[x] << '\n'; 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /solutions/baekjoon/15721/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/2e1ee57b7481444fad22d74a53c6ac21 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int A, T, B; cin >> A >> T >> B; 13 | int answer = -1; 14 | for(int i=1; T ;i++){ 15 | for(int j=0;T && j<4;j++) { 16 | T -= (j % 2 == B); 17 | ++answer; 18 | } 19 | for(int j=0;T && j<2;j++) { 20 | for(int k=0;T && k<=i;k++) { 21 | T -= (j % 2 == B); 22 | ++answer; 23 | } 24 | } 25 | } 26 | cout << answer % A; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/15787/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : yj2221 2 | # Co-authored by : - 3 | # Link : http://boj.kr/a636cadadf8d444180ee022a5af9353a 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | n, m = map(int,input().split()) 11 | trains= [0] * (n+1) 12 | commands = [list(map(int, input().split())) for _ in range(m)] 13 | 14 | for command in commands: 15 | if command[0] == 1: 16 | _, i, x = command 17 | trains[i] |= (1 << (x-1)) 18 | elif command[0] == 2: 19 | _, i, x = command 20 | trains[i] &= ~(1 << (x-1)) 21 | elif command[0] == 3: 22 | _, i = command 23 | trains[i] = trains[i] << 1 24 | trains[i] &= ((1 << 20) - 1) 25 | elif command[0] == 4: 26 | _, i = command 27 | trains[i] = trains[i] >> 1 28 | 29 | result = set(trains[1:]) 30 | print(len(result)) 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/15886/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : hyeonjaee 2 | # Co-authored by : - 3 | # Link : http://boj.kr/f9cd00a87d59430abd180cfe4050d394 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | n = int(input()) 10 | board = input() 11 | ans = sum(1 for i in range(n-1) if board[i] == 'E' and board[i+1] == 'W') 12 | print(ans) 13 | 14 | """ Solution Description 15 | 이동방향이 전환되는 곳, 즉 E 뒤에 W가 이어서 나오는 곳에 선물을 놓아야 한다. 16 | 따라서 입력 받은 리스트에서 E 뒤에 W가 나오면 ans를 1씩 증가한다. 17 | """ 18 | -------------------------------------------------------------------------------- /solutions/baekjoon/15989/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/7363aaeb37fd489aaa5c0ad142ce8a7a 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | ll DP[10005][4]; 10 | 11 | int main(){ 12 | ios::sync_with_stdio(false); 13 | cin.tie(0); 14 | 15 | for(int i=1;i<=3;i++) { 16 | for(int j=1;j<=i;j++) { 17 | DP[i][j] = 1; 18 | } 19 | } 20 | 21 | for(int i=4;i<=10000;i++) { 22 | for(int j=1;j<=3;j++) { 23 | for(int k=1;k<=j;k++) { 24 | DP[i][j] += DP[i - j][k]; 25 | } 26 | } 27 | } 28 | 29 | int T; cin >> T; 30 | while(T--){ 31 | int n; cin >> n; 32 | ll answer = 0; 33 | for(int i=1;i<=3;i++) answer += DP[n][i]; 34 | cout << answer << '\n'; 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /solutions/baekjoon/15990/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/7a8607af45e042df9e44b48962548e1a 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | ll DP[100005][4]; 10 | const ll MOD = 1e9 + 9; 11 | const int MAXN = 100000; 12 | 13 | int main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(0); 16 | 17 | for(int i=1;i<=3;i++) DP[i][i] = DP[3][i] = 1; 18 | for(int i=4;i<=MAXN;i++){ 19 | for(int j=1;j<=3;j++){ 20 | for(int k=1;k<=3;k++){ 21 | if(j == k)continue; 22 | DP[i][j] = (DP[i][j] + DP[i - j][k]) % MOD; 23 | } 24 | } 25 | } 26 | int T; cin >> T; 27 | while(T--){ 28 | int n; cin >> n; 29 | cout << (DP[n][1] + DP[n][2] + DP[n][3]) % MOD << '\n'; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /solutions/baekjoon/16171/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : rlawngus0910 2 | // Co-authored by : tony9402 3 | // Link : http://boj.kr/cddf85db4e694c0d8e9a20dddd32e653 4 | #include 5 | using namespace std; 6 | string input, s, k; 7 | int main() { 8 | cin.sync_with_stdio(0); 9 | cin.tie(0); 10 | cin >> input >> k; 11 | 12 | for (int i = 0; i < (int)input.length(); i++) { 13 | if('0' <= input[i] && input[i] <= '9') continue; 14 | s += input[i]; 15 | } 16 | 17 | if (s.find(k) != string::npos) cout << "1"; 18 | else cout << "0"; 19 | } 20 | -------------------------------------------------------------------------------- /solutions/baekjoon/16174/main.py: -------------------------------------------------------------------------------- 1 | # // Authored by : chj3748 2 | # // Co-authored by : tony9402 3 | # // Link : http://boj.kr/4d17bddef7af409ebdb384693b3f96d9 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | dirx = (0, 1) 11 | diry = (1, 0) 12 | N = int(input()) 13 | maps = [list(map(int, input().split())) for _ in range(N)] 14 | inf = float('inf') 15 | 16 | q = deque() 17 | q.append((0, 0)) 18 | while q: 19 | x, y = q.popleft() 20 | if x == N - 1 and y == N - 1: 21 | print('HaruHaru') 22 | exit(0) 23 | 24 | for dx, dy in zip(dirx, diry): 25 | nx, ny = x + dx * maps[x][y], y + dy * maps[x][y] 26 | if 0 <= nx < N and 0 <= ny < N: 27 | q.append((nx, ny)) 28 | maps[x][y] = inf 29 | 30 | print('Hing') 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/16198/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/3ba9e83879cc4489a5db43c977f87f45 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def DFS(x): 11 | global MAX 12 | if len(arr) == 2: 13 | MAX = max(MAX, x) 14 | return 15 | for i in range(1, len(arr)-1): 16 | save = arr[i] 17 | arr.pop(i) 18 | DFS(x + arr[i-1] * arr[i]) 19 | arr.insert(i, save) 20 | 21 | N = int(input()) 22 | MAX = 0 23 | arr = list(map(int, input().split())) 24 | DFS(0) 25 | print(MAX) 26 | -------------------------------------------------------------------------------- /solutions/baekjoon/1620/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/9289c0621c6f41dabd5bfc2ba190a2ce 4 | #include 5 | 6 | using namespace std; 7 | 8 | unordered_map pokemon; 9 | unordered_map pokemonSeq; 10 | 11 | int main(){ 12 | ios::sync_with_stdio(false); 13 | cin.tie(0); 14 | 15 | int N, Q; cin >> N >> Q; 16 | for(int i=1;i<=N;i++){ 17 | string s; cin >> s; 18 | string idx = to_string(i); 19 | pokemon[s] = idx; 20 | pokemonSeq[idx] = s; 21 | } 22 | 23 | while(Q--) { 24 | string s; cin >> s; 25 | if(isdigit(s[0])) { 26 | cout << pokemonSeq[s] << '\n'; 27 | } 28 | else { 29 | cout << pokemon[s] << '\n'; 30 | } 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /solutions/baekjoon/16208/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/e75629ad3348460599c12c53f64b7062 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | N = int(input()) 9 | arr = list(map(int, input().split())) 10 | arr.sort() 11 | len = sum(arr) 12 | total = 0 13 | for i in arr: 14 | len = len - i 15 | total += i * len 16 | print(total) -------------------------------------------------------------------------------- /solutions/baekjoon/16435/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/ee8c8ce8f36344348accd5605c2aba66 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, L = map(int, input().split()) 10 | arr = list(map(int, input().split())) 11 | arr.sort() 12 | 13 | for i in arr: 14 | if L >= i: 15 | L += 1 16 | print(L) 17 | -------------------------------------------------------------------------------- /solutions/baekjoon/16439/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/e9a6c4d2144e4f7db1fd8ab2bfd14058 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[33][33]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N, M; cin >> N >> M; 15 | for(int i=0;i> arr[i][j]; 16 | int answer = 0; 17 | for(int i=0;i 5 | 6 | using namespace std; 7 | 8 | int uf[1000005]; 9 | 10 | int find(int x) { 11 | if(uf[x] < 0) return x; 12 | return uf[x] = find(uf[x]); 13 | } 14 | 15 | bool merge(int a, int b) { 16 | a = find(a); 17 | b = find(b); 18 | if(a == b)return false; 19 | uf[b] = a; 20 | return true; 21 | } 22 | 23 | int main(){ 24 | ios::sync_with_stdio(false); 25 | cin.tie(0); 26 | 27 | int N, M; cin >> N >> M; 28 | for(int i=0;i<=N;i++) uf[i] = -1; 29 | for(int i=0;i> t >> a >> b; 31 | if(t == 1) { 32 | if(find(a) == find(b)) cout << "YES\n"; 33 | else cout << "NO\n"; 34 | } 35 | else merge(a, b); 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /solutions/baekjoon/17413/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/fe8c559fa57643e4a5b072a35a619f89 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | string s; 13 | getline(cin, s); 14 | int n = s.size(); 15 | 16 | for(int i=0;i 5 | 6 | using namespace std; 7 | 8 | bool isPrime(int x) { 9 | if(x <= 1) return false; 10 | for(int i=2;i*i<=x;i++){ 11 | if(x % i == 0) return false; 12 | } 13 | return true; 14 | } 15 | 16 | bool isPalindrome(int x) { 17 | int origin = x; 18 | int rev = 0; 19 | while(x) { 20 | rev = rev * 10 + x % 10; 21 | x /= 10; 22 | } 23 | return origin == rev; 24 | } 25 | 26 | int main(){ 27 | ios::sync_with_stdio(false); 28 | cin.tie(0); 29 | 30 | int n; cin >> n; 31 | while(true) { 32 | if(isPalindrome(n) && isPrime(n)) break; 33 | n ++; 34 | } 35 | cout << n; 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /solutions/baekjoon/17485/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : yj2221 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/1b3b764580774cf799a9a9606d12fec0 4 | 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | INF = 99999999 10 | n, m = map(int,input().split()) 11 | board = [list(map(int,input().split())) for i in range(n)] 12 | dp = [[[INF] * m for _ in range(n)] for _ in range(3)] 13 | 14 | for i in range(m): 15 | dp[0][0][i] = board[0][i] 16 | dp[1][0][i] = board[0][i] 17 | dp[2][0][i] = board[0][i] 18 | 19 | for i in range(1, n): 20 | for j in range(m): 21 | dp[0][i][j] = min(dp[1][i-1][j], dp[2][i-1][j]) + board[i][j] 22 | if j!=m-1: 23 | dp[1][i][j] = min(dp[0][i-1][j+1], dp[2][i-1][j+1]) + board[i][j] 24 | if j!=0: 25 | dp[2][i][j] = min(dp[1][i-1][j-1], dp[0][i-1][j-1]) + board[i][j] 26 | 27 | print(min(min(dp[0][n-1]),min(dp[1][n-1]), min(dp[2][n-1]))) 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/1749/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/67eb3ee9ba7649f29c3542bb2b034e08 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[222][222]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N, M; cin >> N >> M; 15 | for(int i=1;i<=N;i++) { 16 | for(int j=1;j<=M;j++) { 17 | cin >> arr[i][j]; 18 | arr[i][j] += arr[i-1][j]; 19 | } 20 | } 21 | 22 | int answer = INT_MIN; 23 | for(int i=1;i<=N;i++){ 24 | for(int j=i;j<=N;j++) { 25 | int sum = 0; 26 | for(int k=1;k<=M;k++){ 27 | int cur = arr[j][k] - arr[i - 1][k]; 28 | sum += cur; 29 | if(sum < cur) sum = cur; 30 | answer = max(answer, sum); 31 | } 32 | } 33 | } 34 | cout << answer; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /solutions/baekjoon/1758/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/c3b5f907db554df093b6d9ea748fed35 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | arr = [] 12 | ans = 0 13 | for i in range(N): 14 | arr.append(int(input())) 15 | arr.sort(key = lambda x : -x) 16 | for i in range(len(arr)): 17 | tip = arr[i] - i 18 | if tip > 0: 19 | ans += tip 20 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/17609/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/35708a61bb1d4149952929e8154ba152 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def palin(start, end, del_cnt): 10 | if del_cnt == 2: 11 | return del_cnt 12 | while start <= end: 13 | if string[start] != string[end]: 14 | a = palin(start + 1, end, del_cnt + 1) 15 | b = palin(start, end - 1, del_cnt + 1) 16 | return a if a <= b else b 17 | start += 1 18 | end -= 1 19 | else: 20 | return del_cnt 21 | 22 | for T in range(int(input())): 23 | string = input() 24 | print(palin(0, len(string) - 1, 0)) 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/17614/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/d71c9ab9881a40b08b8854a9a888e74f 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | int ans = 0; 14 | for(int i = 1; i <= N; ++i) { 15 | int tmp = i; 16 | while(tmp) { 17 | int cur = tmp % 10; 18 | if(cur != 0 && cur % 3 == 0) ++ ans; 19 | tmp /= 10; 20 | } 21 | } 22 | cout << ans; 23 | 24 | return 0; 25 | } 26 | 27 | /* Solution Description 28 | 주어진대로 구현하면 되는 문제. 29 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/17626/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/816fdae98bec4a4f95a3fb44fd2f348f 4 | import sys 5 | from math import sqrt 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def solve(N): 11 | ret = 4 12 | for a in range(1, sqrtN + 1): 13 | if a * a == N: 14 | ret = 1 15 | 16 | if ret == 1: 17 | break 18 | for b in range(1, sqrtN + 1): 19 | if a * a + b * b > N: 20 | break 21 | if a * a + b * b == N: 22 | ret = 2 23 | 24 | if ret <= 2: 25 | break 26 | for c in range(1, sqrtN + 1): 27 | if a * a + b * b + c * c > N: 28 | break 29 | if a * a + b * b + c * c == N: 30 | ret = 3 31 | break 32 | 33 | return ret 34 | 35 | N = int(input()) 36 | sqrtN = int(sqrt(N)) 37 | print(solve(N)) 38 | -------------------------------------------------------------------------------- /solutions/baekjoon/1789/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/b757695822a7451ca902c666e024bb5f 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | ll S; 10 | bool chk(ll n){ return n*(n+1)/2 > S; } 11 | 12 | int main(){ 13 | ios::sync_with_stdio(false); 14 | cin.tie(0); 15 | cin >> S; 16 | ll l = 1, r = 93000; // sqrt(4294967295 * 2) 17 | while(l <= r){ 18 | ll mid = (l + r) / 2; 19 | if(chk(mid))r = mid - 1; 20 | else l = mid + 1; 21 | } 22 | cout << r; 23 | } 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/1802/main.py: -------------------------------------------------------------------------------- 1 | # // Authored by : chj3748 2 | # // Co-authored by : - 3 | # // Link : http://boj.kr/28603d67d3014c79af724768c75865af 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def origami(start, end): 10 | if start == end: 11 | return True 12 | mid = (start + end) // 2 13 | sign = True 14 | for i in range(start,mid): 15 | if status[i] == status[end-i]: 16 | sign = False 17 | break 18 | if sign: 19 | return origami(start, mid - 1) and origami(mid + 1, end) 20 | else: 21 | return False 22 | 23 | for T in range(int(input())): 24 | status = list(map(int, input())) 25 | if origami(0, len(status) - 1): 26 | answer = 'YES' 27 | else: 28 | answer = 'NO' 29 | print(answer) -------------------------------------------------------------------------------- /solutions/baekjoon/1806/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/a020564994b8493a92b189861e35636c 4 | 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | n, s = map(int, input().split()) 10 | lst = list(map(int, input().split())) 11 | 12 | l_p, r_p, cur_sum, min_len = 0, 0, 0, 100002 13 | # cur_sum에 저장되는 구간합: sum(lst[l_p:r_p]) 14 | 15 | while l_p < n: 16 | if cur_sum >= s: # 현재 구간이 주어진 s보다 크다면 17 | min_len = min(min_len, r_p-l_p) #현재 구간 길이(r_p-l_p)가 최소라면 업데이트 18 | cur_sum -= lst[l_p] #왼쪽 포인터를 한 칸 오른쪽으로 옮기고 구간 합 업데이트 19 | l_p += 1 20 | 21 | elif r_p == n: #오른쪽 끝에 도달했다면? 22 | break 23 | 24 | else: 25 | cur_sum += lst[r_p] #오른쪽 구간을 움직여서 구간 합 업데이트 26 | r_p += 1 27 | 28 | print(min_len if min_len < 100001 else 0) 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/18115/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : r4pidstart 2 | // Co-authored by : - 3 | // Link : https://www.acmicpc.net/source/share/380f9c5d8ce848cf972fc30b9c8eaa93 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(false); cin.tie(nullptr); 9 | int n; cin >> n; 10 | 11 | vector cmd(n); 12 | for(int i=0; i> cmd[i]; 13 | 14 | // 앞에서도, 뒤에서도 카드를 다루기에 덱이 적합하다 15 | deque dq; 16 | 17 | // 마지막으로 내려놓은 카드부터, 차례대로 처리한다 18 | for(int i=n-1; i>=0; i--){ 19 | // i번째에 내려놓은 카드는 n-i번 카드이다. 20 | if(cmd[i] == 1) dq.push_front(n-i); 21 | else if(cmd[i] == 2) dq.insert(dq.begin()+1, n-i); 22 | else dq.push_back(n-i); // if(cmd[1] == 3) 23 | } 24 | 25 | // dq에 정리된 카드를 순서대로 출력한다 26 | for(auto i : dq) cout << i << ' '; 27 | } 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/1817/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/b60f3d6809514134b0740ee31eeb763a 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N, M = map(int, input().split()) 11 | ans = 0 12 | if N == 0: 13 | print(ans) 14 | else: 15 | queue = deque(list(map(int, input().split()))) 16 | while queue: 17 | weight = 0 18 | while queue and weight + queue[0] <= M: 19 | weight += queue.popleft() 20 | ans += 1 21 | print(ans) 22 | -------------------------------------------------------------------------------- /solutions/baekjoon/18222/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/9573c1f4e8924a1b8f19ce128d132a68 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | int main(){ 10 | ios::sync_with_stdio(false); 11 | cin.tie(0); 12 | 13 | ll N; cin >> N; 14 | ll cnt = 0; 15 | while(N){ 16 | ll cur = 1; 17 | while(cur * 2 < N) cur <<= 1; 18 | N -= cur; 19 | cnt ++; 20 | } 21 | ll ans = ~cnt & 1; 22 | cout << ans; 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/18258/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/6bf4491116ff480fab750a65591c134e 4 | 5 | import sys 6 | from collections import deque 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | queue = deque() 11 | N = int(input()) 12 | for i in range(N): 13 | com = input().split() 14 | if com[0] == 'push': 15 | queue.append(com[1]) 16 | elif com[0] == 'pop': 17 | if queue: 18 | print(queue.popleft()) 19 | else: 20 | print(-1) 21 | elif com[0] == 'size': 22 | print(len(queue)) 23 | elif com[0] == 'front': 24 | if queue: 25 | print(queue[0]) 26 | else: 27 | print(-1) 28 | elif com[0] == 'back': 29 | if queue: 30 | print(queue[-1]) 31 | else: 32 | print(-1) 33 | elif com[0] == 'empty': 34 | if not queue: 35 | print(1) 36 | else: 37 | print(0) -------------------------------------------------------------------------------- /solutions/baekjoon/18312/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/a1f005e8ee00409590b55623b8057ff0 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool chk(int a, int b) { 9 | for(int i=0;i<2;i++) { 10 | if(a % 10 == b) return true; 11 | a /= 10; 12 | } 13 | return false; 14 | } 15 | 16 | int main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int N, K; cin >> N >> K; 21 | int answer = 0; 22 | for(int i=0;i<(N+1)*3600;i++) { 23 | int hh = i / 3600; 24 | int mm = i / 60 % 60; 25 | int ss = i % 60; 26 | if(chk(hh, K) || chk(mm, K) || chk(ss, K)) answer++; 27 | } 28 | cout << answer; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /solutions/baekjoon/18427/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : yj2221 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/069cb935ee08462280976f02691b40ca 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N, M, H = map(int, input().split()) 11 | 12 | students = [] 13 | for _ in range(N): 14 | students.append(list(map(int, input().split()))) 15 | 16 | dp = [1] + [0] * (H+1) 17 | 18 | for i in range(N): 19 | for j in range(H, -1, -1): 20 | for k in students[i]: 21 | if j - k >= 0: 22 | dp[j] = (dp[j] + dp[j - k]) % 10007 23 | 24 | print(dp[H]) 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/18511/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/b56f91d1e33b44c2b24d57cd460eace2 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def backTracking(num): 10 | global ans 11 | if num > N: 12 | return 13 | ans = max(ans,num) 14 | for i in K: 15 | num = num * 10 + i 16 | backTracking(num) 17 | num = (num - i) // 10 18 | 19 | N, C = map(int, input().split()) 20 | K = list(map(int, input().split())) 21 | ans = 0 22 | backTracking(0) 23 | print(ans) 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/1890/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/73b9e168131842dd90aa2b02380cb0fa 4 | 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | n = int(input()) 10 | lst = [] 11 | for _ in range(n): 12 | lst.append(list(map(int, input().split()))) 13 | 14 | dp = [[0]*n for _ in range(n)] 15 | dp[0][0] = 1 16 | 17 | for i in range(n): 18 | for j in range(n): 19 | if lst[i][j] == 0: 20 | continue 21 | jump = lst[j][i] 22 | 23 | if j+jump < n: 24 | dp[j+jump][i] += dp[j][i] 25 | if i+jump < n: 26 | dp[j][i+jump] += dp[j][i] 27 | 28 | print(dp[-1][-1]) 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/1920/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/ecf2284ada79472da95d933e310ca959 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | vector V(N); 14 | for(auto &i: V) cin >> i; 15 | sort(V.begin(), V.end()); 16 | int Q; cin >> Q; 17 | for(int i=0;i> x; 19 | if(binary_search(V.begin(), V.end(), x)) cout << 1 << '\n'; 20 | else cout << 0 << '\n'; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/1922/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/e8d47d936e104388916666605df5778d 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def union(x, y): 11 | x = find_parent(x) 12 | y = find_parent(y) 13 | if x < y: 14 | parent[y] = x 15 | else: 16 | parent[x] = y 17 | 18 | def find_parent(x): 19 | if x != parent[x]: 20 | parent[x] = find_parent(parent[x]) 21 | return parent[x] 22 | 23 | N = int(input()) 24 | M = int(input()) 25 | parent = [i for i in range(N+1)] 26 | arr = [] 27 | ans = 0 28 | for i in range(M): 29 | arr.append(list(map(int, input().split()))) 30 | arr.sort(key = lambda x : x[2]) 31 | for i in range(M): 32 | if find_parent(arr[i][0]) != find_parent(arr[i][1]): 33 | union(arr[i][0], arr[i][1]) 34 | ans += arr[i][2] 35 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/1927/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/5d73f6bad59b42a58688435c855b9580 4 | import sys 5 | import heapq 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | heap = [] 12 | 13 | for i in range(N): 14 | x = int(input()) 15 | if x == 0: 16 | if not heap: 17 | print(0) 18 | else: 19 | print(heapq.heappop(heap)) 20 | else: 21 | heapq.heappush(heap,x) 22 | -------------------------------------------------------------------------------- /solutions/baekjoon/1931/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/7150be3ff485402ebb4c5011fa88ac7d 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | arr = [] 11 | total = 1 12 | 13 | for i in range(N): 14 | a,b = map(int, input().split()) 15 | arr.append((a,b)) 16 | 17 | arr.sort(key = lambda x : (x[1],x[0])) 18 | end_time = arr[0][1] 19 | 20 | for i in range(1,N): 21 | if arr[i][0] >= end_time: 22 | end_time = arr[i][1] 23 | total += 1 24 | 25 | print(total) -------------------------------------------------------------------------------- /solutions/baekjoon/1934/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/ad01b7a316c54d36b65058fd4909173b 4 | #include 5 | 6 | using namespace std; 7 | 8 | int gcd(int a, int b) { 9 | if(b == 0)return a; 10 | return gcd(b, a % b); 11 | } 12 | int lcm(int a, int b) { 13 | return a / gcd(a, b) * b; 14 | } 15 | 16 | int main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int t; cin >> t; 21 | while(t--){ 22 | int a, b; cin >> a >> b; 23 | cout << lcm(a, b) << '\n'; 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/1940/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/901436e12d914d5e9effcd67494bbb44 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | M = int(input()) 12 | arr = list(map(int, input().split())) 13 | arr.sort() 14 | ans = 0 15 | s, e = 0, len(arr) - 1 16 | while s < e: 17 | if arr[s] + arr[e] > M: 18 | e -= 1 19 | elif arr[s] + arr[e] < M: 20 | s += 1 21 | else: 22 | s += 1 23 | e -= 1 24 | ans += 1 25 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/1949/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/627e3feffb1842298d6d7ce3093e807b 4 | #include 5 | 6 | using namespace std; 7 | 8 | const int MAXN = 10005; 9 | vector graph[MAXN]; 10 | int cost[MAXN], DP[MAXN][2]; 11 | 12 | void dfs(int cur, int prv) { 13 | for(auto &nxt: graph[cur]) { 14 | if(nxt == prv) continue; 15 | dfs(nxt, cur); 16 | DP[cur][0] += max(DP[nxt][0], DP[nxt][1]); 17 | DP[cur][1] += DP[nxt][0]; 18 | } 19 | DP[cur][1] += cost[cur]; 20 | } 21 | 22 | int main(){ 23 | ios::sync_with_stdio(false); 24 | cin.tie(0); 25 | 26 | int n; cin >> n; 27 | for(int i=1;i<=n;i++) cin >> cost[i]; 28 | for(int i=1;i< n;i++) { 29 | int a, b; cin >> a >> b; 30 | graph[a].push_back(b); 31 | graph[b].push_back(a); 32 | } 33 | 34 | dfs(1, 1); 35 | cout << max(DP[1][0], DP[1][1]) << '\n'; 36 | 37 | return 0; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /solutions/baekjoon/19532/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/605780919d644059a745b5ae43d221be 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | vector V(6); 13 | for(int i=0;i<6;i++) cin >> V[i]; 14 | 15 | for(int x = -1000; x <= 1000; x++) { 16 | for(int y = -1000; y <= 1000; y++) { 17 | int F = V[0] * x + V[1] * y - V[2]; 18 | int S = V[3] * x + V[4] * y - V[5]; 19 | if(F == 0 && S == 0) { 20 | cout << x << ' ' << y; 21 | return 0; 22 | } 23 | } 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/19598/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/2b9516c8789c4a42849250efcef845c7 4 | import heapq 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | n = int(input()) 10 | lst = sorted([list(map(int, input().split())) for _ in range(n)]) 11 | heap = [lst[0][1]] 12 | for i in range(1, n): 13 | if heap[0] > lst[i][0]: # 새로운 회의실 필요 14 | heapq.heappush(heap, lst[i][1]) 15 | else: # 기존 회의실 이어서 사용 가능 16 | heapq.heappop(heap) 17 | heapq.heappush(heap, lst[i][1]) 18 | 19 | print(len(heap)) -------------------------------------------------------------------------------- /solutions/baekjoon/19622/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/25c02a4ea33e493f9f1320165f1a5f95 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | meetings = [] 11 | for _ in range(N): 12 | meetings.append(list(map(int, input().split()))) 13 | dp = [0] * N 14 | 15 | for i in range(N): 16 | if i == 0: 17 | dp[0] = meetings[0][2] 18 | elif i == 1: 19 | dp[1] = max(meetings[1][2], dp[0]) 20 | else: 21 | dp[i] = max(dp[i-2] + meetings[i][2], dp[i-1]) 22 | 23 | print(dp[N - 1]) -------------------------------------------------------------------------------- /solutions/baekjoon/1966/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/74b1e7adb56b425aa6644b3d2ea726e0 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | T = int(input()) 11 | for i in range(T): 12 | queue = deque() 13 | queue2 = deque() 14 | ct = 1 15 | N,M = map(int, input().split()) 16 | arr = list(map(int, input().split())) 17 | for j in range(len(arr)): 18 | queue.append(arr[j]) 19 | queue2.append(j) 20 | while True: 21 | if queue[0] == max(queue): 22 | if queue2[0] == M: 23 | print(ct) 24 | break 25 | else: 26 | queue.popleft() 27 | queue2.popleft() 28 | ct += 1 29 | else: 30 | queue.rotate(-1) 31 | queue2.rotate(-1) -------------------------------------------------------------------------------- /solutions/baekjoon/1969/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/c08f03602f524dc3822344da70739929 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N, M = map(int, input().split()) 11 | arr = [] 12 | word = '' 13 | dist = 0 14 | 15 | for i in range(N): 16 | arr.append(input()) 17 | 18 | for i in range(M): 19 | dic = {} 20 | for j in range(N): 21 | if arr[j][i] not in dic: 22 | dic[arr[j][i]] = 1 23 | 24 | else: 25 | dic[arr[j][i]] += 1 26 | 27 | ans = list(dic.items()) 28 | ans.sort(key = lambda x : (-x[1], x[0])) 29 | word += ans[0][0] 30 | dist += N - ans[0][1] 31 | 32 | print(word) 33 | print(dist) -------------------------------------------------------------------------------- /solutions/baekjoon/1978/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/0b2168e810154d6e916497d012aa7daa 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool isPrime(int x) { 9 | if(x <= 1) return false; 10 | for(int i=2;i*i<=x;i++) { 11 | if(x % i == 0) return false; 12 | } 13 | return true; 14 | } 15 | 16 | int main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int n; cin >> n; 21 | int answer = 0; 22 | for(int i=0;i> x; 24 | if(isPrime(x)) answer ++; 25 | } 26 | cout << answer; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/1978/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/fba2f023d5c346aa826b3c6922fb0a27 4 | import sys 5 | from math import sqrt 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | prime = [1] * 1005 11 | prime[0] = 0 12 | prime[1] = 0 13 | ct = 0 14 | N = int(input()) 15 | arr = list(map(int, input().split())) 16 | for i in range(2, int(sqrt(1005))+1): 17 | for j in range(i+i, 1005, i): 18 | if prime[j] == 1: 19 | prime[j] = 0 20 | for i in arr: 21 | if prime[i]: 22 | ct += 1 23 | print(ct) 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/1992/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/f4a1319fd1af4655b19f5c7cd7872b92 4 | #include 5 | 6 | using namespace std; 7 | 8 | char arr[66][66]; 9 | string answer; 10 | 11 | void solve(int y, int x, int s) { 12 | bool flag = true; 13 | for(int i=0;i> N; 35 | for(int i=0;i> arr[i]; 36 | solve(0, 0, N); 37 | cout << answer; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /solutions/baekjoon/20053/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/ea1f7df70f5449f18d7cd9dc06640bb7 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int t; cin >> t; 13 | while(t--){ 14 | int n; cin >> n; 15 | int max_value = -1000001, min_value = 1000001; 16 | for(int i=0;i> x; 18 | if(max_value < x) max_value = x; 19 | if(min_value > x) min_value = x; 20 | } 21 | cout << min_value << ' ' << max_value << '\n'; 22 | } 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/20115/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/cd5989ea170a46c9aba0b049b70f4ee6 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | arr = list(map(int, input().split())) 12 | arr.sort() 13 | for i in range(len(arr)-1): 14 | arr[-1] += arr[i] / 2 15 | print(arr[-1]) -------------------------------------------------------------------------------- /solutions/baekjoon/2015/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/d46daeae8c194cb080f41f07b383b113 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | unordered_map mp; 10 | ll prefix[200002]; 11 | 12 | int main(){ 13 | ios::sync_with_stdio(false); 14 | cin.tie(0); 15 | 16 | ll N, K; cin >> N >> K; 17 | ll answer = 0; 18 | for(int i=1;i<=N;i++) { 19 | cin >> prefix[i]; 20 | prefix[i] += prefix[i - 1]; 21 | 22 | if(prefix[i] == K) answer ++; 23 | 24 | if(mp.count(prefix[i] - K)) answer += mp[prefix[i] - K]; 25 | mp[prefix[i]] ++; 26 | } 27 | cout << answer; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/2015/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/c3cc5338e8fa49ae8136e4af174221df 4 | from collections import defaultdict 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | n, k = map(int, input().split()) 10 | lst = list(map(int, input().split())) 11 | dic = defaultdict(int) # 어떤 값이 기존에 몇 번 나왔는지 저장 12 | 13 | for i in range(1, n): lst[i] += lst[i-1] # 누적합 inplace로 만들기 14 | 15 | cnt = 0 16 | for num in lst: 17 | if num == k: cnt += 1 # 1부터 더한 값 중 k 있으면 cnt += 1 18 | # O(n) 연산 대신 dictionary에서 찾는 것으로 시간 단축 19 | cnt += dic[num-k] # 이미 본 누적합 값과 num으로 k 만들 수 있으면 추가 20 | dic[num] += 1 # num 만들 수 있는 개수 +1 21 | 22 | print(cnt) -------------------------------------------------------------------------------- /solutions/baekjoon/20154/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/ff79a90b0e024c4eb328a8595918b096 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | DB = [3, 2, 1, 2, 3, 3, 3, 3, 1, 1, 3, 1, 3, 3, 1, 2, 2, 2, 1, 2, 1, 1, 2, 2, 2, 1] 10 | dic = {} 11 | for idx, data in enumerate(DB): 12 | dic[chr(idx+65)] = DB[idx] # 'A' : 65 13 | 14 | total = 0 15 | a = input() 16 | for i in a: 17 | total += dic[i] 18 | total = total % 10 19 | if total % 2 == 1: 20 | print("I'm a winner!") 21 | else: 22 | print("You're the winner?") 23 | -------------------------------------------------------------------------------- /solutions/baekjoon/2018/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/2b640a2f6eb74e08aae6e351cfcbf537 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | arr = [i for i in range(1, N+1)] 12 | s, e = 0, 0 13 | ans = 0 14 | total = 0 15 | while True: 16 | if total < N: 17 | total += arr[e] 18 | e += 1 19 | elif e == len(arr): 20 | break 21 | elif total >= N: 22 | if total == N: 23 | ans += 1 24 | total -= arr[s] 25 | s += 1 26 | print(ans+1) -------------------------------------------------------------------------------- /solutions/baekjoon/20207/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/495000f668564c6c9a71fa59b0380aae 4 | #include 5 | 6 | using namespace std; 7 | int prefix[444]; 8 | 9 | int main(){ 10 | ios::sync_with_stdio(false); cin.tie(0); 11 | 12 | int n; cin >> n; 13 | for(int i=1;i<=n;i++){ 14 | int a, b; cin >> a >> b; 15 | prefix[a]++; prefix[b+1]--; 16 | } 17 | int mx = 0, ans = 0, prv = -1; 18 | for(int i=1;i<=366;i++){ 19 | prefix[i]+=prefix[i-1]; 20 | mx=max(mx,prefix[i]); 21 | if(!prefix[i]){ 22 | ans += (i - prv) * mx; 23 | mx = 0; prv = -1; 24 | } 25 | else if(!~prv)prv = i; 26 | } 27 | cout << ans; 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/20291/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/76369f4f8225439084adb5f553cecae8 4 | #include 5 | 6 | using namespace std; 7 | 8 | vector file; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int n; cin >> n; 15 | for(int i=0;i> s; 17 | file.emplace_back(s.substr(s.find(".") + 1)); 18 | } 19 | sort(file.begin(), file.end()); 20 | for(int i=0;i 5 | using namespace std; 6 | typedef long long ll; 7 | 8 | int n; 9 | ll arr[10005]; 10 | ll ans = 0; 11 | 12 | int main() { 13 | ios::sync_with_stdio(false); 14 | cin.tie(nullptr); 15 | cout.tie(nullptr); 16 | 17 | cin >> n; 18 | for (int i = 0; i < n; i++) { 19 | cin >> arr[i]; 20 | } 21 | sort(arr, arr + n); 22 | //최대 원소와 최소 원소가 합쳐지는 게 근손실이 최소이다 23 | if (n % 2 == 0) { 24 | for (int i = 0; i < n / 2; i++) { 25 | ans = max(ans, arr[i] + arr[n - i - 1]); 26 | } 27 | } 28 | //홀수일 때는 마지막 하나의 운동기구가 남는다 29 | else { 30 | for (int i = 0; i < n / 2; i++) { 31 | ans = max(ans, arr[i] + arr[n - i - 2]); 32 | } 33 | ans = max(ans, arr[n - 1]); 34 | } 35 | cout << ans << "\n"; 36 | 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /solutions/baekjoon/20365/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : dart 2 | // Co-authored by : - 3 | // Link : http://boj.kr/50c45e2707d946d98571bbeb52348d60 4 | #include 5 | using namespace std; 6 | typedef long long ll; 7 | 8 | int n; 9 | string word; 10 | int red = 0, blue = 0; 11 | 12 | int main() { 13 | ios::sync_with_stdio(false); 14 | cin.tie(nullptr); 15 | cout.tie(nullptr); 16 | 17 | cin >> n >> word; 18 | 19 | for (int i = 0; i < n; i++) { 20 | if (i == 0) { 21 | if (word[i] == 'B') { blue++; } 22 | if (word[i] == 'R') { red++; } 23 | } 24 | else { 25 | if (word[i] == 'B' && word[i - 1] == 'R') { blue++; } 26 | if (word[i] == 'R' && word[i - 1] == 'B') { red++; } 27 | } 28 | } 29 | cout << min(red, blue) + 1 << "\n"; 30 | 31 | 32 | return 0; 33 | } -------------------------------------------------------------------------------- /solutions/baekjoon/20438/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/2d250c49804d4fb6a38cbe6e752cd87d 4 | #include 5 | 6 | using namespace std; 7 | 8 | int prefix[5050], sleep[5050], used[5050]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N, K, Q, M; cin >> N >> K >> Q >> M; 15 | for(int i=1;i<=K;i++) { 16 | int x;cin >> x; 17 | sleep[x] = 1; 18 | } 19 | for(int i=1;i<=Q;i++) { 20 | int x;cin >> x; 21 | if(sleep[x]) continue; 22 | for(int j=x;j<=N+2;j+=x) { 23 | if(sleep[j]) continue; 24 | used[j] = 1; 25 | } 26 | } 27 | 28 | for(int i=3;i<=N+2;i++) { 29 | prefix[i] = prefix[i-1]; 30 | if(used[i] == 0) prefix[i] ++; 31 | } 32 | 33 | for(int i=1;i<=M;i++){ 34 | int L, R; cin >> L >> R; 35 | cout << prefix[R] - prefix[L - 1] << '\n'; 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /solutions/baekjoon/2075/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/9d0a68ae0d4349238f376383cbaf13e0 4 | #include 5 | 6 | using namespace std; 7 | 8 | priority_queue, greater> pq; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N; cin >> N; 15 | for(int i=0;i> x; 18 | pq.push(x); 19 | if((int)pq.size() > N) pq.pop(); 20 | } 21 | } 22 | cout << pq.top(); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /solutions/baekjoon/20922/main.cpp: -------------------------------------------------------------------------------- 1 | //Authored by : suin8 2 | //Co-authored by : tony9402 3 | //Link : http://boj.kr/bf868d6487744424a792c188673bf339 4 | 5 | #include 6 | 7 | using namespace std; 8 | 9 | int num[200010], cnt[100010]; 10 | 11 | int main() { 12 | ios::sync_with_stdio(false); 13 | cin.tie(nullptr); 14 | 15 | int N, K; cin >> N >> K; 16 | 17 | for(int i = 1;i <= N;i++) 18 | cin >> num[i]; 19 | 20 | // start와 end사이에 겹치는 수가 K개 이하일 때는 end를 늘리며 21 | // 최대 길이를 늘리고 22 | // K개 초과일 때는 begin를 늘리며 겹치는 수가 빠질때까지 begin을 증가 23 | int ans = 0; 24 | for(int begin = 1, end = 1; begin <= N; begin ++) { 25 | while(end <= N && cnt[num[end]] < K) ++cnt[num[end++]]; 26 | ans = max(ans, end - begin); 27 | cnt[num[begin]]--; 28 | } 29 | 30 | cout << ans; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /solutions/baekjoon/21312/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/327c054505c748d68ef1e3c46b855f7a 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int cnt[2] = {0, 0}; 13 | for(int i = 0; i < 3; ++i) { 14 | int x; cin >> x; 15 | if(cnt[x % 2] == 0) cnt[x % 2] = x; 16 | else cnt[x % 2] *= x; 17 | } 18 | if(cnt[1] != 0) cout << cnt[1]; 19 | else cout << cnt[0]; 20 | 21 | return 0; 22 | } 23 | 24 | /* Solution Description 25 | 홀수가 하나라도 있다면 홀수들의 곱을 출력하고 없다면 짝수들만 남아있는 경우이므로 짝수들의 곱을 출력하면 된다. 26 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/21312/main.py: -------------------------------------------------------------------------------- 1 | # // Authored by : chj3748 2 | # // Co-authored by : - 3 | # // Link : http://boj.kr/21536cc8d28a4570aca6c9b48fc41e26 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | odd_num = -1 11 | even_num = -1 12 | for number in map(int, input().split()): 13 | if number % 2: 14 | if odd_num == -1: 15 | odd_num = number 16 | else: 17 | odd_num *= number 18 | else: 19 | if even_num == -1: 20 | even_num = number 21 | else: 22 | even_num *= number 23 | if odd_num != -1: 24 | print(odd_num) 25 | else: 26 | print(even_num) 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/21317/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/7b74ffa836cb49029ffc4ee08767c9db 4 | #include 5 | 6 | using namespace std; 7 | 8 | int DP[105][2], arr[105][2]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N; cin >> N; 15 | for(int i=1;i> arr[i][0] >> arr[i][1]; 16 | int k; cin >> k; 17 | for(int i=2;i<105;i++) DP[i][0] = DP[i][1] = INT_MAX; 18 | for(int i=1;i 5 | 6 | using namespace std; 7 | 8 | int arr[100005], prefix[100005]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N; cin >> N; 15 | for(int i=1;i<=N;i++) cin >> arr[i]; 16 | for(int i=1;i<=N;i++) { 17 | if(arr[i] > arr[i + 1]) prefix[i] = 1; 18 | prefix[i] += prefix[i - 1]; 19 | } 20 | 21 | int Q; cin >> Q; 22 | while(Q--){ 23 | int x, y; cin >> x >> y; 24 | --x; --y; 25 | cout << prefix[y] - prefix[x] << '\n'; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/2141/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/8be8b254ebe24830805a22953bdb3fcc 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | n = int(input()) 9 | lst = [list(map(int, input().split())) for _ in range(n)] 10 | lst.sort() # 마을 위치 따라 먼저 정렬 11 | 12 | dist = 0 13 | r_man, l_man = 0, 0 14 | for i in range(n): 15 | tmp = lst[i][0] - lst[0][0] 16 | dist += tmp*lst[i][1] # (최초 마을 ~ i번째 마을 거리) * 사람 수 17 | r_man += lst[i][1] #현재 위치보다 오른똑에 있는 사람 수 18 | 19 | min_dist = dist 20 | sol = lst[0][0] 21 | for i in range(1, n): 22 | tmp = lst[i][0] - lst[i-1][0] 23 | l_man += lst[i-1][1] # 이동 시 왼쪽에 있게 될 사람 추가 24 | r_man -= lst[i-1][1] # 이동 시 더 이상 오른쪽에 있지 않는 사람 제거 25 | dist = dist + (l_man - r_man)*tmp # 거리 계산 26 | 27 | if min_dist > dist: #업데이트 28 | min_dist = dist 29 | sol = lst[i][0] 30 | 31 | print(sol) 32 | -------------------------------------------------------------------------------- /solutions/baekjoon/2156/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : ccocco0609 2 | // Co-authored by : - 3 | // Link : http://boj.kr/1a58200da0374f249178f1d258ff4c90 4 | #include 5 | using namespace std; 6 | 7 | // 전역에 배열 또는 변수를 선언한 경우 0으로 초기화 됩니다. 8 | int wine[10001]; 9 | int dp[10001]; 10 | 11 | int main() { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(NULL); 14 | cout.tie(NULL); 15 | 16 | int N; cin >> N; 17 | 18 | for (int i = 1; i <= N; i++) cin >> wine[i]; 19 | 20 | dp[1] = wine[1]; 21 | dp[2] = wine[1] + wine[2]; 22 | for (int i = 3; i <= N; i++) { 23 | dp[i] = max(wine[i] + dp[i - 2], max(wine[i] + wine[i - 1] + dp[i - 3], dp[i - 1])); 24 | } 25 | 26 | cout << dp[N]; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/2156/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : wassup37 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/1211037748274f97ae2a8a24c4f0ec9e 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | N = int(input()) 9 | wine = [0] + [int(input()) for i in range(N)] # 인덱스가 1부터 시작하도록 만듭니다. 10 | 11 | if N == 1: # n이 1일 경우 맨 처음 포도주를 마시는게 최대입니다. 12 | print(wine[1]) 13 | else: 14 | dp = [0, wine[1], wine[1] + wine[2]] # n 인덱스까지의 최댓값을 저장하는 리스트 15 | for i in range(3, N+1): # 3부터 n까지 dp 테이블을 채웁니다. 16 | dp.append(max(dp[i - 1], dp[i - 2] + wine[i], dp[i - 3] + wine[i - 1] + wine[i])) 17 | print(dp[N]) # 포도주 잔의 개수가 n개일 때, 최대로 마실 수 있는 포도주의 양 출력 18 | -------------------------------------------------------------------------------- /solutions/baekjoon/2164/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/cb5c5740111745b0b9f0fb6582da5bdd 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | queue Q; 14 | for(int i=1;i<=N;i++) Q.push(i); 15 | while((int)Q.size() > 1) { 16 | Q.pop(); 17 | Q.push(Q.front()); 18 | Q.pop(); 19 | } 20 | cout << Q.front(); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/2164/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/3ad1b45ad3db4bf7b1bfc5227e1acd12 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | queue = deque() 11 | N = int(input()) 12 | for i in range(1,N+1): 13 | queue.append(i) 14 | 15 | while True: 16 | a = queue.popleft() 17 | if not queue: 18 | print(a) 19 | break 20 | b = queue.popleft() 21 | queue.append(b) -------------------------------------------------------------------------------- /solutions/baekjoon/2167/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/5182387e6c9745238986dcbe9231c45d 4 | #include 5 | 6 | using namespace std; 7 | int prefix[303][303]; 8 | 9 | int main(){ 10 | ios::sync_with_stdio(false); 11 | cin.tie(0); 12 | 13 | int N, M; cin >> N >> M; 14 | for(int i=1;i<=N;i++) { 15 | for(int j=1;j<=M;j++) { 16 | cin >> prefix[i][j]; 17 | prefix[i][j] = prefix[i][j] + prefix[i-1][j] + prefix[i][j-1] - prefix[i-1][j-1]; 18 | } 19 | } 20 | int Q; cin >> Q; 21 | while(Q--) { 22 | int a, b, c, d; cin >> a >> b >> c >> d; 23 | --a; -- b; 24 | cout << prefix[c][d] - prefix[a][d] - prefix[c][b] + prefix[a][b] << '\n'; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/21756/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/6fabfcca5d6b483c9f24b81bfabf2124 4 | #include 5 | 6 | using namespace std; 7 | 8 | int arr[105], tmp[105]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N; cin >> N; 15 | for(int i=1;i<=N;i++) arr[i] = i; 16 | 17 | while(N != 1) { 18 | int idx = 1; 19 | for(int i=2;i<=N;i+=2) tmp[idx++] = arr[i]; 20 | N = idx - 1; 21 | for(int i=1;i<=N;i++) arr[i] = tmp[i]; 22 | } 23 | cout << arr[1]; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/21758/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/ba24cf477f634be3b516d7475296bf67 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | const int MAXN = 100000; 10 | ll arr[MAXN + 5], prefix[MAXN + 5]; 11 | 12 | ll psum(int l, int r) { 13 | return prefix[r] - prefix[l - 1]; 14 | } 15 | 16 | int main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int N; cin >> N; 21 | for(int i = 1; i <= N; i++) { 22 | cin >> arr[i]; 23 | prefix[i] = prefix[i - 1] + arr[i]; 24 | } 25 | 26 | ll answer = 0; 27 | for(int i = 2; i < N; i++ ){ 28 | answer = max(answer, psum(2, i) + psum(i, N - 1)); 29 | answer = max(answer, psum(2, N) + psum(i + 1, N) - arr[i]); 30 | answer = max(answer, psum(1, N - 1) + psum(1, i - 1) - arr[i]); 31 | } 32 | cout << answer; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /solutions/baekjoon/21918/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/04ffe7467c0542c386a2ff3fc95f0b6b 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | arr = list(map(int, input().split())) 11 | 12 | for i in range(M): 13 | a,b,c = map(int, input().split()) 14 | 15 | if a == 1: 16 | arr[b-1] = c 17 | 18 | elif a == 2: 19 | for j in range(b-1,c): 20 | if arr[j] == 0: 21 | arr[j] = 1 22 | else: 23 | arr[j] = 0 24 | 25 | elif a == 3: 26 | for j in range(b-1,c): 27 | arr[j] = 0 28 | 29 | else: 30 | for j in range(b-1,c): 31 | arr[j] = 1 32 | 33 | print(*arr) -------------------------------------------------------------------------------- /solutions/baekjoon/21919/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/e59d5d5d486b44ba93000175e5118406 4 | import sys 5 | from math import sqrt 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def GCD(x,y): 11 | if y == 0: 12 | return x 13 | else: 14 | return GCD(y, x%y) 15 | 16 | arr = [0] * 1000003 17 | for i in range(2,int(sqrt(1000003))+1): 18 | for j in range(i+i, 1000003, i): 19 | if arr[j] == 0: 20 | arr[j] = 1 21 | arr[0] = 1 22 | arr[1] = 1 23 | LCM = 1 24 | N = int(input()) 25 | A = list(map(int, input().split())) 26 | ans = [] 27 | for i in A: 28 | if not arr[i]: 29 | ans.append(i) 30 | if not ans: 31 | print(-1) 32 | else: 33 | LCM = ans[0] 34 | for i in range(1,len(ans)): 35 | LCM = ans[i] * LCM // GCD(ans[i], LCM) 36 | print(LCM) -------------------------------------------------------------------------------- /solutions/baekjoon/21920/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/9824ccd807974698b94586b14edbb348 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def GCD(x,y): 10 | if y == 0: 11 | return x 12 | else: 13 | return GCD(y, x%y) 14 | 15 | N = int(input()) 16 | A = list(map(int, input().split())) 17 | X = int(input()) 18 | ans = [] 19 | for i in A: 20 | if GCD(X,i) == 1: 21 | ans.append(i) 22 | print(sum(ans)/len(ans)) 23 | -------------------------------------------------------------------------------- /solutions/baekjoon/2204/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/685c4c3dc1c24c118d3c89ffdefa6679 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | while True: 9 | n = int(input()) 10 | if n == 0: 11 | break 12 | arr = [] 13 | for i in range(n): 14 | a = input() 15 | a_lower = a.lower() 16 | arr.append((a,a_lower)) 17 | arr.sort(key = lambda x : x[1]) 18 | print(arr[0][0]) -------------------------------------------------------------------------------- /solutions/baekjoon/2212/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/015e042c8e6b4611891355efc3844453 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N, K; cin >> N >> K; 13 | vector arr(N), dis(N - 1); 14 | for(int i = 0; i < N; ++i) cin >> arr[i]; 15 | sort(arr.begin(), arr.end()); 16 | 17 | for(int i = 0; i < N - 1; ++i) { 18 | dis[i] = arr[i + 1] - arr[i]; 19 | } 20 | sort(dis.begin(), dis.end()); 21 | 22 | int ans = 0; 23 | for(int i = 0; i < N - K; ++i) { 24 | ans += dis[i]; 25 | } 26 | cout << ans; 27 | 28 | return 0; 29 | } 30 | 31 | /* Solution Description 32 | 센서들의 위치를 정렬한 후 사이의 거리들을 계산한다. 33 | K - 1개의 큰 값들은 집중국을 잘 세우면 커버할 수 있다. 34 | 즉, 거리의 차이에서 N - K개의 합을 더한 값이 집중국을 잘 세웠을 때 길이의 합의 최솟값이다. 35 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/2212/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/2b4e1797973e4e16a3b38ff778023e3e 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | n = int(input()) 9 | k = int(input()) 10 | lst = sorted(list(set(map(int, input().split())))) # 중복 제거 후 정렬 11 | distance = sorted([lst[i]-lst[i-1] for i in range(1, len(lst))]) # 센서 사이 거리 계산 후 정렬 12 | print(sum(distance[:(len(lst)-k)])) # 그리디하게 최장 거리 k개 제외한 게 정답 13 | -------------------------------------------------------------------------------- /solutions/baekjoon/2231/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/19379bdb38884854badc892db21a8d6b 4 | #include 5 | 6 | using namespace std; 7 | 8 | int cal(int x) { 9 | int tmp = x; 10 | while(x) { 11 | tmp += x % 10; 12 | x /= 10; 13 | } 14 | return tmp; 15 | } 16 | 17 | int main(){ 18 | ios::sync_with_stdio(false); 19 | cin.tie(0); 20 | 21 | int N; cin >> N; 22 | int cur = 1; 23 | while(cur < N + 100 && N != cal(cur)) cur++; 24 | if(cur == N + 100) cur = 0; 25 | cout << cur; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/22856/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/850a62c4f2e14d2d8c3214dbd97398e4 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | vector> tree(N + 1); 14 | for(int i = 1; i <= N; ++i) { 15 | int a, b, c; cin >> a >> b >> c; 16 | tree[a] = make_pair(b, c); 17 | } 18 | 19 | int ans = 2 * (N - 1); 20 | for(int cur = 1; tree[cur].second != -1; cur = tree[cur].second) { 21 | -- ans; 22 | } 23 | cout << ans; 24 | 25 | return 0; 26 | } 27 | 28 | /* Solution Description 29 | 잘 생각해보면 가장 루트에서 시작하여 가장 오른쪽으로 가는 경로를 제외하고는 2번 이동한다. 30 | 직접 유사 중위 순회를 구현해도 되지만, 잘 관찰을 하면 답은 2 * (N - 1) - (루트에서 시작해서 가장 오른쪽 노드까지 이동하는 횟수)가 되는 것을 알 수 있다. 31 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/22869/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : yj2221 2 | # Co-authored by : - 3 | # Link : http://boj.kr/18c501c01b3d4d91aa311c9c4d952e67 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | n, k = map(int, input().split()) 11 | rocks = list(map(int, input().split())) 12 | dp = [99999999] * n 13 | dp[0] = 0 14 | for i in range(n-1): 15 | if dp[i]>k: 16 | continue 17 | for j in range(i+1, n): 18 | need = (j-i) * (1 + abs(rocks[i]-rocks[j])) 19 | dp[j] = min(dp[j], need) 20 | 21 | if dp[n-1]>k: 22 | print('NO') 23 | else: 24 | print('YES') 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/2294/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/4c2449f200e440f39d4ba8e1e71601b6 4 | 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | n, k = map(int, input().split()) 10 | coin = set([int(input()) for _ in range(n)]) #중복 동전 제거 11 | dp = [0]*(k+1) 12 | 13 | for i in range(1, k+1): 14 | possible = [] 15 | for c in coin: 16 | if i-c >= 0 and dp[i-c] >= 0: # i-c원 경우에 c원 동전을 추가해서 i원을 만들 수 있는 경우 17 | possible.append(dp[i-c]) 18 | if possible: 19 | dp[i] = min(possible) + 1 # optimal 값 + 1 20 | else: 21 | dp[i] = -1 #불가능! 22 | 23 | print(dp[k]) 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/2309/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/be3b4fb036844cb390e1f7a818471cde 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def findIndex(ans): 11 | 12 | for i in range(9): 13 | for j in range(i+1,9): 14 | if arr[i] + arr[j] == ans: 15 | return (arr[i], arr[j]) 16 | 17 | arr = [] 18 | for i in range(9): 19 | arr.append(int(input())) 20 | 21 | ans = sum(arr) - 100 22 | first, second = findIndex(ans) 23 | arr.remove(first) 24 | arr.remove(second) 25 | arr.sort() 26 | 27 | for i in arr: 28 | print(i) -------------------------------------------------------------------------------- /solutions/baekjoon/2346/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/71af42c3664749e48f8f0272c3c04fd2 4 | import sys 5 | from collections import deque 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | queue = deque(list(map(int, input().split()))) 11 | queue2 = deque([i for i in range(1,N+1)]) 12 | while queue: 13 | q = queue[0] 14 | if q > 0: 15 | queue.popleft() 16 | queue.rotate(-q+1) 17 | print(queue2.popleft()) 18 | queue2.rotate(-q+1) 19 | else: 20 | queue.popleft() 21 | queue.rotate(-q) 22 | print(queue2.popleft()) 23 | queue2.rotate(-q) -------------------------------------------------------------------------------- /solutions/baekjoon/2417/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/dc2b68715aff442db67228432e9510ed 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | bool chk(ll a, ll b) { 10 | if(b % a == 0) return a >= b / a; 11 | return a > b / a; 12 | } 13 | 14 | int main(){ 15 | ios::sync_with_stdio(false); 16 | cin.tie(0); 17 | 18 | ll N; cin >> N; 19 | if(N == 0) { 20 | cout << 0; 21 | return 0; 22 | } 23 | ll L = 1, R = 1LL << 32; 24 | while(L <= R) { 25 | ll mid = L + (R - L) / 2; 26 | if(chk(mid, N)) R = mid - 1; 27 | else L = mid + 1; 28 | } 29 | cout << L; 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /solutions/baekjoon/2422/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/514a7a75b2eb4a2eaf862e8227682be7 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool chk[222][222]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int N, M; cin >> N >> M; 15 | for(int i=0;i> a >> b; 17 | chk[a][b] = chk[b][a] = true; 18 | } 19 | int answer = 0; 20 | for(int i=1;i<=N;i++) { 21 | for(int j=i+1;j<=N;j++) { 22 | for(int k=j+1;k<=N;k++) { 23 | if(chk[i][j] || chk[j][k] || chk[i][k])continue; 24 | answer++; 25 | } 26 | } 27 | } 28 | cout << answer; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /solutions/baekjoon/2438/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/9a6e490b384645388ae1aaefc4c04e8f 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | for(int i = 1; i <= N; ++i) { 14 | for(int j = 1; j <= i; ++j) { 15 | cout << "*"; 16 | } 17 | cout << "\n"; 18 | } 19 | 20 | return 0; 21 | } 22 | 23 | /* Solution Description 24 | i는 1부터 N까지 j는 1부터 i까지 중첩 반복문으로 풀면 되는 문제. 25 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/24499/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/68d9036a3cd94afd9f2c9d657301fff9 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N, K; cin >> N >> K; 13 | vector arr(2 * N + 1); 14 | vector prefix_sum(2 * N + 1); 15 | for(int i = 1; i <= N; ++i) { 16 | cin >> arr[i]; 17 | arr[i + N] = arr[i]; 18 | } 19 | for(int i = 1; i <= 2 * N; ++i) { 20 | prefix_sum[i] = prefix_sum[i - 1] + arr[i]; 21 | } 22 | 23 | int ans = 0; 24 | for(int i = 1; i <= N; ++i) { 25 | ans = max(ans, prefix_sum[i + K - 1] - prefix_sum[i - 1]); 26 | } 27 | cout << ans; 28 | 29 | return 0; 30 | } 31 | 32 | /* Solution Description 33 | 길이가 고정되어 있는 슬라이딩 윈도우 기법으로 최대값을 구할 수 있음. 34 | 원형으로 되어 있으니깐 하나의 일차원 배열을 두 개를 이어붙어서 보면 쉽게 볼 수 있음. 35 | 그리고 길이가 고정되어 있으므로 누적합을 계산해놓고 연속된 K개의 합이 최대인 값을 찾으면 됨. 36 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/2493/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/b2e3a3c79d3f4e219827c39174c3238f 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | stack> st; 14 | 15 | st.emplace(100000005, 0); 16 | for(int i=1;i<=N;i++) { 17 | int x; cin >> x; 18 | while(!st.empty() && st.top().first < x) st.pop(); 19 | cout << st.top().second << ' '; 20 | st.emplace(x, i); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/2512/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/7910ebb7f8ec409ba2e93cb14d047a19 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def binary_search(): 10 | start, end = 0, max(arr) 11 | while start <= end: 12 | mid = (start + end) // 2 13 | total = 0 14 | for i in arr: 15 | if mid < i: 16 | total += mid 17 | else: 18 | total += i 19 | if total <= M: 20 | start = mid + 1 21 | else: 22 | end = mid - 1 23 | return end 24 | 25 | N = int(input()) 26 | arr = list(map(int, input().split())) 27 | M = int(input()) 28 | print(binary_search()) 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/25214/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/d1c085db2c784030a0ea6e6c3b0b248f 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | int mn = INT_MAX, ans = 0; 14 | for(int i = 0; i < N; ++i) { 15 | int x; cin >> x; 16 | mn = min(mn, x); 17 | ans = max(ans, x - mn); 18 | cout << ans << ' '; 19 | } 20 | 21 | return 0; 22 | } 23 | 24 | /* Solution Description 25 | 현재까지 나온 값들 중 최솟값만 계속 들고 가면서 현재 값인 x - mn와 이전에 계산했던 최댓값 중 최댓값을 출력하면 되는 문제. 26 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/2559/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/1d6b566a715d4126b3cd42cc39521ac0 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N, K = map(int, input().split()) 11 | arr = list(map(int, input().split())) 12 | total = 0 13 | MAX = -1e9 14 | s, e = 0, K-1 15 | if K == 1: 16 | print(max(arr)) 17 | else: 18 | total = sum(arr[:K]) 19 | while True: 20 | MAX = max(MAX, total) 21 | total -= arr[s] 22 | s += 1 23 | e += 1 24 | if e == N: 25 | break 26 | total += arr[e] 27 | print(MAX) -------------------------------------------------------------------------------- /solutions/baekjoon/2579/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/3d9ff337b9bc420a975cf6783b298212 4 | 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | n = int(input()) 10 | lst = [int(input()) for _ in range(n)] 11 | 12 | if n > 3: 13 | dp = [lst[0], lst[0]+lst[1], max(lst[0], lst[1])+lst[2]] # 3번째 칸까지는 먼저 구하기 14 | for i in range(3, n): 15 | next_max = max(dp[i-2], dp[i-3]+lst[i-1]) # max(2칸 전에서 i번째 경우, 3칸-1칸 전 밟고 i번째 오는 경우) 16 | dp.append(next_max+lst[i]) 17 | print(dp[-1]) 18 | else: 19 | print(sum(lst)) #2칸 이하면 모두 밟는게 최대 20 | 21 | -------------------------------------------------------------------------------- /solutions/baekjoon/2581/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/f3c6407dc6ab4ad38ebb74b1ea3a9c8e 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool isPrime(int x) { 9 | if(x <= 1) return false; 10 | for(int i=2;i*i<=x;i++) { 11 | if(x % i == 0) return false; 12 | } 13 | return true; 14 | } 15 | 16 | int main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int sum = 0, minimum = 10001; 21 | int l, r; cin >> l >> r; 22 | for(int i=l;i<=r;i++){ 23 | if(isPrime(i)) { 24 | sum += i; 25 | minimum = min(minimum, i); 26 | } 27 | } 28 | if(sum) { 29 | cout << sum << '\n'; 30 | cout << minimum; 31 | } 32 | else { 33 | cout << -1; 34 | } 35 | return 0; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /solutions/baekjoon/2606/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : seastar105 2 | // Co-authored by : - 3 | // Link : http://boj.kr/f4a2942a69264111a18e39d0c384209e 4 | #include 5 | using namespace std; 6 | vector> G(105); 7 | bool vis[105]; 8 | int N, M; 9 | 10 | void dfs(int cur) { 11 | vis[cur] = true; 12 | for (const int &nxt : G[cur]) { 13 | if (!vis[nxt]) dfs(nxt); 14 | } 15 | } 16 | 17 | int main() { 18 | cin.tie(nullptr); 19 | ios::sync_with_stdio(false); 20 | cin >> N >> M; 21 | for (int i = 0; i < M; ++i) { 22 | int u, v; 23 | cin >> u >> v; 24 | G[u].push_back(v); 25 | G[v].push_back(u); 26 | } 27 | dfs(1); 28 | int ans = 0; 29 | for (int i = 1; i <= N; ++i) ans += vis[i]; 30 | cout << ans - 1 << '\n'; // except vertex 1 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /solutions/baekjoon/2609/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/054bab418a2c441a99982acfa1ba2b27 4 | #include 5 | 6 | using namespace std; 7 | 8 | int gcd(int a, int b) { 9 | if(b == 0)return a; 10 | return gcd(b, a % b); 11 | } 12 | int lcm(int a, int b){ 13 | return a / gcd(a, b) * b; 14 | } 15 | 16 | int main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int a, b; cin >> a >> b; 21 | cout << gcd(a, b) << '\n' << lcm(a, b); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/2609/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : hji7599 2 | # Co-authored by : - 3 | # Link : http://boj.kr/9f0533b8217348959a820f3ac7f19283 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | # 유클리드 호제법(Euclidean algorithm) 10 | def gcd(num1, num2): 11 | if num2 == 0: return num1 12 | return gcd(num2, num1 % num2) 13 | 14 | def lcm(num1, num2): 15 | return (num1 * num2) // gcd(num1, num2) 16 | 17 | a, b = map(int, input().split()) 18 | 19 | g = gcd(a, b) 20 | l = lcm(a, b) 21 | 22 | print(g) 23 | print(l) 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/2729/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/fd10df28858644eebc6b4ffd042c2d83 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | T = int(input()) 9 | for i in range(T): 10 | a,b = input().split() 11 | total = int(a,2) + int(b,2) 12 | print(bin(total)[2:]) -------------------------------------------------------------------------------- /solutions/baekjoon/2744/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/39641966833845ec931ab403fc15026d 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | word = input() 9 | ans = '' 10 | for i in word: 11 | if i.islower(): 12 | ans += i.upper() 13 | else: 14 | ans += i.lower() 15 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/2745/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/6f8324f145664e3890bd12301389737d 4 | #include 5 | 6 | using namespace std; 7 | 8 | int getValue(char x) { 9 | if(x <= '9') return x - '0'; 10 | return x - 'A' + 10; 11 | } 12 | 13 | int main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(0); 16 | 17 | string s; cin >> s; 18 | int base; cin >> base; 19 | 20 | int answer = 0; 21 | for(int i=0;i<(int)s.size();i++) { 22 | answer = answer * base + getValue(s[i]); 23 | } 24 | cout << answer; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/2748/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/b5fdc8a3c2c84784a6b308c98e4aa7e9 4 | #include 5 | 6 | using namespace std; 7 | 8 | long long DP[99]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | DP[1] = 1; 15 | for(int i=2;i<=90;i++)DP[i] = DP[i-1] + DP[i-2]; 16 | 17 | int N; cin >> N; 18 | cout << DP[N]; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /solutions/baekjoon/2753/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/a5fabcbae0604daabb17802f9323c69f 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int n; cin >> n; 13 | if(n % 4 == 0 && (n % 100 != 0 || n % 400 == 0)){ 14 | cout << 1; 15 | } 16 | else { 17 | cout << 0; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /solutions/baekjoon/2753/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/8321cffd959748c981d1cb359cccee9d 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | year = int(input()) 10 | 11 | print(1 if not year % 4 and (year % 100 or not year % 400) else 0) 12 | -------------------------------------------------------------------------------- /solutions/baekjoon/2776/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/93afacc450454aedbd2b0d6667914846 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def binary_search(t): 10 | start, end = 0, len(arr)-1 11 | while start <= end: 12 | mid = (start + end) // 2 13 | if arr[mid] == t: 14 | return 1 15 | elif arr[mid] > t: 16 | end = mid - 1 17 | else: 18 | start = mid + 1 19 | return 0 20 | 21 | T = int(input()) 22 | for i in range(T): 23 | N = int(input()) 24 | arr = list(map(int, input().split())) 25 | M = int(input()) 26 | arr2 = list(map(int, input().split())) 27 | arr.sort() 28 | for j in arr2: 29 | print(binary_search(j)) -------------------------------------------------------------------------------- /solutions/baekjoon/2798/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/dc356e3adafd4e158b47dce9a9acd59b 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N, M; cin >> N >> M; 13 | int answer = 0; 14 | vector V(N); 15 | for(int i=0;i> V[i]; 16 | for(int i=0;i M) continue; 21 | answer = max(answer, value); 22 | } 23 | } 24 | } 25 | cout << answer; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/2798/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/29a558ec778348f589fad5c627187638 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N, M = map(int, input().split()) 10 | MAX = 0 11 | arr = list(map(int, input().split())) 12 | for i in range(len(arr)): 13 | for j in range(i+1,len(arr)): 14 | for z in range(j+1,len(arr)): 15 | if arr[i] + arr[j] + arr[z] <= M: 16 | MAX = max(MAX, arr[i] + arr[j] + arr[z]) 17 | print(MAX) -------------------------------------------------------------------------------- /solutions/baekjoon/2805/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/331c1288d35f4db9b12e371e014dfffd 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def binary_search(): 10 | global ans 11 | start, end = 0, max(arr) 12 | 13 | while start <= end: 14 | mid = (start + end) // 2 15 | total_length = 0 16 | for i in arr: 17 | if i - mid >= 0: 18 | total_length += i - mid 19 | 20 | if total_length < M: 21 | end = mid - 1 22 | else: 23 | start = mid + 1 24 | ans = end 25 | 26 | N, M = map(int, input().split()) 27 | arr = list(map(int, input().split())) 28 | ans = 0 29 | binary_search() 30 | print(ans) 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/28070/main2.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/9471affea01c478683f7d4b2b1a63c04 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | vector> V; 14 | for(int i = 0; i < N; ++i) { 15 | string u, v; cin >> u >> v; 16 | V.emplace_back(u, 1); // 구간의 시작 17 | V.emplace_back(v, 2); // 구간의 끝 18 | } 19 | sort(V.begin(), V.end()); 20 | 21 | int cnt = 0, mx = 0; 22 | string ans = ""; 23 | for(auto [date, type]: V) { 24 | if(type == 1) { 25 | if(++ cnt > mx) { 26 | mx = cnt; 27 | ans = date; 28 | } 29 | } 30 | else { 31 | -- cnt; 32 | } 33 | } 34 | cout << ans; 35 | 36 | return 0; 37 | } 38 | 39 | /* Solution Description 40 | 이런 일정한 길이의 요일(ex. YYYY-MM)은 파싱을 하지 않고 문자열 비교로만 해도 충분하다. 41 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/2812/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/632e2f63fb4a44caacbddb53207f2279 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | n, k = map(int, input().split()) 9 | t = k # 미래를 위해 저장 10 | num = list(input()) 11 | stack = [] # 정답 저장 및 지울 후보 저장 12 | 13 | for i in range(n): 14 | while k>0 and stack: # 지울 수 있는 숫자가 있을 때 15 | if stack[-1] < num[i]: # 지우는 게 이득이면 16 | stack.pop() 17 | k -= 1 18 | else: 19 | break 20 | stack.append(num[i]) 21 | 22 | print(*stack[:(n-t)], sep='') #남아있는 숫자는 n-(최초 k) => t를 여기서 사용 -------------------------------------------------------------------------------- /solutions/baekjoon/2839/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/48cb7b8049444c7eb5cdc5752dd5eb66 4 | #include 5 | 6 | using namespace std; 7 | 8 | int DP[5005]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | const int INF = 50000; 15 | for(int i=1;i<=5000;i++) DP[i] = INF; 16 | DP[3] = 1; 17 | 18 | for(int i=5;i<=5000;i++) DP[i] = min({ DP[i], DP[i - 3] + 1, DP[i - 5] + 1}); 19 | 20 | int N; cin >> N; 21 | if(DP[N] == INF)DP[N] = -1; 22 | cout << DP[N]; 23 | } 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/2960/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/bf53232ebf90497bbcdea9716eade1e8 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool erased[1005]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | int K, N; cin >> N >> K; 15 | for(int i=2;K && i<=N;i++){ 16 | if(erased[i])continue; 17 | for(int j=i;K && j<=N;j+=i){ 18 | if(erased[j])continue; 19 | erased[j] = true; 20 | if(--K == 0) cout << j; 21 | } 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /solutions/baekjoon/30457/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/0d27b72bdd8d4832b2dfdca3f71105df 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int N; cin >> N; 13 | vector V(N); 14 | for(int i = 0; i < N; ++i) { 15 | cin >> V[i]; 16 | } 17 | sort(V.begin(), V.end()); 18 | vector used(N); 19 | int pre = 0, ans = 0; 20 | for(int i = 0; i < N; ++i) { 21 | if(pre < V[i]) { 22 | used[i] = 1; 23 | pre = V[i]; 24 | ++ans; 25 | } 26 | } 27 | pre = 1001; 28 | for(int i = N - 1; i >= 0; --i) { 29 | if(pre > V[i] && used[i] == 0) { 30 | pre = V[i]; 31 | ++ ans; 32 | } 33 | } 34 | cout << ans; 35 | 36 | return 0; 37 | } 38 | 39 | /* Solution Description 40 | 정렬을 하고 작은거부터 큰 값을 보면서 하나씩 선택하고 그리고 큰 값에서부터 다시 작은 값으로 보면서 선택되지 않은 값들을 선택하면 됨. 41 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/3079/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : yj2221 2 | # Co-authored by : - 3 | # Link : http://boj.kr/efcb8c8f772044538717ee1203d7c02d 4 | 5 | import sys 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | n, m = map(int, input().split()) 11 | arr = [int(input()) for _ in range(n)] 12 | 13 | low, high = 0, 1000000000 * m 14 | while low <= high: 15 | mid = (low + high)//2 16 | cnt = 0 17 | for time in arr: 18 | cnt += mid//time 19 | if cnt>=m: 20 | high = mid - 1 21 | else: 22 | low = mid + 1 23 | 24 | print(low) 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/30979/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: http://boj.kr/23eecf0ad4d34516bf8df6de7b8a64ee 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main() { 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int T; cin >> T; 13 | int N; cin >> N; 14 | int S = 0; 15 | for(int i = 0; i < N; ++i) { 16 | int x; cin >> x; 17 | S += x; 18 | } 19 | if(S >= T) cout << "Padaeng_i Happy"; 20 | else cout << "Padaeng_i Cry"; 21 | 22 | return 0; 23 | } 24 | 25 | /* Solution Description 26 | 주어진 N개의 합이 T보다 크거나 같은지 확인하면 되는 문제 27 | */ -------------------------------------------------------------------------------- /solutions/baekjoon/3986/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/25fcff12eee34fb6a0f0d4023cac4e4d 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | ans = 0 11 | for i in range(N): 12 | stack = [] 13 | a = input() 14 | for i in a: 15 | if not stack: 16 | stack.append(i) 17 | else: 18 | if stack[-1] == i: 19 | stack.pop() 20 | else: 21 | stack.append(i) 22 | if not stack: 23 | ans += 1 24 | print(ans) -------------------------------------------------------------------------------- /solutions/baekjoon/4096/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/b554cc74d1a24c9e9306775641121065 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | def isPalindrome(s): 9 | return s == s[::-1] 10 | 11 | while True: 12 | N = input() 13 | length = len(N) 14 | ct = 0 15 | if N == '0': 16 | break 17 | elif isPalindrome(N): 18 | print(0) 19 | else: 20 | while True: 21 | if isPalindrome(N): 22 | print(ct) 23 | break 24 | N = str(int(N)+1) 25 | N = '0' * (length - len(N)) + N 26 | ct += 1 -------------------------------------------------------------------------------- /solutions/baekjoon/4134/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/7269680b194f4af3a6a05b0f88161fb2 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | bool isPrime(ll x) { 10 | if(x < 2) return false; 11 | for(ll i=2;i*i<=x;i++){ 12 | if(x % i == 0) return false; 13 | } 14 | return true; 15 | } 16 | 17 | int main(){ 18 | ios::sync_with_stdio(false); 19 | cin.tie(0); 20 | 21 | int t; cin >> t; 22 | while(t--){ 23 | ll x; cin >> x; 24 | while(!isPrime(x))x++; 25 | cout << x << '\n'; 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /solutions/baekjoon/4256/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/320c53a7494341c0b867034b59ec4377 4 | #include 5 | 6 | using namespace std; 7 | 8 | vector preorder, inorder; 9 | void solve(int L, int R, int L2, int R2) { 10 | if(L > R || L2 > R2) return; 11 | int root = preorder[L]; 12 | int idx = L2; 13 | while(inorder[idx] != root) idx ++; 14 | solve(L + 1, L + idx - L2, L2, idx - 1); 15 | solve(L + idx - L2 + 1, R, idx + 1, R2); 16 | cout << root << ' '; 17 | } 18 | 19 | int main(){ 20 | ios::sync_with_stdio(false); 21 | cin.tie(0); 22 | 23 | int t; cin >> t; 24 | while(t--) { 25 | int n; cin >> n; 26 | preorder.clear(); preorder.resize(n); 27 | inorder.clear(); inorder.resize(n); 28 | for(int i=0;i> preorder[i]; 29 | for(int i=0;i> inorder[i]; 30 | solve(0, n - 1, 0, n - 1); 31 | cout << '\n'; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /solutions/baekjoon/4358/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/8af3200059e848aaa9c06901b34bcef7 4 | #include 5 | 6 | using namespace std; 7 | 8 | map mp; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | string s; 15 | int total = 0; 16 | while(getline(cin, s)) { 17 | mp[s] += 1; 18 | total += 1; 19 | } 20 | 21 | cout.precision(4); 22 | cout << fixed; 23 | for(auto &[k, v]: mp) { 24 | cout << k << ' ' << v * 100.0 / total << '\n'; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/4690/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/fb355cbf95324465b430f4423567a2c4 4 | for a in range(2, 100 + 1): 5 | for b in range(2, a): 6 | for c in range(b, a): 7 | for d in range(c, a): 8 | if a ** 3 == b ** 3 + c ** 3 + d ** 3: 9 | print(f'Cube = {a}, Triple = ({b},{c},{d})') -------------------------------------------------------------------------------- /solutions/baekjoon/4779/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/5aee7052f3ee45d5b0294edfb54c92f1 4 | #include 5 | 6 | using namespace std; 7 | 8 | string answer; 9 | 10 | void dfs(int L, int dis) { 11 | if(dis == 1) { 12 | answer[L] = '-'; 13 | return; 14 | } 15 | 16 | dis /= 3; 17 | dfs(L, dis); 18 | dfs(L + 2 * dis, dis); 19 | } 20 | 21 | int main(){ 22 | ios::sync_with_stdio(false); 23 | cin.tie(0); 24 | 25 | int k; 26 | while(cin >> k) { 27 | int N = 1; 28 | for(int i = 0; i < k; i++) N *= 3; 29 | answer = string(N, ' '); 30 | dfs(0, N); 31 | cout << answer << '\n'; 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /solutions/baekjoon/4963/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/27c8f362bf2c4defbe77f079e9eaa89e 4 | import sys 5 | sys.setrecursionlimit(10000) 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | def DFS(x, y): 11 | arr[x][y] = 0 12 | for i in range(8): 13 | dx = nx[i] + x 14 | dy = ny[i] + y 15 | if dx < 0 or dx >= h or dy < 0 or dy >= w: 16 | continue 17 | if arr[dx][dy] == 1: 18 | DFS(dx,dy) 19 | 20 | nx = [-1,-1,-1,0,1,1,1,0] 21 | ny = [-1,0,1,1,1,0,-1,-1] 22 | 23 | while True: 24 | w, h = map(int, input().split()) 25 | if w == 0 and h == 0: 26 | break 27 | arr = [] 28 | ct = 0 29 | for i in range(h): 30 | arr.append(list(map(int, input().split()))) 31 | for i in range(h): 32 | for j in range(w): 33 | if arr[i][j] == 1: 34 | DFS(i,j) 35 | ct += 1 36 | print(ct) 37 | -------------------------------------------------------------------------------- /solutions/baekjoon/5347/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/3e2183112f164d1f98320d51f1ce2642 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | ll gcd(ll a, ll b){ 10 | return b ? gcd(b, a % b) : a; 11 | } 12 | ll lcm(ll a, ll b) { 13 | return a / gcd(a, b) * b; 14 | } 15 | 16 | int main(){ 17 | ios::sync_with_stdio(false); 18 | cin.tie(0); 19 | 20 | int t; cin >> t; 21 | while(t--){ 22 | ll a, b; cin >> a >> b; 23 | cout << lcm(a, b) << '\n'; 24 | } 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /solutions/baekjoon/5397/main.py: -------------------------------------------------------------------------------- 1 | # // Authored by : chj3748 2 | # // Co-authored by : - 3 | # // Link : http://boj.kr/471d69f455a544769c6c2fa7199442d1 4 | import sys 5 | from collections import deque 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | T = int(input()) 11 | for test in range(T): 12 | answer_l = deque() 13 | answer_r = deque() 14 | for string in input(): 15 | if string == '<': 16 | if answer_l: 17 | temp = answer_l.pop() 18 | answer_r.appendleft(temp) 19 | elif string == '>': 20 | if answer_r: 21 | temp = answer_r.popleft() 22 | answer_l.append(temp) 23 | elif string == '-': 24 | if answer_l: 25 | answer_l.pop() 26 | else: 27 | answer_l.append(string) 28 | print(''.join(answer_l + answer_r)) 29 | -------------------------------------------------------------------------------- /solutions/baekjoon/5557/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/23af4ad30fe24df4a71cdd3db925087c 4 | import sys 5 | import heapq 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | N = int(input()) 11 | numbers = list(map(int, input().split())) 12 | dp = [[0] * 21 for _ in range(N - 1)] 13 | dp[0][numbers[0]] = 1 14 | for i in range(1, N - 1): 15 | for j in range(21): 16 | if dp[i - 1][j] <= 0: 17 | continue 18 | for oper in (1, -1): 19 | temp = j + oper * numbers[i] 20 | if 0 <= temp < 21: 21 | dp[i][temp] += dp[i - 1][j] 22 | answer = dp[N - 2][numbers[N - 1]] 23 | print(answer) 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/5568/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/0dd94001579e4341b3ea06ed523d2cba 4 | import sys 5 | from itertools import permutations 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | n = int(input()) 11 | arr = [] 12 | ans = set() 13 | k = int(input()) 14 | for i in range(n): 15 | arr.append(input()) 16 | per = list(permutations(arr, k)) 17 | for i in range(len(per)): 18 | st = '' 19 | for j in range(len(per[i])): 20 | st += per[i][j] 21 | ans.add(st) 22 | ans = list(ans) 23 | print(len(ans)) -------------------------------------------------------------------------------- /solutions/baekjoon/5597/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/2fdc4dd328f9417b8b9f64e2ed0640be 4 | #include 5 | 6 | using namespace std; 7 | 8 | bool chk[33]; 9 | 10 | int main(){ 11 | ios::sync_with_stdio(false); 12 | cin.tie(0); 13 | 14 | for(int i=0;i<28;i++){ 15 | int x;cin >> x; 16 | chk[x] = true; 17 | } 18 | for(int i=1;i<=30;i++){ 19 | if(chk[i] == false)cout << i << '\n'; 20 | } 21 | 22 | return 0; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /solutions/baekjoon/5597/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : samuel95 2 | # Co-authored by : - 3 | # Link : http://boj.kr/5229a16593bd45beb68eefd6224ef63b 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | numbers = [False for _ in range(31)] 10 | 11 | for _ in range(28): 12 | n = int(input()) 13 | numbers[n] = True 14 | 15 | ans = [] 16 | 17 | for i in range(1, 31): 18 | if not numbers[i]: 19 | ans.append(i) 20 | 21 | print(ans[0]) 22 | print(ans[1]) 23 | -------------------------------------------------------------------------------- /solutions/baekjoon/5618/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/1df904530afc47edbe9a9983b130ce19 4 | #include 5 | 6 | using namespace std; 7 | 8 | int gcd(int a, int b) { 9 | if(b == 0) return a; 10 | return gcd(b, a%b); 11 | } 12 | 13 | int main(){ 14 | ios::sync_with_stdio(false); 15 | cin.tie(0); 16 | 17 | int n; cin >> n; 18 | int a, b; cin >> a >> b; 19 | a = gcd(a, b); 20 | if(n == 3) { 21 | int c; cin >> c; 22 | a = gcd(a, c); 23 | } 24 | 25 | vector ans; 26 | for(int i=1;i*i<=a;i++){ 27 | if(a % i != 0) continue; 28 | ans.push_back(i); 29 | if(i * i != a) ans.push_back(a / i); 30 | } 31 | sort(ans.begin(), ans.end()); 32 | for(int i=0;i<(int)ans.size();i++){ 33 | cout << ans[i] << '\n'; 34 | } 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /solutions/baekjoon/5618/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/aef57ade1e5c4c6e90f08a159fe96ca2 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def GCD(x,y): 10 | if y == 0: 11 | return x 12 | else: 13 | return GCD(y, x%y) 14 | 15 | n = int(input()) 16 | arr = list(map(int, input().split())) 17 | outputs = list() 18 | 19 | gcd = arr[0] 20 | for i in range(1, n): 21 | gcd = GCD(gcd, arr[i]) 22 | 23 | x = 1 24 | while x * x <= gcd: 25 | if gcd % x == 0: 26 | outputs.append(x) 27 | if x * x != gcd: 28 | outputs.append(gcd // x) 29 | x += 1 30 | 31 | outputs.sort() 32 | print(*outputs) 33 | -------------------------------------------------------------------------------- /solutions/baekjoon/6236/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/2fe2f6f8da4f448a8b1b2e6a4da13627 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def binary_search(): 10 | global K 11 | start, end = max(arr), sum(arr) 12 | while start <= end: 13 | mid = (start + end) // 2 14 | have,ct = 0,0 15 | for i in arr: 16 | if have < i: 17 | have = mid - i 18 | ct += 1 19 | else: 20 | have = have - i 21 | if ct > M: 22 | start = mid + 1 23 | else: 24 | end = mid - 1 25 | K = mid 26 | 27 | N, M = map(int, input().split()) 28 | arr = [] 29 | K = 0 30 | for i in range(N): 31 | arr.append(int(input())) 32 | binary_search() 33 | print(K) 34 | -------------------------------------------------------------------------------- /solutions/baekjoon/7568/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/5540a61d3d364466bbe47e8c62beaedb 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | arr = [] 11 | 12 | for i in range(N): 13 | weight, height = map(int, input().split()) 14 | arr.append([weight,height,1]) 15 | 16 | for i in range(N): 17 | for j in range(N): 18 | if arr[i][0] < arr[j][0] and arr[i][1] < arr[j][1]: 19 | arr[i][2] += 1 20 | 21 | for i in range(len(arr)): 22 | print(arr[i][2], end=' ') -------------------------------------------------------------------------------- /solutions/baekjoon/7579/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/7cc3cfd9bda64cfe8af9ff0a99c789a9 4 | #include 5 | 6 | using namespace std; 7 | 8 | int DP[10001], N, M, mem[101], cost[101]; 9 | int sum_cost; 10 | 11 | int main(){ 12 | ios::sync_with_stdio(false); 13 | cin.tie(0); 14 | 15 | cin >> N >> M; 16 | for(int i=0;i> mem[i]; 17 | for(int i=0;i> cost[i]; 19 | sum_cost += cost[i]; 20 | } 21 | for(int i=0;i=0;j--){ 23 | if(j - cost[i] >= 0){ 24 | DP[j] = max(DP[j], DP[j - cost[i]] + mem[i]); 25 | } 26 | } 27 | } 28 | int answer = 0; 29 | for(int i=0;i<=sum_cost;i++) { 30 | if(DP[i] >= M) { 31 | answer = i; 32 | break; 33 | } 34 | } 35 | cout << answer; 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /solutions/baekjoon/9012/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/553d0936c1674183a249a58070467343 4 | #include 5 | 6 | using namespace std; 7 | 8 | string solve(string str) { 9 | stack st; 10 | for(int i=0;i<(int)str.size();i++){ 11 | if(str[i] == '(') st.push('('); 12 | else { 13 | if(st.empty()) return "NO"; 14 | st.pop(); 15 | } 16 | } 17 | 18 | if(st.empty()) return "YES"; 19 | return "NO"; 20 | } 21 | 22 | int main(){ 23 | ios::sync_with_stdio(false); 24 | cin.tie(0); 25 | 26 | int T; cin >> T; 27 | while(T--) { 28 | string s; cin >> s; 29 | cout << solve(s) << '\n'; 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /solutions/baekjoon/9012/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : klm03025 2 | # Co-authored by : - 3 | # Link : http://boj.kr/b57f1dad96a946e48e0679872d97d024 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | N = int(input()) 10 | result = "" 11 | 12 | for i in range(N): 13 | testcase = input() 14 | cnt = 0 15 | for c in testcase: 16 | cnt += 1 if c == '(' else -1 17 | if cnt < 0: 18 | result += "NO\n" 19 | break 20 | else: 21 | result += "YES\n" if cnt == 0 else "NO\n" 22 | 23 | print(result) -------------------------------------------------------------------------------- /solutions/baekjoon/9046/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/ecd357e546d24b059db0160435e99364 4 | import sys 5 | def input(): 6 | return sys.stdin.readline().rstrip() 7 | 8 | N = int(input()) 9 | for i in range(N): 10 | a = input() 11 | total = {} 12 | for j in a: 13 | if j == ' ': 14 | continue 15 | if j not in total: 16 | total[j] = 1 17 | else: 18 | total[j] += 1 19 | new_total = list(total.items()) 20 | if len(new_total) == 1: 21 | print(new_total[0][0]) 22 | else: 23 | new_total.sort(key = lambda x : -x[1]) 24 | if new_total[0][1] == new_total[1][1]: 25 | print('?') 26 | else: 27 | print(new_total[0][0]) -------------------------------------------------------------------------------- /solutions/baekjoon/9094/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : tony9402 3 | # Link : http://boj.kr/ea96af96027540dcb1daa3b65e849eab 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | T = int(input()) 10 | for i in range(T): 11 | n,m = map(int, input().split()) 12 | ct = 0 13 | for a in range(1,n): 14 | for b in range(a+1,n): 15 | if (a * a + b * b + m) % (a*b) == 0: 16 | ct += 1 17 | 18 | print(ct) 19 | -------------------------------------------------------------------------------- /solutions/baekjoon/9095/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : osy0056 2 | # Co-authored by : - 3 | # Link : http://boj.kr/da3d10e3ebc945349d778cb06444ffb1 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | tc = int(input()) 10 | 11 | dp = [0] * 15 12 | dp[1] = 1 13 | dp[2] = 2 14 | dp[3] = 4 15 | for i in range(4, 12): 16 | dp[i] = dp[i - 3] + dp[i - 2] + dp[i - 1] 17 | 18 | for _ in range(tc): 19 | n = int(input()) 20 | 21 | print(dp[n]) 22 | -------------------------------------------------------------------------------- /solutions/baekjoon/9251/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : chj3748 2 | # Co-authored by : - 3 | # Link : http://boj.kr/fa5cc7635c6b497495804944b5696e12 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | string1 = '_' + input() 10 | string2 = '_' + input() 11 | len1 = len(string1) 12 | len2 = len(string2) 13 | dp = [[0] * len2 for _ in range(len1)] 14 | 15 | for i in range(1, len1): 16 | for j in range(1, len2): 17 | if string1[i] == string2[j]: 18 | dp[i][j] = dp[i - 1][j - 1] + 1 19 | else: 20 | dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]) 21 | 22 | print(dp[len1 - 1][len2 - 1]) 23 | 24 | -------------------------------------------------------------------------------- /solutions/baekjoon/9342/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/1df192eb8ca749ec8a568e9189e4ef5d 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(){ 9 | ios::sync_with_stdio(false); 10 | cin.tie(0); 11 | 12 | int T; cin >> T; 13 | while(T--) { 14 | string s; cin >> s; 15 | bool flag = true; 16 | int idx = 0, N = (int)s.size(); 17 | if(idx < N && 'B' <= s[idx] && s[idx] <= 'F') idx++; 18 | for(char cur : {'A', 'F', 'C'}) { 19 | int cnt = 0; 20 | while(idx < N && s[idx] == cur) idx++, cnt++; 21 | if(cnt == 0) flag = false; 22 | } 23 | if(idx < N && 'A' <= s[idx] && s[idx] <= 'F') idx++; 24 | if(idx < N) flag = false; 25 | if(flag) cout << "Infected!\n"; 26 | else cout << "Good\n"; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /solutions/baekjoon/9342/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : tony9402 2 | # Co-authored by : - 3 | # Link : http://boj.kr/4fcec3ea35e4472bbca8beeebd2fe065 4 | import sys 5 | import re 6 | 7 | def input(): 8 | return sys.stdin.readline().rstrip() 9 | 10 | regex = re.compile('^[A-F]?A+F+C+[A-F]?$') 11 | N = int(input()) 12 | for testcase in range(N): 13 | line = input() 14 | print("Infected!" if regex.match(line) else "Good") 15 | 16 | -------------------------------------------------------------------------------- /solutions/baekjoon/9461/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : gusdn3477 2 | # Co-authored by : - 3 | # Link : http://boj.kr/369118cac2b14c75866029d361c95152 4 | import sys 5 | 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | def recursion(x): 10 | if x == 1 or x == 2 or x == 3: 11 | return 1 12 | if dp[x] == 0: 13 | dp[x] = recursion(x-2) + recursion(x-3) 14 | return dp[x] 15 | 16 | T = int(input()) 17 | dp = [0] * 101 18 | for i in range(T): 19 | N = int(input()) 20 | print(recursion(N)) -------------------------------------------------------------------------------- /solutions/baekjoon/9465/main.py: -------------------------------------------------------------------------------- 1 | # Authored by : cieske 2 | # Co-authored by : - 3 | # Link : http://boj.kr/39643867e537451a9ae49e16ec4f2f3f 4 | 5 | import sys 6 | def input(): 7 | return sys.stdin.readline().rstrip() 8 | 9 | t = int(input()) 10 | for _ in range(t): 11 | n = int(input()) 12 | lst = [list(map(int, input().split())) for i in range(2)] 13 | # 새로 dp 행렬 만들 필요 없이 스티커 값이 저장된 lst 배열에서 dp 수행 14 | 15 | if n > 1: 16 | # 경우의 수 오직 1개 17 | lst[0][1] += lst[1][0] 18 | lst[1][1] += lst[0][0] 19 | 20 | if n > 2: 21 | for i in range(2, n): 22 | #대각선에 있는 스티커를 고를 지, 거기서 한 칸 더 떨어져 있는 스티커를 고를 지 선택 23 | lst[0][i] += max(lst[1][i-1], lst[1][i-2]) 24 | lst[1][i] += max(lst[0][i-1], lst[0][i-2]) 25 | 26 | print(max(lst[0][-1], lst[1][-1])) 27 | -------------------------------------------------------------------------------- /solutions/baekjoon/9613/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tony9402 2 | // Co-authored by : - 3 | // Link : http://boj.kr/81fae9eae6b04d77bb40a1d3fb340b3c 4 | #include 5 | 6 | using namespace std; 7 | typedef long long ll; 8 | 9 | int gcd(int a, int b){ 10 | if(b == 0)return a; 11 | return gcd(b, a % b); 12 | } 13 | 14 | int main(){ 15 | ios::sync_with_stdio(false); 16 | cin.tie(0); 17 | 18 | int t; cin >> t; 19 | while(t--){ 20 | int n;cin >> n; 21 | vector v(n); 22 | for(int i=0;i> v[i]; 23 | ll ans = 0; 24 | for(int i=0;i 5 | 6 | using namespace std; 7 | 8 | int n, ans; 9 | bool Y[22], DL[44], DR[44]; 10 | 11 | void dfs(int y, int cnt){ 12 | if(cnt == n){ 13 | ans++; 14 | return; 15 | } 16 | for(int j=0;j> n; 29 | dfs(0, 0); 30 | cout << ans; 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /solutions/hackerrank/8137/main.sql: -------------------------------------------------------------------------------- 1 | -- Authored by: tony9402 2 | -- Co-authored by: - 3 | -- Link: 4 | 5 | SELECT * FROM CITY; 6 | 7 | /* Solution Description 8 | SELECT절을 사용할 수 있는 묻는 문제 9 | */ -------------------------------------------------------------------------------- /solutions/leetcode/1609/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: https://leetcode.com/problems/even-odd-tree/submissions/1189214289?envType=daily-question&envId=2024-02-29 4 | class Solution { 5 | public: 6 | array chk; 7 | bool isEvenOddTree(TreeNode* root, int dep = 0) { 8 | if(root == nullptr) return true; 9 | if(chk[dep] == 0 && dep % 2) chk[dep] = INT_MAX; 10 | if(1 - dep % 2 != root->val % 2) return false; 11 | if( dep & 1 && chk[dep] <= root->val) return false; 12 | if(~dep & 1 && chk[dep] >= root->val) return false; 13 | chk[dep] = root->val; 14 | return isEvenOddTree(root->left, dep + 1) && isEvenOddTree(root->right, dep + 1); 15 | } 16 | }; 17 | 18 | /* Solution Description 19 | 현재 노드에서 왼쪽 오른쪽 자식을 순서대로 재귀적으로 보면서 짝수 번째 레벨에 존재하는 값이 증가하는지, 홀수 번째 레벨에 존재하는 값들은 감소하는지 확인하면 된다. 20 | */ -------------------------------------------------------------------------------- /solutions/leetcode/2864/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: https://leetcode.com/problems/maximum-odd-binary-number/submissions/1190335975 4 | class Solution { 5 | public: 6 | string maximumOddBinaryNumber(string s) { 7 | int k = 0; 8 | for(int i = 0; i < s.size(); ++i) { 9 | if(s[i] == '1') swap(s[k ++], s[i]); 10 | } 11 | swap(s[k - 1], s.back()); 12 | return s; 13 | } 14 | }; 15 | 16 | /* Solution Description 17 | 적어도 한 개 이상 '1'이 주어지므로 무조건 홀수를 만들 수 있다. 18 | 19 | 홀수이면서 가장 큰 수로 만들기 위해서는 '1'을 하위비트에 배치하고 나머지 '1'들을 가장 상위비트에 몰아넣으면 된다. 20 | */ -------------------------------------------------------------------------------- /solutions/leetcode/9/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: https://leetcode.com/problems/palindrome-number/submissions/1163121115 4 | class Solution { 5 | public: 6 | bool isPalindrome(int x) { 7 | if(x < 0) return false; 8 | long long y = 0, tmp = x; 9 | while(tmp > 0) { 10 | y = y * 10 + tmp % 10; 11 | tmp /= 10; 12 | } 13 | return x == y; 14 | } 15 | }; 16 | 17 | /* Solution Description 18 | x값이 음수인 경우 항상 false, x가 양수일 땐 수를 뒤집어서 처음 주어진 x와 값이 같은지 판별. 19 | x를 뒤집을 때 int보다 커질 수 있으므로 타입 주의 20 | */ -------------------------------------------------------------------------------- /solutions/leetcode/9/main.py: -------------------------------------------------------------------------------- 1 | # Authored by: tony9402 2 | # Co-authored by: - 3 | # Link: https://leetcode.com/problems/palindrome-number/submissions/1163289608 4 | class Solution(object): 5 | def isPalindrome(self, x): 6 | return str(x)[::-1] == str(x) 7 | 8 | 9 | """ Solution Description 10 | x값이 음수인 경우 항상 false, x가 양수일 땐 수를 뒤집어서 처음 주어진 x와 값이 같은지 판별. 11 | x를 뒤집을 때 int보다 커질 수 있으므로 타입 주의 12 | """ -------------------------------------------------------------------------------- /solutions/leetcode/977/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: https://leetcode.com/problems/squares-of-a-sorted-array/submissions/1191057000 4 | class Solution { 5 | public: 6 | vector sortedSquares(vector& nums) { 7 | int N = nums.size(); 8 | vector answer(N); 9 | for(int i = N - 1, l = 0, r = N - 1; i >= 0; --i) { 10 | if(abs(nums[l]) >= abs(nums[r])) answer[i] = nums[l] * nums[l ++]; 11 | else answer[i] = nums[r] * nums[r --]; 12 | } 13 | return answer; 14 | } 15 | } 16 | 17 | /* Solution Description 18 | 이미 정렬된 배열이므로 양 끝에서부터 제곱이 가장 큰 값으로 뒤에서부터 채워나가면 된다. 19 | 20 | Time Complexity: O(N) 21 | */ -------------------------------------------------------------------------------- /solutions/programmers/181952/main.cpp: -------------------------------------------------------------------------------- 1 | // Authored by: tony9402 2 | // Co-authored by: - 3 | // Link: 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main(void) { 10 | string str; 11 | cin >> str; 12 | cout << str; 13 | return 0; 14 | } 15 | 16 | /* Solution Description 17 | 주어진 문자열을 그대로 출력하면 되는 문제 18 | */ 19 | --------------------------------------------------------------------------------