├── .github └── workflows │ └── auto-workbook-update.yml ├── 0x01 ├── test.cpp └── test_ans.cpp ├── 0x02 └── solutions │ ├── 1000.cpp │ ├── 10093.cpp │ ├── 10171.cpp │ ├── 10804.cpp │ ├── 10804_1.cpp │ ├── 10869.cpp │ ├── 10871.cpp │ ├── 1267.cpp │ ├── 15552.cpp │ ├── 2309.cpp │ ├── 2438.cpp │ ├── 2439.cpp │ ├── 2440.cpp │ ├── 2441.cpp │ ├── 2442.cpp │ ├── 2443.cpp │ ├── 2444.cpp │ ├── 2445.cpp │ ├── 2446.cpp │ ├── 2480.cpp │ ├── 2480_1.cpp │ ├── 2490.cpp │ ├── 2557.cpp │ ├── 2562.cpp │ ├── 2562_1.cpp │ ├── 2576.cpp │ ├── 2577.cpp │ ├── 2587.cpp │ ├── 2752.cpp │ ├── 2752_1.cpp │ ├── 2753.cpp │ └── 9498.cpp ├── 0x03 ├── 10808_1.cpp ├── 10808_2.cpp ├── array_test.cpp ├── array_test_ans.cpp ├── func2_ans.cpp ├── solutions │ ├── 10807.cpp │ ├── 10808.cpp │ ├── 11328.cpp │ ├── 13300.cpp │ ├── 1475.cpp │ ├── 1919.cpp │ ├── 2577.cpp │ ├── 3273.cpp │ └── 3273_1.cpp └── vector_example.cpp ├── 0x04 ├── 1406_1.cpp ├── 1406_2.cpp ├── linked_list_test.cpp ├── linked_list_test_ans.cpp ├── list_example.cpp └── solutions │ ├── 1158.cpp │ ├── 1158_1.cpp │ ├── 1158_2.cpp │ ├── 1406.cpp │ └── 5397.cpp ├── 0x05 ├── 10828_1.cpp ├── 10828_2.cpp ├── solutions │ ├── 10773.cpp │ ├── 10828.cpp │ ├── 17298.cpp │ ├── 1874.cpp │ ├── 2493.cpp │ ├── 3015.cpp │ ├── 6198.cpp │ └── 6549.cpp ├── stack_example.cpp ├── stack_test.cpp └── stack_test_ans.cpp ├── 0x06 ├── 10845_1.cpp ├── 10845_2.cpp ├── queue_example.cpp ├── queue_test.cpp ├── queue_test_ans.cpp └── solutions │ ├── 10845.cpp │ ├── 18258.cpp │ ├── 18258_1.cpp │ └── 2164.cpp ├── 0x07 ├── 10866_1.cpp ├── 10866_2.cpp ├── deque_example.cpp ├── deque_test.cpp ├── deque_test_ans.cpp └── solutions │ ├── 1021.cpp │ ├── 10866.cpp │ ├── 11003.cpp │ ├── 11003_1.cpp │ ├── 5430.cpp │ └── 5430_1.cpp ├── 0x08 ├── 4949.cpp └── solutions │ ├── 10799.cpp │ ├── 2504.cpp │ ├── 3986.cpp │ ├── 4889.cpp │ ├── 4949.cpp │ └── 9012.cpp ├── 0x09 ├── 1697.cpp ├── 1926.cpp ├── 2178.cpp ├── 4179.cpp ├── 7576.cpp ├── BFS.cpp ├── pair_example.cpp └── solutions │ ├── 10026.cpp │ ├── 1012.cpp │ ├── 11967.cpp │ ├── 13549.cpp │ ├── 13549_1.cpp │ ├── 13913.cpp │ ├── 14442.cpp │ ├── 1600.cpp │ ├── 16920.cpp │ ├── 16933.cpp │ ├── 1697.cpp │ ├── 17071.cpp │ ├── 1926.cpp │ ├── 20304.cpp │ ├── 2146.cpp │ ├── 2146_1.cpp │ ├── 2178.cpp │ ├── 2206.cpp │ ├── 2468.cpp │ ├── 2573.cpp │ ├── 2583.cpp │ ├── 2667.cpp │ ├── 3197.cpp │ ├── 4179.cpp │ ├── 5014.cpp │ ├── 5427.cpp │ ├── 6593.cpp │ ├── 7562.cpp │ ├── 7569.cpp │ ├── 7576.cpp │ ├── 9328.cpp │ └── 9466.cpp ├── 0x0A └── DFS.cpp ├── 0x0B ├── 1074.cpp ├── 11729.cpp ├── 1629.cpp └── solutions │ ├── 1074.cpp │ ├── 11729.cpp │ ├── 14956.cpp │ ├── 1629.cpp │ ├── 17478.cpp │ ├── 1780.cpp │ ├── 1992.cpp │ ├── 2447.cpp │ ├── 2447_1.cpp │ ├── 2448.cpp │ ├── 2448_1.cpp │ └── 2630.cpp ├── 0x0C ├── 1182.cpp ├── 15649.cpp ├── 9663.cpp └── solutions │ ├── 1182.cpp │ ├── 15649.cpp │ ├── 15650.cpp │ ├── 15650_1.cpp │ ├── 15651.cpp │ ├── 15652.cpp │ ├── 15654.cpp │ ├── 15655.cpp │ ├── 15656.cpp │ ├── 15657.cpp │ ├── 15663.cpp │ ├── 15664.cpp │ ├── 15665.cpp │ ├── 15666.cpp │ ├── 16987.cpp │ ├── 1759.cpp │ ├── 1759_1.cpp │ ├── 1799.cpp │ ├── 18809.cpp │ ├── 1941.cpp │ ├── 6603.cpp │ ├── 6603_1.cpp │ └── 9663.cpp ├── 0x0D ├── 12100.cpp ├── 15683.cpp ├── 15686.cpp ├── 18808.cpp └── solutions │ ├── 11559.cpp │ ├── 12100.cpp │ ├── 13335.cpp │ ├── 13335_1.cpp │ ├── 13460.cpp │ ├── 14499.cpp │ ├── 14500.cpp │ ├── 14500_1.cpp │ ├── 14500_2.cpp │ ├── 14502.cpp │ ├── 14502_1.cpp │ ├── 14502_2.cpp │ ├── 14503.cpp │ ├── 14888.cpp │ ├── 14888_1.cpp │ ├── 14889.cpp │ ├── 14890.cpp │ ├── 14891.cpp │ ├── 15683.cpp │ ├── 15684.cpp │ ├── 15685.cpp │ ├── 15686.cpp │ ├── 15898.cpp │ ├── 16234.cpp │ ├── 16235.cpp │ ├── 16236.cpp │ ├── 16637.cpp │ ├── 16985.cpp │ ├── 16986.cpp │ ├── 17070.cpp │ ├── 17070_1.cpp │ ├── 17135.cpp │ ├── 17136.cpp │ ├── 17140.cpp │ ├── 17141.cpp │ ├── 17142.cpp │ ├── 17143.cpp │ ├── 17144.cpp │ ├── 17281.cpp │ ├── 17281_1.cpp │ ├── 17406.cpp │ ├── 17471.cpp │ ├── 17472.cpp │ ├── 17779.cpp │ ├── 17822.cpp │ ├── 17825.cpp │ ├── 17837.cpp │ ├── 18808.cpp │ ├── 19235.cpp │ ├── 19236.cpp │ ├── 19237.cpp │ ├── 19238.cpp │ ├── 1941.cpp │ ├── 20055.cpp │ ├── 20056.cpp │ ├── 20057.cpp │ ├── 20058.cpp │ ├── 20061.cpp │ ├── 21608.cpp │ ├── 21609.cpp │ ├── 21610.cpp │ ├── 21611.cpp │ ├── 23288.cpp │ ├── 23289.cpp │ ├── 23290.cpp │ ├── 23291.cpp │ ├── 2478.cpp │ ├── 3190.cpp │ ├── 4991.cpp │ └── 5373.cpp ├── 0x0E ├── 11728.cpp ├── 2751.cpp ├── merge_sort_test.cpp ├── merge_sort_test_ans.cpp ├── quick_sort.cpp └── solutions │ ├── 10814.cpp │ ├── 10989.cpp │ ├── 11650.cpp │ ├── 11651.cpp │ ├── 11651_1.cpp │ ├── 11931.cpp │ ├── 15688.cpp │ ├── 2750.cpp │ └── 2751.cpp ├── 0x0F ├── 11652.cpp ├── 15688.cpp ├── radix_sort.cpp └── solutions │ ├── 10814.cpp │ ├── 10825.cpp │ ├── 11652.cpp │ ├── 11656.cpp │ ├── 1181.cpp │ ├── 1431.cpp │ ├── 2910.cpp │ ├── 5648.cpp │ ├── 7795.cpp │ └── 7795_1.cpp ├── 0x10 ├── 1149.cpp ├── 11659.cpp ├── 11726.cpp ├── 12852.cpp ├── 1463.cpp ├── 2579_1.cpp ├── 2579_2.cpp ├── 9095.cpp └── solutions │ ├── 1003.cpp │ ├── 10844.cpp │ ├── 10942.cpp │ ├── 11052.cpp │ ├── 11053.cpp │ ├── 11055.cpp │ ├── 11057.cpp │ ├── 11057_1.cpp │ ├── 1149.cpp │ ├── 11659.cpp │ ├── 11660.cpp │ ├── 11726.cpp │ ├── 11727.cpp │ ├── 12852.cpp │ ├── 14002.cpp │ ├── 14501.cpp │ ├── 14501_1.cpp │ ├── 1463.cpp │ ├── 1520.cpp │ ├── 15486.cpp │ ├── 15988.cpp │ ├── 1699.cpp │ ├── 1788.cpp │ ├── 1904.cpp │ ├── 1912.cpp │ ├── 1915.cpp │ ├── 1932.cpp │ ├── 2011.cpp │ ├── 2133.cpp │ ├── 2156.cpp │ ├── 2156_1.cpp │ ├── 2193.cpp │ ├── 2240.cpp │ ├── 2240_1.cpp │ ├── 2293.cpp │ ├── 2294.cpp │ ├── 2302.cpp │ ├── 2482.cpp │ ├── 2579.cpp │ ├── 2579_1.cpp │ ├── 2579_2.cpp │ ├── 2748.cpp │ ├── 4883.cpp │ ├── 9084.cpp │ ├── 9095.cpp │ ├── 9251.cpp │ ├── 9461.cpp │ ├── 9465.cpp │ ├── 9655.cpp │ ├── 9655_1.cpp │ └── 9657.cpp ├── 0x11 ├── 1026.cpp ├── 11047.cpp ├── 1931.cpp ├── 2217.cpp └── solutions │ ├── 1026.cpp │ ├── 11000.cpp │ ├── 11000_1.cpp │ ├── 11047.cpp │ ├── 11399.cpp │ ├── 11501.cpp │ ├── 1439.cpp │ ├── 1541.cpp │ ├── 15903.cpp │ ├── 15903_1.cpp │ ├── 1700.cpp │ ├── 1744.cpp │ ├── 1931.cpp │ ├── 2170.cpp │ ├── 2170_1.cpp │ ├── 2217.cpp │ ├── 2457.cpp │ ├── 2847.cpp │ ├── 7570.cpp │ └── 8980.cpp ├── 0x12 ├── 11050.cpp ├── 11051.cpp ├── 11653.cpp ├── 1929.cpp ├── 1978.cpp ├── 6064.cpp └── solutions │ ├── 1011.cpp │ ├── 1019.cpp │ ├── 10250.cpp │ ├── 1038.cpp │ ├── 1038_1.cpp │ ├── 1057.cpp │ ├── 1057_1.cpp │ ├── 10610.cpp │ ├── 11050.cpp │ ├── 11051.cpp │ ├── 11653.cpp │ ├── 1193.cpp │ ├── 1256.cpp │ ├── 1292.cpp │ ├── 1456.cpp │ ├── 1476.cpp │ ├── 15894.cpp │ ├── 1676.cpp │ ├── 17103.cpp │ ├── 1735.cpp │ ├── 1747.cpp │ ├── 1747_1.cpp │ ├── 1790.cpp │ ├── 1929.cpp │ ├── 1963.cpp │ ├── 1978.cpp │ ├── 2004.cpp │ ├── 2089.cpp │ ├── 2292.cpp │ ├── 2312.cpp │ ├── 2839.cpp │ ├── 2869.cpp │ ├── 2960.cpp │ ├── 3036.cpp │ ├── 3343.cpp │ ├── 4796.cpp │ ├── 4948.cpp │ ├── 5347.cpp │ ├── 6064.cpp │ ├── 6359.cpp │ ├── 6359_1.cpp │ ├── 9020.cpp │ └── 9613.cpp ├── 0x13 ├── 10816.cpp ├── 10816_1.cpp ├── 1654.cpp ├── 18870.cpp ├── 18870_1.cpp ├── 1920.cpp ├── 1920_1.cpp ├── 2295.cpp └── solutions │ ├── 10815.cpp │ ├── 10816.cpp │ ├── 10816_1.cpp │ ├── 12015.cpp │ ├── 1253.cpp │ ├── 1477.cpp │ ├── 1477_1.cpp │ ├── 14921.cpp │ ├── 16401.cpp │ ├── 1654.cpp │ ├── 1822.cpp │ ├── 18869.cpp │ ├── 18870.cpp │ ├── 18870_1.cpp │ ├── 1920.cpp │ ├── 1920_1.cpp │ ├── 2110.cpp │ ├── 2143.cpp │ ├── 2295.cpp │ ├── 2467.cpp │ ├── 2467_1.cpp │ ├── 2473.cpp │ ├── 2512.cpp │ ├── 2805.cpp │ ├── 3151.cpp │ └── 7453.cpp ├── 0x14 ├── 1806.cpp ├── 2230.cpp └── solutions │ ├── 13144.cpp │ ├── 1644.cpp │ ├── 1806.cpp │ ├── 2003.cpp │ ├── 20366.cpp │ ├── 20922.cpp │ ├── 2230.cpp │ ├── 2283.cpp │ ├── 22862.cpp │ ├── 2461.cpp │ └── 2531.cpp ├── 0x15 ├── 1620.cpp ├── 7785.cpp ├── hash_chaining_test.cpp ├── hash_chaining_test_ans.cpp ├── hash_open_addressing_test.cpp ├── hash_open_addressing_test_ans.cpp ├── solutions │ ├── 11478.cpp │ ├── 13414.cpp │ ├── 16165.cpp │ ├── 1620.cpp │ ├── 17219.cpp │ ├── 19583.cpp │ ├── 20166.cpp │ ├── 7785.cpp │ └── 9375.cpp └── stl_example.cpp ├── 0x16 ├── 1202.cpp ├── 7662.cpp ├── solutions │ ├── 1202.cpp │ ├── 1539.cpp │ ├── 19700.cpp │ ├── 21939.cpp │ ├── 21944.cpp │ ├── 21944_1.cpp │ ├── 23326.cpp │ └── 7662.cpp └── stl_example.cpp ├── 0x17 ├── 11286.cpp ├── 1715.cpp ├── heap_example.cpp ├── heap_test.cpp ├── heap_test_ans.cpp └── solutions │ ├── 11279.cpp │ ├── 11286.cpp │ ├── 13975.cpp │ ├── 1655.cpp │ ├── 1715.cpp │ ├── 1781.cpp │ ├── 1927.cpp │ └── 2075.cpp ├── 0x18 ├── 11724.cpp ├── 1260.cpp └── solutions │ ├── 1043.cpp │ ├── 11403.cpp │ ├── 11724.cpp │ ├── 1260.cpp │ ├── 1325.cpp │ ├── 1389.cpp │ ├── 1389_1.cpp │ ├── 1707.cpp │ ├── 2606.cpp │ ├── 2617.cpp │ ├── 2660.cpp │ ├── 5214.cpp │ ├── 5567.cpp │ └── 6118.cpp ├── 0x19 ├── 11725.cpp ├── 1991.cpp └── solutions │ ├── 1068.cpp │ ├── 1068_1.cpp │ ├── 1167.cpp │ ├── 1167_1.cpp │ ├── 11725.cpp │ ├── 1240.cpp │ ├── 14267.cpp │ ├── 15681.cpp │ ├── 1967.cpp │ ├── 1967_1.cpp │ ├── 1991.cpp │ ├── 20955.cpp │ ├── 20955_1.cpp │ ├── 2250.cpp │ ├── 22856.cpp │ ├── 2533.cpp │ └── 4803.cpp ├── 0x1A ├── 2252.cpp └── solutions │ ├── 1005.cpp │ ├── 1005_1.cpp │ ├── 1766.cpp │ ├── 2056.cpp │ ├── 21276.cpp │ ├── 2252.cpp │ ├── 2623.cpp │ └── 2637.cpp ├── 0x1B ├── 1197_1.cpp ├── 1197_2.cpp ├── 1368.cpp └── solutions │ ├── 10423.cpp │ ├── 1197.cpp │ ├── 1197_1.cpp │ ├── 13418.cpp │ ├── 1368.cpp │ ├── 1368_1.cpp │ ├── 16398.cpp │ ├── 16398_1.cpp │ ├── 1647.cpp │ ├── 1774.cpp │ ├── 2887.cpp │ └── 9372.cpp ├── 0x1C ├── 11404.cpp ├── 11780.cpp └── solutions │ ├── 11404.cpp │ ├── 11562.cpp │ ├── 11780.cpp │ ├── 13141.cpp │ ├── 13168.cpp │ ├── 13314.cpp │ ├── 14938.cpp │ ├── 1507.cpp │ ├── 1602.cpp │ ├── 17182.cpp │ ├── 1719.cpp │ ├── 1956.cpp │ ├── 21940.cpp │ ├── 23258.cpp │ └── 23286.cpp ├── 0x1D ├── 11779.cpp ├── 1753.cpp └── solutions │ ├── 1162.cpp │ ├── 11779.cpp │ ├── 1238.cpp │ ├── 1261.cpp │ ├── 13907.cpp │ ├── 1504.cpp │ ├── 1753.cpp │ ├── 17835.cpp │ ├── 1854.cpp │ ├── 1916.cpp │ ├── 20183.cpp │ ├── 22870.cpp │ ├── 24042.cpp │ └── 5719.cpp ├── 0x1E ├── 16916.cpp ├── solutions │ ├── 10266.cpp │ ├── 11585.cpp │ ├── 1305.cpp │ ├── 16172.cpp │ ├── 16916.cpp │ ├── 1786.cpp │ ├── 1893.cpp │ └── 4354.cpp └── string_example.cpp ├── 0x1F ├── 14425.cpp ├── solutions │ ├── 14425.cpp │ ├── 14426.cpp │ ├── 14725.cpp │ ├── 16906.cpp │ ├── 16934.cpp │ ├── 5052.cpp │ ├── 5446.cpp │ ├── 5670.cpp │ ├── 7432.cpp │ └── 9202.cpp └── trie_example.cpp ├── Appendix A ├── 1543.cpp ├── 2941.cpp ├── solutions │ ├── 1213.cpp │ ├── 15312.cpp │ ├── 1543.cpp │ ├── 16113.cpp │ ├── 16719.cpp │ ├── 17413.cpp │ ├── 1969.cpp │ ├── 23304.cpp │ ├── 2870.cpp │ ├── 2941.cpp │ ├── 2999.cpp │ ├── 3107.cpp │ ├── 3613.cpp │ ├── 6581.cpp │ ├── 9536.cpp │ ├── 9536_1.cpp │ └── 9996.cpp └── string_example.cpp ├── Appendix B ├── dynamic_array_test.cpp └── dynamic_array_test_ans.cpp ├── Appendix C ├── 11723_1.cpp ├── 11723_2.cpp ├── 1497.cpp └── solutions │ ├── 11723.cpp │ ├── 1497.cpp │ ├── 15787.cpp │ ├── 17114.cpp │ ├── 2064.cpp │ ├── 24389.cpp │ └── 2961.cpp ├── Appendix D ├── 1717.cpp ├── 7511.cpp ├── solutions │ ├── 10775.cpp │ ├── 14595.cpp │ ├── 1717.cpp │ ├── 17619.cpp │ ├── 18116.cpp │ ├── 1976.cpp │ ├── 20040.cpp │ ├── 2162.cpp │ └── 7511.cpp └── union-find.cpp ├── Appendix E ├── 1005.cpp ├── 12865.cpp ├── 1351.cpp ├── 1915.cpp ├── 1937.cpp ├── 1949.cpp ├── 9084.cpp ├── 9251.cpp └── solutions │ ├── 1005.cpp │ ├── 10942.cpp │ ├── 11660.cpp │ ├── 12784.cpp │ ├── 12865.cpp │ ├── 1351.cpp │ ├── 1520.cpp │ ├── 1699.cpp │ ├── 1915.cpp │ ├── 1937.cpp │ ├── 1949.cpp │ ├── 2011.cpp │ ├── 21276.cpp │ ├── 2133.cpp │ ├── 2294.cpp │ ├── 24232.cpp │ ├── 2482.cpp │ ├── 25515.cpp │ ├── 2611.cpp │ ├── 27501.cpp │ ├── 3665.cpp │ ├── 9084.cpp │ ├── 9251.cpp │ ├── 9655.cpp │ ├── 9655_1.cpp │ ├── 9657.cpp │ └── 9665.cpp ├── README.md ├── docs ├── how-to-ask.md └── solution-request.md ├── workbook.md └── workbook ├── 0x02.md ├── 0x03.md ├── 0x04.md ├── 0x05.md ├── 0x06.md ├── 0x07.md ├── 0x08.md ├── 0x09.md ├── 0x0B.md ├── 0x0C.md ├── 0x0D.md ├── 0x0E.md ├── 0x0F.md ├── 0x10.md ├── 0x11.md ├── 0x12.md ├── 0x13.md ├── 0x14.md ├── 0x15.md ├── 0x16.md ├── 0x17.md ├── 0x18.md ├── 0x19.md ├── 0x1A.md ├── 0x1B.md ├── 0x1C.md ├── 0x1D.md ├── 0x1E.md ├── 0x1F.md ├── Appendix A.md ├── Appendix C.md ├── Appendix D.md ├── Appendix E.md ├── actions.py ├── links.txt └── problems.txt /0x02/solutions/1000.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : sihyeon-kim 3 | // http://boj.kr/239db99c29924302b0a9237910e0a26d 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int a, b; 11 | cin >> a >> b; 12 | cout << a + b; 13 | } 14 | -------------------------------------------------------------------------------- /0x02/solutions/10093.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : pha-ran (soft18) 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/c6e91442976c4a2a8e6c626462aceced 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | long long a, b; 12 | cin >> a >> b; 13 | if (a > b) swap(a,b); 14 | if (a == b || b - a == 1) cout << 0; 15 | else { 16 | cout << b - a - 1 << "\n"; 17 | for(long long i = a+1; i < b; i++) 18 | cout << i << " "; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x02/solutions/10171.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : twinkite 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/953c8f3733c340d89f75b10453622f19 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | cout << "\\ /\\" << '\n'; 12 | cout << " ) ( \')" << '\n'; 13 | cout << "( / )" << '\n'; 14 | cout << " \\(__)|"; 15 | } 16 | -------------------------------------------------------------------------------- /0x02/solutions/10804.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/443a4e33d87c4916956eb95218bad0ac 4 | #include 5 | using namespace std; 6 | 7 | int num[21]; 8 | 9 | // 카드를 역순으로 놓는 함수 10 | void reverse(int a, int b){ 11 | for(int i = 0; i < (b - a + 1) / 2; i++) 12 | swap(num[a+i], num[b-i]); 13 | } 14 | 15 | int main(void){ 16 | ios::sync_with_stdio(0); 17 | cin.tie(0); 18 | 19 | for(int i = 1; i <= 20; i++) num[i] = i; 20 | 21 | for(int i = 1; i <= 10; i++) { 22 | int a, b; 23 | cin >> a >> b; 24 | reverse(a, b); 25 | } 26 | 27 | for(int i = 1; i <= 20; i++) cout << num[i] << ' '; 28 | } 29 | -------------------------------------------------------------------------------- /0x02/solutions/10804_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/4c29334a05624e9b88fde38677834a97 4 | #include 5 | using namespace std; 6 | 7 | int num[21]; 8 | 9 | int main(void){ 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | for(int i = 1; i <= 20; i++) num[i] = i; 14 | 15 | for(int i = 1; i <= 10; i++) { 16 | int a, b; 17 | cin >> a >> b; 18 | reverse(num+a, num+b+1); 19 | } 20 | 21 | for(int i = 1; i <= 20; i++) cout << num[i] << ' '; 22 | } 23 | 24 | /* 25 | STL reverse를 이용한 풀이 26 | */ 27 | -------------------------------------------------------------------------------- /0x02/solutions/10869.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/928e2846ee944751ac277ec16a3cb9e3 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int A, B; 12 | cin >> A >> B; 13 | 14 | cout << A + B << "\n"; 15 | cout << A - B << "\n"; 16 | cout << A * B << "\n"; 17 | cout << A / B << "\n"; 18 | cout << A % B << "\n"; 19 | } -------------------------------------------------------------------------------- /0x02/solutions/10871.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/b140362e3257436a8d4b19ef50dad9c2 4 | #include 5 | using namespace std; 6 | 7 | int n, x, a[10005]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n >> x; 12 | for(int i = 0; i < n; i++) cin >> a[i]; 13 | for(int i = 0; i < n; i++) 14 | if(a[i] < x) cout << a[i] << ' '; 15 | } -------------------------------------------------------------------------------- /0x02/solutions/1267.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/9472d4ad1d274797a4fab2edd93722af 4 | #include 5 | using namespace std; 6 | 7 | int phone[10000], Y, M; 8 | 9 | int main(void){ 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | int N; 14 | cin >> N; 15 | 16 | for(int n = 0; n < N; n++) cin >> phone[n]; 17 | 18 | for(int n = 0; n < N; n++) Y += ((phone[n] / 30) + 1) * 10; 19 | 20 | for(int n = 0; n < N; n++) M += ((phone[n] / 60) + 1) * 15; 21 | 22 | if(Y < M) cout << "Y " << Y; 23 | else if(Y > M) cout << "M " << M; 24 | else cout << "Y M " << Y; 25 | } -------------------------------------------------------------------------------- /0x02/solutions/15552.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/760b06ca209c4bd4992230e77255278a 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int T; 12 | cin >> T; 13 | 14 | for(int t = 0; t < T; t++){ 15 | int A, B; 16 | cin >> A >> B; 17 | 18 | cout << A + B << "\n"; 19 | } 20 | } -------------------------------------------------------------------------------- /0x02/solutions/2438.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/b6adf7a5cfeb49f7a45563ac675a6b3a 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | 14 | for(int i = 0; i < N; i++) { 15 | for(int j = 0; j <= i; j++) cout << '*'; 16 | cout << "\n"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x02/solutions/2439.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/24752bdbcfe543f9b4fbad61b5c3e46c 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | 14 | for(int i = 0; i < N; i++) { 15 | int j = 0; 16 | for( ; j < N - i - 1; j++) cout << ' '; 17 | for( ; j < N; j++) cout << '*'; 18 | cout << "\n"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x02/solutions/2440.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/541d92f7657c4d088ec50462093bbc1b 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | 14 | for(int i = 0; i < N; i++) { 15 | for(int j = 0; j < N - i; j++) cout << '*'; 16 | cout << "\n"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x02/solutions/2441.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/286ff628320c410e9e691600014cd18d 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | 14 | for(int i = 0; i < N; i++) { 15 | int j = 0; 16 | for( ; j < i; j++) cout << ' '; 17 | for( ; j < N; j++) cout << '*'; 18 | cout << "\n"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x02/solutions/2442.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/00eea29b840146edac2da552f91c0f41 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | 14 | for(int i = 1; i <= N; i++){ 15 | for(int j = 1; j <= N - i; j++) cout << ' '; 16 | for(int j = 1; j <= 2 * i - 1; j++) cout << '*'; 17 | // '*'의 오른쪽 공백은 출력하지 말아야 통과합니다. 18 | cout << "\n"; 19 | } 20 | } -------------------------------------------------------------------------------- /0x02/solutions/2443.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/043411fb280c4b0fbb3264fa5400f7a8 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | 14 | for(int i = N; i >= 1; i--){ 15 | for(int j = 1; j <= N - i; j++) cout << ' '; 16 | for(int j = 1; j <= 2 * i - 1; j++) cout << '*'; 17 | // '*'의 오른쪽 공백은 출력하지 말아야 통과합니다. 18 | cout << "\n"; 19 | } 20 | } -------------------------------------------------------------------------------- /0x02/solutions/2446.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/7026df35c02346969ab865fd2c15ad16 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | 14 | for(int i = 0; i < N - 1; i++) { 15 | for(int j = 0; j < i; j++) cout << ' '; 16 | for(int j = 0; j < 2 * (N - i) - 1; j++) cout << '*'; 17 | cout << "\n"; 18 | } 19 | 20 | for(int j = 0; j < N - 1; j++) cout << ' '; 21 | cout << "*\n"; 22 | 23 | for(int i = 1; i <= N - 1; i++) { 24 | for(int j = 1; j <= N - i - 1; j++) cout << ' '; 25 | for(int j = 1; j <= 2 * i + 1; j++) cout << '*'; 26 | cout << "\n"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /0x02/solutions/2480.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/0b6d46b39f7c4fc8afd6d0c7d21e7bad 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int a, b, c; 12 | cin >> a >> b >> c; 13 | if(a == b && b == c) cout << 10000 + a*1000; 14 | else if(a == b || a == c) cout << 1000 + a*100; 15 | else if(b == c) cout << 1000 + b*100; 16 | else cout << max({a,b,c}) * 100; 17 | } 18 | -------------------------------------------------------------------------------- /0x02/solutions/2480_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/a66f45063a2a4f1bb9816a2080077fe3 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int a[3]; 12 | cin >> a[0] >> a[1] >> a[2]; 13 | sort(a, a+3); 14 | if(a[0] == a[2]) cout << 10000 + a[0]*1000; // 세 수가 동일 15 | else if(a[0] == a[1] || a[1] == a[2]) cout << 1000 + a[1]*100; // 두 수가 동일 16 | else cout << a[2]*100; 17 | } 18 | -------------------------------------------------------------------------------- /0x02/solutions/2490.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/38cf0450b8c8458e859c486e3ea80323 4 | #include 5 | using namespace std; 6 | 7 | int result, input; 8 | string res = "DCBAE"; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | for(int r = 0; r < 3; r++) { 15 | result = 0; 16 | for(int c = 0; c < 4; c++) { 17 | cin >> input; 18 | result += input; 19 | } 20 | cout << res[result] << '\n'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /0x02/solutions/2557.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/2044f55034ab4715a9a9d677ab51bc7f 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | cout << "Hello World!"; 11 | } 12 | -------------------------------------------------------------------------------- /0x02/solutions/2562.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/e8b0bfc16a1e4c9fbe75c66e7ec6c341 4 | #include 5 | using namespace std; 6 | 7 | int n, maxvalue, maxindex; 8 | 9 | int main(void){ 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | for(int i = 1; i < 10; i++){ 14 | cin >> n; 15 | // 전역변수의 초기값은 0이므로 바로 비교 가능합니다. 16 | if(maxvalue < n){ 17 | maxvalue = n; 18 | maxindex = i; 19 | } 20 | } 21 | cout << maxvalue << "\n" << maxindex; 22 | } -------------------------------------------------------------------------------- /0x02/solutions/2562_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/359583ea75ef49f7acf7c5564827ebba 4 | #include 5 | using namespace std; 6 | 7 | int a[9]; 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | for(int i = 0; i < 9; i++) cin >> a[i]; 13 | cout << *max_element(a, a+9) << '\n'; 14 | cout << max_element(a, a+9) - a + 1; 15 | } 16 | 17 | /* 18 | max_element 함수를 이용한 풀이 19 | */ 20 | -------------------------------------------------------------------------------- /0x02/solutions/2576.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : pha-ran (soft18) 2 | // Co-authored by : - 3 | // http://boj.kr/c2a05cf9d222441dba79bba4e9ac5b6e 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int x, odd = 0, sum = 0, min = 100; 12 | 13 | for (int i = 0; i < 7; i++) { 14 | cin >> x; 15 | 16 | if (x & 1) { 17 | odd += 1; 18 | sum += x; 19 | 20 | if (x < min) { 21 | min = x; 22 | } 23 | } 24 | } 25 | 26 | if (odd) cout << sum << "\n" << min; 27 | else cout << "-1"; 28 | } -------------------------------------------------------------------------------- /0x02/solutions/2577.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/ad5720bb26524654aa714a5f51ddc0e4 4 | #include 5 | using namespace std; 6 | 7 | int num[10]; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | int A, B, C, total; 14 | cin >> A >> B >> C; 15 | total = A * B * C; 16 | 17 | while(total > 0) { 18 | num[total % 10]++; 19 | total /= 10; 20 | } 21 | 22 | for(int i = 0; i < 10; i++) cout << num[i] << "\n"; 23 | } -------------------------------------------------------------------------------- /0x02/solutions/2587.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/3f4f42b54653435ab38e16a902368184 4 | #include 5 | using namespace std; 6 | 7 | int num[5], total; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | for(int i = 0; i < 5; i++) cin >> num[i]; 14 | 15 | // 평균 16 | for(int i = 0; i < 5; i++) total += num[i]; 17 | cout << total / 5 << "\n"; 18 | 19 | // 중앙값 20 | sort(num, num + 5); 21 | cout << num[2]; 22 | } -------------------------------------------------------------------------------- /0x02/solutions/2752.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/c58003e0efd546baad2e58671aa8f7f3 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int a, b, c; // 입력 12 | cin >> a >> b >> c; 13 | int d, e, f; // 크기 순으로 출력할 세 수 14 | d = min({a,b,c}); 15 | f = max({a,b,c}); 16 | e = a+b+c-d-f; 17 | cout << d << ' ' << e << ' ' << f; 18 | } 19 | -------------------------------------------------------------------------------- /0x02/solutions/2752_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : twinkite 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/47ed3d4621a546b28422297d8fb6a7ba 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int arr[4]; 12 | for(int i=0;i<3;i++){ 13 | cin>>arr[i]; 14 | } 15 | sort(arr, arr+3); 16 | for(int i=0;i<3;i++){ 17 | cout< 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int year; 12 | cin >> year; 13 | 14 | if(year % 4 == 0){ 15 | // 4의 배수이면서 400의 배수 16 | if(year % 400 == 0) cout << 1; 17 | // 4의 배수이면서 100의 배수 18 | else if(year % 100 == 0) cout << 0; 19 | // 4의 배수이면서 100, 400의 배수가 아닌 수 20 | else cout << 1; 21 | } 22 | // 4의 배수가 아닌 수 23 | else cout << 0; 24 | } 25 | -------------------------------------------------------------------------------- /0x02/solutions/9498.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : wogha95 2 | // Co-authored by : - 3 | // http://boj.kr/b077642563084c938e85e4396993fd6b 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int score; 12 | cin >> score; 13 | 14 | if(90 <= score && score <= 100) cout << 'A'; 15 | else if(80 <= score) cout << 'B'; 16 | else if(70 <= score) cout << 'C'; 17 | else if(60 <= score) cout << 'D'; 18 | else cout << 'F'; 19 | } -------------------------------------------------------------------------------- /0x03/10808_1.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/ece8236c02cf46aba9933f28e358b51c 2 | #include 3 | using namespace std; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); 7 | cin.tie(0); 8 | string s; 9 | cin >> s; 10 | for(char a = 'a'; a <= 'z'; a++){ 11 | int cnt = 0; 12 | for(auto c : s) 13 | if(a == c) cnt++; 14 | cout << cnt << ' '; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /0x03/10808_2.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/d7178d89538a42ababf4455443e60fe2 2 | #include 3 | using namespace std; 4 | 5 | int freq[26]; 6 | int main(void) { 7 | ios::sync_with_stdio(0); 8 | cin.tie(0); 9 | string s; 10 | cin >> s; 11 | for(auto c : s) 12 | freq[c-'a']++; 13 | for(int i = 0; i < 26; i++) 14 | cout << freq[i] << ' '; 15 | } 16 | -------------------------------------------------------------------------------- /0x03/func2_ans.cpp: -------------------------------------------------------------------------------- 1 | int func2(int arr[], int N){ 2 | int occur[101] = {}; 3 | for(int i = 0; i < N; i++){ 4 | if(occur[100-arr[i]] == 1) 5 | return 1; 6 | occur[arr[i]] = 1; 7 | } 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /0x03/solutions/10807.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : OceanShape 2 | // Co-authored by : - 3 | // http://boj.kr/52f2aac1e7fd4287b3c136159a533c9b 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | // -100 <= v && v <= 100 이므로 음수도 저장할 수 있는 공간을 배열에 추가 12 | int N, v, a[201] = {}; 13 | cin >> N; 14 | 15 | // 입력값을 배열에 저장 16 | while(N--){ 17 | int t; 18 | cin >> t; 19 | // 음수도 인덱스로 접근하기 위해 기존 인덱스+100으로 배열에 저장 20 | a[t+100]++; 21 | } 22 | 23 | // v의 개수를 배열에서 확인 24 | cin >> v; 25 | cout << a[v+100]; 26 | } 27 | -------------------------------------------------------------------------------- /0x03/solutions/10808.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/d7178d89538a42ababf4455443e60fe2 4 | #include 5 | using namespace std; 6 | 7 | int freq[26]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | string s; 12 | cin >> s; 13 | for(auto c : s) 14 | freq[c-'a']++; 15 | for(int i = 0; i < 26; i++) 16 | cout << freq[i] << ' '; 17 | } -------------------------------------------------------------------------------- /0x03/solutions/13300.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : OceanShape 2 | // Co-authored by : - 3 | // http://boj.kr/da61fda65b7d4d7c96fde827da8d1834 4 | #include 5 | using namespace std; 6 | 7 | int N, K, ans=0; 8 | int s[2][7]={}; // 성별/반별 학생 수를 저장하는 배열 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> N >> K; 15 | // 학생 수 저장 16 | for (int i=0; i> a >> b; 19 | s[a][b]++; 20 | } 21 | 22 | // 필요한 방의 개수 계산 23 | for (int i=0; i<2; ++i) { 24 | for (int j=1; j<7; ++j) { 25 | // 배정에 필요한 만큼 방의 개수 추가 26 | ans += s[i][j] / K; 27 | // 학생이 남을 경우, 하나의 방이 더 필요하므로 방의 개수 추가 28 | if (s[i][j] % K) ++ans; 29 | } 30 | } 31 | cout << ans; 32 | } 33 | -------------------------------------------------------------------------------- /0x03/solutions/1475.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : OceanShape 2 | // Co-authored by : BaaaaaaaaaaarkingDog, kiiimiiin 3 | // http://boj.kr/a7a4aa95c4ee446990f868f926993161 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N, a[10] = {}, ans = 0; 12 | cin >> N; 13 | 14 | // 자리수 추출 15 | while(N){ 16 | a[N%10]++; 17 | N /= 10; 18 | } 19 | 20 | for(int i = 0; i < 10; i++){ 21 | if(i == 6 || i == 9) continue; 22 | ans = max(ans, a[i]); 23 | } 24 | // (a[6]+a[9])/2를 올림한 값이 6, 9에 대한 필요한 세트의 수이므로 (a[6]+a[9]+1)/2을 계산 25 | ans = max(ans, (a[6]+a[9]+1)/2); 26 | cout << ans; 27 | } 28 | -------------------------------------------------------------------------------- /0x03/solutions/1919.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : twinkite 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/ae5d8d2f69f04530b4df0c591e9b07d5 4 | #include 5 | using namespace std; 6 | 7 | int arr[2][26], res; 8 | string s1, s2; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin>>s1>>s2; 15 | for(char c : s1) 16 | arr[0][c-'a']++; 17 | 18 | for(char c : s2) 19 | arr[1][c-'a']++; 20 | 21 | for(int i=0; i<26; i++) 22 | res += abs(arr[0][i]-arr[1][i]); 23 | 24 | cout << res; 25 | } 26 | -------------------------------------------------------------------------------- /0x03/solutions/2577.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : OceanShape 3 | // http://boj.kr/fefbce1d30c9442db611909c690df1a8 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int A, B, C; 11 | cin >> A >> B >> C; 12 | int t=A*B*C; 13 | int d[10] = {}; 14 | // 계산 결과를 자릿수별로 확인하여 저장 15 | while (t>0) { 16 | d[t%10]++; 17 | t/=10; 18 | } 19 | for (int i=0; i<10; ++i) cout << d[i] << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /0x03/solutions/3273.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/fc842a288ef843e49e2fe5b6a8bbcf5e 4 | #include 5 | using namespace std; 6 | 7 | int a[1000001]={}; 8 | // 각 자연수의 존재 여부를 저장하는 배열, 아래에서 x-a[i]가 1000000보다 큰 경우를 예외처리하기 싫어서 그냥 배열을 최대 200만으로 잡음 9 | bool occur[2000001]; 10 | int n, x; 11 | 12 | int main(void){ 13 | ios::sync_with_stdio(0); 14 | cin.tie(0); 15 | 16 | int ans = 0; 17 | cin >> n; 18 | for(int i = 0; i < n; i++) cin >> a[i]; 19 | cin >> x; 20 | 21 | for (int i = 0; i < n; i++) { 22 | // x-a[i]가 존재하는지 확인 23 | if(x-a[i] > 0 && occur[x-a[i]]) ans++; 24 | occur[a[i]] = true; 25 | } 26 | cout << ans; 27 | } 28 | 29 | /* 30 | 공간복잡도 O(2000000), 시간복잡도 O(n)에 풀이가 가능. 만약 입력 형식에서 31 | x가 a 배열보다 먼저 주어졌다면 int a[] 배열은 필요가 없었음. 32 | */ 33 | -------------------------------------------------------------------------------- /0x03/vector_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | vector v1(3, 5); // {5,5,5}; 6 | cout << v1.size() << '\n'; // 3 7 | v1.push_back(7); // {5,5,5,7}; 8 | 9 | vector v2(2); // {0,0}; 10 | v2.insert(v2.begin()+1, 3); // {0,3,0}; 11 | 12 | vector v3 = {1,2,3,4}; // {1,2,3,4} 13 | v3.erase(v3.begin()+2); // {1,2,4}; 14 | 15 | vector v4; // {} 16 | v4 = v3; // {1,2,4} 17 | cout << v4[0] << v4[1] << v4[2] << '\n'; 18 | v4.pop_back(); // {1,2} 19 | v4.clear(); // {} 20 | } 21 | -------------------------------------------------------------------------------- /0x04/list_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | list L = {1,2}; // 1 2 6 | list::iterator t = L.begin(); // t는 1을 가리키는 중 7 | L.push_front(10); // 10 1 2 8 | cout << *t << '\n'; // t가 가리키는 값 = 1을 출력 9 | L.push_back(5); // 10 1 2 5 10 | L.insert(t, 6); // t가 가리키는 곳 앞에 6을 삽입, 10 6 1 2 5 11 | t++; // t를 1칸 앞으로 전진, 현재 t가 가리키는 값은 2 12 | t = L.erase(t); // t가 가리키는 값을 제거, 그 다음 원소인 5의 위치를 반환 13 | // 10 6 1 5, t가 가리키는 값은 5 14 | cout << *t << '\n'; // 5 15 | for(auto i : L) cout << i << ' '; 16 | cout << '\n'; 17 | for(list::iterator it = L.begin(); it != L.end(); it++) 18 | cout << *it << ' '; 19 | } 20 | -------------------------------------------------------------------------------- /0x04/solutions/1158_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : haneulkimdev 2 | // Co-authored by : - 3 | // http://boj.kr/4ef85f8d8d834deb8b8ae054d249fff9 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n, k; 11 | cin >> n >> k; 12 | queue Q; 13 | for (int i = 1; i <= n; i++) Q.push(i); 14 | cout << '<'; 15 | while (!Q.empty()) { 16 | for (int i = 0; i < k - 1; i++) { 17 | Q.push(Q.front()); 18 | Q.pop(); 19 | } 20 | cout << Q.front(); 21 | Q.pop(); 22 | if (Q.size()) cout << ", "; 23 | } 24 | cout << '>'; 25 | } 26 | 27 | /* 28 | STL queue를 이용한 풀이 29 | */ 30 | -------------------------------------------------------------------------------- /0x05/10828_1.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/c792146f735b42559e8cb3bf21e61fa9 2 | #include 3 | using namespace std; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); 7 | cin.tie(0); 8 | int n; 9 | cin >> n; 10 | stack S; 11 | while(n--){ // n번 반복 12 | string c; 13 | cin >> c; 14 | if(c=="push"){ 15 | int t; 16 | cin >> t; 17 | S.push(t); 18 | } 19 | else if(c=="pop"){ 20 | if(S.empty()) cout << -1 << '\n'; 21 | else{ 22 | cout << S.top() << '\n'; 23 | S.pop(); 24 | } 25 | } 26 | else if(c=="size") 27 | cout << S.size() << '\n'; 28 | else if(c=="empty") 29 | cout << (int)S.empty() << '\n'; 30 | else{ // top 31 | if(S.empty()) cout << -1 << '\n'; 32 | else cout << S.top() << '\n'; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /0x05/solutions/10773.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : OceanShape 2 | // Co-authored by : - 3 | // http://boj.kr/572b87aed4eb43d9b9084797f5fbace2 4 | #include 5 | using namespace std; 6 | 7 | int K, ans = 0; 8 | stack s; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> K; 15 | while(K--){ 16 | int n; 17 | cin >> n; 18 | if(n == 0) s.pop(); // 0을 입력할 경우, 가장 최신값(s.top()) 제거 19 | else s.push(n); // 0 이외의 수를 입력할 경우, 스택에 추가 20 | } 21 | 22 | // 스택에 쌓여 있는 모든 값을 더해줌 23 | while(!s.empty()){ 24 | ans += s.top(); 25 | s.pop(); 26 | } 27 | cout << ans; 28 | } 29 | -------------------------------------------------------------------------------- /0x05/solutions/17298.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : haneulkimdev 2 | // Co-authored by : - 3 | // http://boj.kr/98a57090ad0b472f86492f495a362127 4 | #include 5 | using namespace std; 6 | 7 | int a[1000000]; 8 | int ans[1000000]; 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | int n; 13 | cin >> n; 14 | for (int i = 0; i < n; i++) cin >> a[i]; 15 | stack S; 16 | for (int i = n - 1; i >= 0; i--) { 17 | while (!S.empty() && S.top() <= a[i]) S.pop(); 18 | if (S.empty()) 19 | ans[i] = -1; 20 | else 21 | ans[i] = S.top(); 22 | S.push(a[i]); 23 | } 24 | for (int i = 0; i < n; i++) cout << ans[i] << ' '; 25 | } 26 | -------------------------------------------------------------------------------- /0x05/solutions/2493.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : twinkite 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/44465623025e452bba5feb80b0b0e60e 4 | #include 5 | using namespace std; 6 | #define X first 7 | #define Y second 8 | 9 | int N; 10 | stack> tower; 11 | 12 | int main() { 13 | ios_base::sync_with_stdio(0); 14 | cin.tie(0); 15 | 16 | cin >> N; 17 | tower.push({100000001, 0}); 18 | for (int i = 1; i <= N; i++) { 19 | int height; 20 | cin >> height; 21 | while (tower.top().X < height) 22 | tower.pop(); 23 | cout << tower.top().Y << " "; 24 | tower.push({height, i}); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x05/solutions/3015.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : haneulkimdev 2 | // Co-authored by : - 3 | // http://boj.kr/cbef82389d1048db80c9652d18b71304 4 | #include 5 | using namespace std; 6 | #define X first 7 | #define Y second 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | int n; 13 | cin >> n; 14 | stack> S; 15 | long long ans = 0; 16 | while (n--) { 17 | int h; 18 | cin >> h; 19 | int cnt = 1; 20 | while (!S.empty() && S.top().X <= h) { 21 | ans += S.top().Y; 22 | if (S.top().X == h) cnt += S.top().Y; 23 | S.pop(); 24 | } 25 | if (!S.empty()) ans++; 26 | S.push({h, cnt}); 27 | } 28 | cout << ans; 29 | } 30 | -------------------------------------------------------------------------------- /0x05/solutions/6198.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : unluckyjung 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/a84f083cdee3436f9f46acdef175e55f 4 | 5 | #include 6 | using namespace std; 7 | 8 | #define ll long long 9 | 10 | stack s; 11 | int n; 12 | ll ans; 13 | 14 | int main() { 15 | ios_base::sync_with_stdio(0); 16 | cin.tie(0); 17 | 18 | cin >> n; 19 | ll h; 20 | while (n--) { 21 | cin >> h; 22 | while(!s.empty() && s.top() <= h) 23 | s.pop(); 24 | ans += s.size(); 25 | s.push(h); 26 | } 27 | cout << ans; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /0x05/stack_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | stack S; 6 | S.push(10); // 10 7 | S.push(20); // 10 20 8 | S.push(30); // 10 20 30 9 | cout << S.size() << '\n'; // 3 10 | if(S.empty()) cout << "S is empty\n"; 11 | else cout << "S is not empty\n"; // S is not empty 12 | S.pop(); // 10 20 13 | cout << S.top() << '\n'; // 20 14 | S.pop(); // 10 15 | cout << S.top() << '\n'; // 10 16 | S.pop(); // empty 17 | if(S.empty()) cout << "S is empty\n"; // S is empty 18 | cout << S.top() << '\n'; // runtime error 발생 19 | } 20 | -------------------------------------------------------------------------------- /0x05/stack_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int MX = 1000005; 5 | int dat[MX]; 6 | int pos = 0; 7 | 8 | void push(int x){ 9 | 10 | } 11 | 12 | void pop(){ 13 | 14 | } 15 | 16 | int top(){ 17 | 18 | } 19 | 20 | void test(){ 21 | push(5); push(4); push(3); 22 | cout << top() << '\n'; // 3 23 | pop(); pop(); 24 | cout << top() << '\n'; // 5 25 | push(10); push(12); 26 | cout << top() << '\n'; // 12 27 | pop(); 28 | cout << top() << '\n'; // 10 29 | } 30 | 31 | int main(void) { 32 | test(); 33 | } 34 | -------------------------------------------------------------------------------- /0x05/stack_test_ans.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int MX = 1000005; 5 | int dat[MX]; 6 | int pos = 0; 7 | 8 | void push(int x){ 9 | dat[pos++] = x; 10 | } 11 | 12 | void pop(){ 13 | pos--; 14 | } 15 | 16 | int top(){ 17 | return dat[pos-1]; 18 | } 19 | 20 | void test(){ 21 | push(5); push(4); push(3); 22 | cout << top() << '\n'; // 3 23 | pop(); pop(); 24 | cout << top() << '\n'; // 5 25 | push(10); push(12); 26 | cout << top() << '\n'; // 12 27 | pop(); 28 | cout << top() << '\n'; // 10 29 | } 30 | 31 | int main(void) { 32 | test(); 33 | } 34 | -------------------------------------------------------------------------------- /0x06/queue_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void) { 5 | queue Q; 6 | Q.push(10); // 10 7 | Q.push(20); // 10 20 8 | Q.push(30); // 10 20 30 9 | cout << Q.size() << '\n'; // 3 10 | if(Q.empty()) cout << "Q is empty\n"; 11 | else cout << "Q is not empty\n"; // Q is not empty 12 | Q.pop(); // 20 30 13 | cout << Q.front() << '\n'; // 20 14 | cout << Q.back() << '\n'; // 30 15 | Q.push(40); // 20 30 40 16 | Q.pop(); // 30 40 17 | cout << Q.front() << '\n'; // 30 18 | } 19 | -------------------------------------------------------------------------------- /0x06/queue_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int MX = 1000005; 5 | int dat[MX]; 6 | int head = 0, tail = 0; 7 | 8 | void push(int x){ 9 | 10 | } 11 | 12 | void pop(){ 13 | 14 | } 15 | 16 | int front(){ 17 | 18 | } 19 | 20 | int back(){ 21 | 22 | } 23 | 24 | void test(){ 25 | push(10); push(20); push(30); 26 | cout << front() << '\n'; // 10 27 | cout << back() << '\n'; // 30 28 | pop(); pop(); 29 | push(15); push(25); 30 | cout << front() << '\n'; // 30 31 | cout << back() << '\n'; // 25 32 | } 33 | 34 | int main(void) { 35 | test(); 36 | } 37 | -------------------------------------------------------------------------------- /0x06/queue_test_ans.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int MX = 1000005; 5 | int dat[MX]; 6 | int head = 0, tail = 0; 7 | 8 | void push(int x){ 9 | dat[tail++] = x; 10 | } 11 | 12 | void pop(){ 13 | head++; 14 | } 15 | 16 | int front(){ 17 | return dat[head]; 18 | } 19 | 20 | int back(){ 21 | return dat[tail-1]; 22 | } 23 | 24 | void test(){ 25 | push(10); push(20); push(30); 26 | cout << front() << '\n'; // 10 27 | cout << back() << '\n'; // 30 28 | pop(); pop(); 29 | push(15); push(25); 30 | cout << front() << '\n'; // 30 31 | cout << back() << '\n'; // 25 32 | } 33 | 34 | int main(void) { 35 | test(); 36 | } 37 | -------------------------------------------------------------------------------- /0x06/solutions/2164.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : OceanShape 2 | // Co-authored by : - 3 | // http://boj.kr/de9183460fa945a69e8692510b3fd803 4 | #include 5 | using namespace std; 6 | 7 | int N; 8 | queue q; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> N; 15 | for(int i = 1; i <= N; ++i) q.push(i); 16 | while(q.size() != 1){ 17 | q.pop(); 18 | int tmp = q.front(); 19 | q.push(tmp); 20 | q.pop(); 21 | } 22 | cout << q.front(); 23 | } 24 | -------------------------------------------------------------------------------- /0x07/deque_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | const int MX = 1000005; 5 | int dat[2*MX+1]; 6 | int head = MX, tail = MX; 7 | 8 | void push_front(int x){ 9 | 10 | } 11 | 12 | void push_back(int x){ 13 | 14 | } 15 | 16 | void pop_front(){ 17 | 18 | } 19 | 20 | void pop_back(){ 21 | 22 | } 23 | 24 | int front(){ 25 | 26 | } 27 | 28 | int back(){ 29 | 30 | } 31 | 32 | void test(){ 33 | push_back(30); // 30 34 | cout << front() << '\n'; // 30 35 | cout << back() << '\n'; // 30 36 | push_front(25); // 25 30 37 | push_back(12); // 25 30 12 38 | cout << back() << '\n'; // 12 39 | push_back(62); // 25 30 12 62 40 | pop_front(); // 30 12 62 41 | cout << front() << '\n'; // 30 42 | pop_front(); // 12 62 43 | cout << back() << '\n'; // 62 44 | } 45 | 46 | int main(void){ 47 | test(); 48 | } 49 | -------------------------------------------------------------------------------- /0x07/solutions/11003_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : scsc3204 2 | // Co-authored by : - 3 | // http://boj.kr/102f4219c84648288e5aac38a46c9e40 4 | #include 5 | using namespace std; 6 | 7 | priority_queue , 8 | vector>, 9 | greater>> pq; 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | int n, m; 16 | cin >> n >> m; 17 | 18 | int x, idx, cur; 19 | for(int i = 0; i < n; i++) { 20 | cin >> x; 21 | pq.push({x, i}); 22 | tie(cur, idx) = pq.top(); 23 | while(idx < max(0, i - m + 1)) { 24 | pq.pop(); 25 | tie(cur, idx) = pq.top(); 26 | } 27 | cout << cur << ' '; 28 | } 29 | } 30 | /* 31 | 우선순위 큐를 이용한 풀이 32 | */ 33 | -------------------------------------------------------------------------------- /0x08/solutions/3986.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : yongjunleeme 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/216c90b92a494e9ba701e13ca9b7d7aa 4 | #include 5 | using namespace std; 6 | 7 | int n, ans = 0; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> n; 14 | while (n--) { 15 | string a; 16 | cin >> a; 17 | stack S; 18 | for (auto c : a) { 19 | if (!S.empty() && S.top() == c) S.pop(); 20 | else S.push(c); 21 | } 22 | if (S.empty()) ans++; 23 | } 24 | cout << ans << "\n"; 25 | } 26 | -------------------------------------------------------------------------------- /0x08/solutions/4889.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/431d0c16ab78498898a51fe2334cdafb 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int ord = 0; 11 | while(true){ 12 | ord++; 13 | string a; 14 | getline(cin, a); 15 | if(a[0]=='-')break; 16 | int cnt = 0; 17 | int ans = 0; 18 | for(auto c : a){ 19 | if(c=='{') cnt++; 20 | else{ 21 | cnt--; 22 | if(cnt == -1){ 23 | cnt=1; 24 | ans++; 25 | } 26 | } 27 | } 28 | ans += cnt/2; 29 | cout << ord << ". " << ans << '\n'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /0x08/solutions/9012.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : haneulkimdev 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/6d1d0cec49bb4e0d94616c2ab82a3688 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n; 11 | cin >> n; 12 | while (n--) { 13 | string a; 14 | cin >> a; 15 | stack s; 16 | bool is_valid = true; 17 | for (auto c : a) { 18 | if (c == '(') 19 | s.push(c); 20 | else { // c == ')' 21 | if (s.empty() || s.top() != '(') { 22 | is_valid = false; 23 | break; 24 | } 25 | s.pop(); 26 | } 27 | } 28 | if (!s.empty()) is_valid = false; 29 | 30 | if (is_valid) cout << "YES\n"; 31 | else cout << "NO\n"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /0x09/1697.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/ba53d62b7651443cbf7b2028c28ce197 2 | #include 3 | using namespace std; 4 | #define X first 5 | #define Y second 6 | int dist[100002]; 7 | int n,k; 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n >> k; 12 | fill(dist, dist+100001,-1); 13 | dist[n] = 0; 14 | queue Q; 15 | Q.push(n); 16 | while(dist[k] == -1){ 17 | int cur = Q.front(); Q.pop(); 18 | for(int nxt : {cur-1, cur+1, 2*cur}){ 19 | if(nxt < 0 || nxt > 100000) continue; 20 | if(dist[nxt] != -1) continue; 21 | dist[nxt] = dist[cur]+1; 22 | Q.push(nxt); 23 | } 24 | } 25 | cout << dist[k]; 26 | } 27 | -------------------------------------------------------------------------------- /0x09/pair_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void){ 5 | pair t1 = make_pair(10, 13); 6 | pair t2 = {4, 6}; // C++11 7 | cout << t2.first << ' ' << t2.second << '\n'; // 4 6 8 | if(t2 < t1) cout << "t2 < t1"; // t2 < t1 9 | } 10 | -------------------------------------------------------------------------------- /0x09/solutions/1697.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/ba53d62b7651443cbf7b2028c28ce197 4 | #include 5 | using namespace std; 6 | #define X first 7 | #define Y second 8 | int dist[100002]; 9 | int n,k; 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> n >> k; 14 | fill(dist, dist+100001,-1); 15 | dist[n] = 0; 16 | queue Q; 17 | Q.push(n); 18 | while(dist[k] == -1){ 19 | int cur = Q.front(); Q.pop(); 20 | for(int nxt : {cur-1, cur+1, 2*cur}){ 21 | if(nxt < 0 || nxt > 100000) continue; 22 | if(dist[nxt] != -1) continue; 23 | dist[nxt] = dist[cur]+1; 24 | Q.push(nxt); 25 | } 26 | } 27 | cout << dist[k]; 28 | } -------------------------------------------------------------------------------- /0x09/solutions/5014.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : std-freejia 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/8f34874217304e3ca3a499f672788d70 4 | #include 5 | using namespace std; 6 | 7 | int f, s, g, u, d; 8 | int dist[1000002]; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> f >> s >> g >> u >> d; 15 | fill(dist+1, dist+f+1, -1); 16 | 17 | queue q; 18 | dist[s] = 0; // 현재 위치의 거리를 0으로 둠 19 | q.push(s); // s층에서 시작 20 | while(!q.empty()){ 21 | int cur = q.front(); q.pop(); 22 | for(auto nxt : {cur + u, cur - d}){ 23 | if(nxt > f || nxt <= 0 || dist[nxt] != -1) continue; 24 | dist[nxt] = dist[cur] + 1; 25 | q.push(nxt); 26 | } 27 | } 28 | 29 | if(dist[g] == -1) cout << "use the stairs"; 30 | else cout << dist[g]; 31 | } 32 | -------------------------------------------------------------------------------- /0x0B/1074.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/fd805e1226e949f9b6b2eff59e5be642 2 | #include 3 | using namespace std; 4 | 5 | int func(int n, int r, int c){ 6 | if(n == 0) return 0; 7 | int half = 1<<(n-1); 8 | if(r < half && c < half) return func(n-1, r, c); 9 | if(r < half && c >= half) return half*half + func(n-1, r, c-half); 10 | if(r >= half && c < half) return 2*half*half + func(n-1, r-half, c); 11 | return 3*half*half + func(n-1, r-half, c-half); 12 | } 13 | 14 | int main(void){ 15 | ios::sync_with_stdio(0); 16 | cin.tie(0); 17 | int n, r, c; 18 | cin >> n >> r >> c; 19 | cout << func(n, r, c); 20 | } 21 | -------------------------------------------------------------------------------- /0x0B/11729.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/f2440915dca04aaa9aec759080516973 2 | #include 3 | using namespace std; 4 | 5 | void func(int a, int b, int n){ 6 | if(n == 1){ 7 | cout << a << ' ' << b << '\n'; 8 | return; 9 | } 10 | func(a, 6-a-b, n-1); 11 | cout << a << ' ' << b << '\n'; 12 | func(6-a-b, b, n-1); 13 | } 14 | 15 | int main(void){ 16 | ios::sync_with_stdio(0); 17 | cin.tie(0); 18 | int k; 19 | cin >> k; 20 | cout << (1< 3 | using namespace std; 4 | 5 | using ll = long long; 6 | 7 | ll POW(ll a, ll b, ll m){ 8 | if(b==1) return a % m; 9 | ll val = POW(a, b/2, m); 10 | val = val * val % m; 11 | if(b%2 == 0) return val; 12 | return val * a % m; 13 | } 14 | 15 | int main(void){ 16 | ios::sync_with_stdio(0); 17 | cin.tie(0); 18 | ll a,b,c; 19 | cin >> a >> b >> c; 20 | cout << POW(a,b,c); 21 | } 22 | -------------------------------------------------------------------------------- /0x0B/solutions/1074.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/fd805e1226e949f9b6b2eff59e5be642 4 | #include 5 | using namespace std; 6 | 7 | int func(int n, int r, int c){ 8 | if(n == 0) return 0; 9 | int half = 1<<(n-1); 10 | if(r < half && c < half) return func(n-1, r, c); 11 | if(r < half && c >= half) return half*half + func(n-1, r, c-half); 12 | if(r >= half && c < half) return 2*half*half + func(n-1, r-half, c); 13 | return 3*half*half + func(n-1, r-half, c-half); 14 | } 15 | 16 | int main(void){ 17 | ios::sync_with_stdio(0); 18 | cin.tie(0); 19 | int n, r, c; 20 | cin >> n >> r >> c; 21 | cout << func(n, r, c); 22 | } -------------------------------------------------------------------------------- /0x0B/solutions/11729.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/f2440915dca04aaa9aec759080516973 4 | #include 5 | using namespace std; 6 | 7 | void func(int a, int b, int n){ 8 | if(n == 1){ 9 | cout << a << ' ' << b << '\n'; 10 | return; 11 | } 12 | func(a, 6-a-b, n-1); 13 | cout << a << ' ' << b << '\n'; 14 | func(6-a-b, b, n-1); 15 | } 16 | 17 | int main(void){ 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | int k; 21 | cin >> k; 22 | cout << (1< 5 | using namespace std; 6 | 7 | using ll = long long; 8 | 9 | ll POW(ll a, ll b, ll m){ 10 | if(b==1) return a % m; 11 | ll val = POW(a, b/2, m); 12 | val = val * val % m; 13 | if(b%2 == 0) return val; 14 | return val * a % m; 15 | } 16 | 17 | int main(void){ 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | ll a,b,c; 21 | cin >> a >> b >> c; 22 | cout << POW(a,b,c); 23 | } -------------------------------------------------------------------------------- /0x0B/solutions/2447_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : cpprhtn 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/1e1d8717951a425c94049401b38053b6 4 | #include 5 | using namespace std; 6 | 7 | void print_star(int i, int j, int num) { 8 | if ((i / num) % 3 == 1 && (j / num) % 3 == 1) 9 | cout << ' '; 10 | else { 11 | if (num / 3 == 0) 12 | cout << '*'; 13 | else 14 | print_star(i, j, num / 3); 15 | } 16 | } 17 | 18 | int main(void) { 19 | ios::sync_with_stdio(0); 20 | cin.tie(0); 21 | int num; 22 | cin >> num; 23 | for (int i = 0; i < num; i++) { 24 | for (int j = 0; j < num; j++) print_star(i, j, num); 25 | cout << '\n'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /0x0B/solutions/2448_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : paulcjy 2 | // Co-authored by : - 3 | // http://boj.kr/b510439ad07b43d2b6a689ff104c3783 4 | #include 5 | using namespace std; 6 | 7 | void print_star(int n, int i, int j) { 8 | if (j <= 2*i) 9 | if (n == 3 && !(i == 1 && j == 1)) cout << '*'; 10 | else print_star(n/2, i%(n/2), j%n); 11 | else cout << ' '; 12 | } 13 | 14 | int main() { 15 | ios::sync_with_stdio(0); 16 | cin.tie(0); 17 | int n; 18 | cin >> n; 19 | for (int i = 0; i < n; i++) { 20 | cout << string(n-i-1, ' '); 21 | for (int j = 0; j <= n+i; j++) 22 | print_star(n, i, j); 23 | cout << '\n'; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /0x0C/1182.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/792d9af025724ce2912c77e8d56793d1 2 | #include 3 | using namespace std; 4 | 5 | int n, s; 6 | int arr[30]; 7 | int cnt = 0; 8 | void func(int cur, int tot){ 9 | if(cur == n){ 10 | if(tot == s) cnt++; 11 | return; 12 | } 13 | func(cur+1, tot); 14 | func(cur+1, tot+arr[cur]); 15 | } 16 | int main(void) { 17 | ios::sync_with_stdio(0); 18 | cin.tie(0); 19 | cin >> n >> s; 20 | for(int i = 0; i < n; i++) 21 | cin >> arr[i]; 22 | func(0, 0); 23 | if(s == 0) cnt--; 24 | cout << cnt; 25 | } 26 | -------------------------------------------------------------------------------- /0x0C/15649.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/f36567ec0c9f44b4b460b5b29683c27b 2 | #include 3 | using namespace std; 4 | 5 | int n,m; 6 | int arr[10]; 7 | bool isused[10]; 8 | 9 | void func(int k){ // 현재 k개까지 수를 택했음. 10 | if(k == m){ // m개를 모두 택했으면 11 | for(int i = 0; i < m; i++) 12 | cout << arr[i] << ' '; // arr에 기록해둔 수를 출력 13 | cout << '\n'; 14 | return; 15 | } 16 | 17 | for(int i = 1; i <= n; i++){ // 1부터 n까지의 수에 대해 18 | if(!isused[i]){ // 아직 i가 사용되지 않았으면 19 | arr[k] = i; // k번째 수를 i로 정함 20 | isused[i] = 1; // i를 사용되었다고 표시 21 | func(k+1); // 다음 수를 정하러 한 단계 더 들어감 22 | isused[i] = 0; // k번째 수를 i로 정한 모든 경우에 대해 다 확인했으니 i를 이제 사용되지않았다고 명시함. 23 | } 24 | } 25 | } 26 | 27 | int main(void){ 28 | ios::sync_with_stdio(0); 29 | cin.tie(0); 30 | cin >> n >> m; 31 | func(0); 32 | } 33 | -------------------------------------------------------------------------------- /0x0C/solutions/1182.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/792d9af025724ce2912c77e8d56793d1 4 | #include 5 | using namespace std; 6 | 7 | int n, s; 8 | int arr[30]; 9 | int cnt = 0; 10 | void func(int cur, int tot){ 11 | if(cur == n){ 12 | if(tot == s) cnt++; 13 | return; 14 | } 15 | func(cur+1, tot); 16 | func(cur+1, tot+arr[cur]); 17 | } 18 | int main(void) { 19 | ios::sync_with_stdio(0); 20 | cin.tie(0); 21 | cin >> n >> s; 22 | for(int i = 0; i < n; i++) 23 | cin >> arr[i]; 24 | func(0, 0); 25 | if(s == 0) cnt--; 26 | cout << cnt; 27 | } -------------------------------------------------------------------------------- /0x0C/solutions/15650_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : OceanShape700 2 | // Co-authored by : - 3 | // http://boj.kr/5378d116242244a38cd2d7fc28d8678d 4 | #include 5 | using namespace std; 6 | 7 | int N, M; 8 | vector a; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> N >> M; 14 | // M의 개수만큼 0을 넣어줌 15 | for(int i = 0; i < N; ++i) a.push_back(i < M ? 0 : 1); 16 | do{ 17 | for(int i = 0; i < N; ++i) 18 | if(a[i] == 0) cout << i+1 << ' '; 19 | cout << '\n'; 20 | }while(next_permutation(a.begin(), a.end())); 21 | } 22 | -------------------------------------------------------------------------------- /0x0C/solutions/15651.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/3220f7e9482f4564bf6d059a406fca47 4 | #include 5 | using namespace std; 6 | 7 | int n, m; 8 | int arr[10]; 9 | 10 | void func(int k){ // 현재 k개까지 수를 택했음. 11 | if(k == m){ // m개를 모두 택했으면 12 | for(int i = 0; i < m; i++) 13 | cout << arr[i] << ' '; // arr에 기록해둔 수를 출력 14 | cout << '\n'; 15 | return; 16 | } 17 | for(int i = 1; i <= n; i++){ 18 | arr[k] = i; // k번째 수를 i로 정함 19 | func(k+1); // 다음 수를 정하러 한 단계 더 들어감 20 | } 21 | } 22 | 23 | int main(void){ 24 | ios::sync_with_stdio(0); 25 | cin.tie(0); 26 | cin >> n >> m; 27 | func(0); 28 | } 29 | -------------------------------------------------------------------------------- /0x0C/solutions/15652.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/a237cd7949004a76aa9ac3cf1b13c03c 4 | #include 5 | using namespace std; 6 | 7 | int n, m; 8 | int arr[10]; 9 | 10 | void func(int k){ // 현재 k개까지 수를 택했음. 11 | if(k == m){ // m개를 모두 택했으면 12 | for(int i = 0; i < m; i++) 13 | cout << arr[i] << ' '; // arr에 기록해둔 수를 출력 14 | cout << '\n'; 15 | return; 16 | } 17 | int st = 1; // 시작지점, k = 0일 때에는 st = 1 18 | if(k != 0) st = arr[k-1]; // k != 0일 경우 st = arr[k-1] 19 | for(int i = st; i <= n; i++){ 20 | arr[k] = i; // k번째 수를 i로 정함 21 | func(k+1); // 다음 수를 정하러 한 단계 더 들어감 22 | } 23 | } 24 | 25 | int main(void){ 26 | ios::sync_with_stdio(0); 27 | cin.tie(0); 28 | cin >> n >> m; 29 | func(0); 30 | } 31 | -------------------------------------------------------------------------------- /0x0C/solutions/15656.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : yongjunleeme 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/8b9c11f721a44186bb4da3bff5e72f88 4 | #include 5 | using namespace std; 6 | 7 | int n, m; 8 | int arr[10]; 9 | int num[10]; 10 | 11 | void func(int k){ // 현재 k개까지 수를 택했음. 12 | if(k == m){ // m개를 모두 택했으면 13 | for(int i = 0; i < m; i++) 14 | cout << num[arr[i]] << ' '; // arr에 기록해둔 인덱스를 참고해 값을 출력 15 | cout << '\n'; 16 | return; 17 | } 18 | for(int i = 0; i < n; i++){ 19 | arr[k] = i; // k번째 수를 i로 정함 20 | func(k+1); // 다음 수를 정하러 한 단계 더 들어감 21 | } 22 | } 23 | 24 | int main(void){ 25 | ios::sync_with_stdio(0); 26 | cin.tie(0); 27 | cin >> n >> m; 28 | for(int i = 0; i < n; i++){ 29 | cin >> num[i]; 30 | } 31 | sort(num, num+n); 32 | func(0); 33 | } 34 | -------------------------------------------------------------------------------- /0x0C/solutions/15657.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : yongjunleeme 2 | // Co-authored by : - 3 | // http://boj.kr/0b00507b5e3743d4b95451fa8bf75ba9 4 | #include 5 | using namespace std; 6 | 7 | int n, m; 8 | int arr[10]; 9 | int num[10]; 10 | 11 | void func(int k, int st){ 12 | if(k == m){ 13 | for(int i = 0; i < m; i++) 14 | cout << num[arr[i]] << " "; 15 | cout << "\n"; 16 | return; 17 | } 18 | 19 | for(int i = st; i < n; i++){ 20 | arr[k] = i; 21 | func(k+1, i); 22 | } 23 | } 24 | 25 | int main(void){ 26 | ios::sync_with_stdio(0); 27 | cin.tie(0); 28 | cin >> n >> m; 29 | for(int i = 0; i < n; i++) 30 | cin >> num[i]; 31 | sort(num, num+n); 32 | func(0, 0); 33 | } 34 | -------------------------------------------------------------------------------- /0x0C/solutions/15666.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : yongjunleeme 2 | // Co-authored by : - 3 | // http://boj.kr/801162160382436b971d8a4bbcec798a 4 | #include 5 | using namespace std; 6 | 7 | int arr[10]; 8 | int num[10]; 9 | int n, m; 10 | 11 | void func(int k, int st){ 12 | if(k == m){ 13 | for(int i = 0; i < m; i++) cout << arr[i] << " "; 14 | cout << "\n"; 15 | return; 16 | } 17 | int tmp = -1; 18 | for(int i = st; i < n; i++){ 19 | if(num[i] != tmp){ 20 | arr[k] = num[i]; 21 | tmp = arr[k]; 22 | func(k+1, i); 23 | } 24 | } 25 | } 26 | 27 | int main(void) { 28 | ios::sync_with_stdio(0); 29 | cin.tie(0); 30 | cin >> n >> m; 31 | for(int i = 0; i < n; i++) cin >> num[i]; 32 | sort(num, num+n); 33 | func(0, 0); 34 | } 35 | -------------------------------------------------------------------------------- /0x0C/solutions/6603_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : qwee158 2 | // Co-authored by : - 3 | // http://boj.kr/091a628889c24cd79d04dd2abe6e8b5d 4 | #include 5 | using namespace std; 6 | 7 | int k, input[20], arr[10]; 8 | 9 | void func(int cnt, int cur) { 10 | if (cnt == 6) { 11 | for (int i = 0; i < 6; i++) cout << arr[i] << ' '; 12 | cout << '\n'; 13 | return; 14 | } 15 | for (int i = cur; i < k; i++) { 16 | arr[cnt] = input[i]; 17 | func(cnt + 1, i + 1); 18 | } 19 | } 20 | 21 | int main(void) { 22 | ios::sync_with_stdio(0); 23 | cin.tie(0); 24 | while (1) { 25 | cin >> k; 26 | if (k == 0) break; 27 | for (int i = 0; i < k; i++) cin >> input[i]; 28 | func(0, 0); 29 | cout << '\n'; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /0x0D/solutions/13335_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : haneulkimdev 2 | // Co-authored by : - 3 | // http://boj.kr/7b4898813082467bb053d38e54a1f83f 4 | #include 5 | using namespace std; 6 | 7 | int n, w, L; 8 | int a[1000]; // i번째 트럭의 무게 9 | int cross[1000]; // cross[i] : i번째 트럭이 다리에 올라간 시간 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> n >> w >> L; 14 | for (int i = 0; i < n; i++) cin >> a[i]; 15 | cross[0] = 1; 16 | int sum = a[0]; 17 | int idx = 0; // 현재 다리에 올라가있는 트럭 중 가장 앞에 있는 트럭의 번호 18 | for (int i = 1; i < n; i++) { 19 | while (i - idx + 1 > w || sum + a[i] > L) sum -= a[idx++]; 20 | sum += a[i]; 21 | if (idx == 0) 22 | cross[i] = cross[i - 1] + 1; 23 | else 24 | cross[i] = max(cross[i - 1] + 1, cross[idx - 1] + w); 25 | } 26 | cout << cross[n - 1] + w; 27 | } 28 | -------------------------------------------------------------------------------- /0x0D/solutions/15898.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/16637.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/17136.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/17472.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/17779.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/17822.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/17837.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/19238.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/1941.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/20056.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/20057.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/20058.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/20061.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/21609.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/21610.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/21611.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/23289.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/23291.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/2478.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0D/solutions/4991.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x0E/11728.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/eff70b5b64974fdebbcd7d2a1fdf29a5 2 | #include 3 | using namespace std; 4 | 5 | int n, m; 6 | int a[1000005], b[1000005], c[2000005]; 7 | 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> n >> m; 13 | for(int i = 0; i < n; i++) cin >> a[i]; 14 | for(int i = 0; i < m; i++) cin >> b[i]; 15 | int aidx = 0, bidx = 0; 16 | for(int i = 0; i < n+m; i++){ 17 | if(bidx == m) c[i] = a[aidx++]; 18 | else if(aidx == n) c[i] = b[bidx++]; 19 | else if(a[aidx] <= b[bidx]) c[i] = a[aidx++]; 20 | else c[i] = b[bidx++]; 21 | } 22 | for(int i = 0; i < n+m; i++) cout << c[i] << ' '; 23 | } 24 | -------------------------------------------------------------------------------- /0x0E/solutions/10814.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : hgmhc 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/9e42012f919544dfa94544e08b2ee1fe 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n; cin >> n; 11 | pair x[n]; 12 | for (auto& s : x) cin >> s.first >> s.second; 13 | stable_sort(x, x+n, [&](pair a, pair b) { 14 | return a.first < b.first; 15 | }); 16 | for (auto p : x) cout << p.first << ' ' << p.second << '\n'; 17 | } 18 | /* 19 | 13 to 15번째 줄의 코드가 낯설면 람다 함수 키워드로 구글링 추천 20 | */ 21 | -------------------------------------------------------------------------------- /0x0E/solutions/10989.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : std-freejia 2 | // Co-authored by : - 3 | // http://boj.kr/8de1786b61294a3ba048b1365c77bd38 4 | #include 5 | using namespace std; 6 | int n, num; 7 | int arr[10001]; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> n; 14 | for(int i = 0; i < n; i++){ 15 | cin >> num; arr[num]++; 16 | } 17 | for(int i = 1; i <= 10000; i++){ 18 | while(arr[i]){ 19 | cout << i << '\n'; arr[i]--; 20 | } 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /0x0E/solutions/11650.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : std-freejia 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/5a5a95bcc0644b138ad6850e5db9e87a 4 | #include 5 | using namespace std; 6 | 7 | #define X first 8 | #define Y second 9 | 10 | int n, a, b; 11 | pair p[100004]; 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(0); 15 | cin.tie(0); 16 | cin >> n; 17 | for(int i = 0; i < n; i++) { 18 | cin >> p[i].X >> p[i].Y; 19 | } 20 | sort(p, p + n); 21 | for(int i = 0; i < n; i++) cout << p[i].X << ' ' << p[i].Y << '\n'; 22 | } 23 | -------------------------------------------------------------------------------- /0x0E/solutions/11651.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/14e7ff380ec945d086845dfa9dbba5f2 4 | #include 5 | using namespace std; 6 | 7 | #define X first 8 | #define Y second 9 | 10 | pair p[100004]; 11 | 12 | int main(void) { 13 | ios::sync_with_stdio(0); 14 | cin.tie(0); 15 | 16 | int n; 17 | cin >> n; 18 | for (int i = 0; i < n; i++) 19 | cin >> p[i].Y >> p[i].X; 20 | sort(p, p + n); 21 | for (int i = 0; i < n; i++) 22 | cout << p[i].Y << ' ' << p[i].X << '\n'; 23 | } 24 | 25 | /* 26 | pair의 정렬 순서는 first를 먼저 비교하기 때문에 둘의 자리를 바꿔서 집어넣은 후 정렬함. 27 | */ 28 | -------------------------------------------------------------------------------- /0x0E/solutions/11931.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/7a7deeedae3b4177a1ed53482685bf15 4 | #include 5 | using namespace std; 6 | 7 | const int MXN = 2'000'000, HALF = MXN / 2; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | vector isnum(MXN + 2); 13 | int N, t; 14 | cin >> N; 15 | while (N--) { 16 | cin >> t; 17 | isnum[t + HALF] = true; 18 | } 19 | for (int i = MXN; i >= 0; i--) 20 | if (isnum[i]) cout << i - HALF << '\n'; 21 | } 22 | 23 | /* 24 | 수의 등장 여부만 확인, 인덱스를 0에서부터 시작할 수 있게 1,000,000을 더함. 25 | */ 26 | -------------------------------------------------------------------------------- /0x0E/solutions/15688.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/ff8bea751284429baa8fd53b43f694d2 4 | #include 5 | using namespace std; 6 | 7 | const int MXN = 2'000'000, HALF = MXN / 2; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | vector numcnt(MXN + 2); 13 | int N, t; 14 | cin >> N; 15 | while (N--) { 16 | cin >> t; 17 | numcnt[t + HALF]++; 18 | } 19 | for (int i = 0; i <= MXN; i++) 20 | while (numcnt[i]--) cout << i - HALF << '\n'; 21 | } -------------------------------------------------------------------------------- /0x0E/solutions/2750.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/801d75f3fc57460c94e9bd730172ad02 4 | #include 5 | using namespace std; 6 | 7 | const int MXN = 2000, HALF = MXN / 2; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | vector arr(MXN + 2); 13 | int N, t; 14 | cin >> N; 15 | while (N--) { 16 | cin >> t; 17 | arr[t + HALF] = true; 18 | } 19 | for (int i = 0; i <= MXN; i++) 20 | if (arr[i]) cout << i - HALF << '\n'; 21 | } -------------------------------------------------------------------------------- /0x0F/11652.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/f3feaf22016f4c9687b84ab6be2f4389 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | long long a[100005]; 7 | 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n; 12 | for(int i = 0; i < n; i++) 13 | cin >> a[i]; 14 | sort(a, a+n); 15 | int cnt = 0; 16 | long long mxval = -(1ll << 62) - 1; // 1을 long long으로 형변환하지 않고 1 << 62로 작성시 int overflow 발생 17 | int mxcnt = 0; 18 | for(int i = 0; i < n; i++){ 19 | if(i == 0 || a[i-1] == a[i]) cnt++; // i가 0인 경우 앞쪽 식이 true이기 때문에 a[i-1]을 참조하지 않음 20 | else{ 21 | if(cnt > mxcnt){ 22 | mxcnt = cnt; 23 | mxval = a[i-1]; 24 | } 25 | cnt = 1; 26 | } 27 | } 28 | if(cnt > mxcnt) mxval = a[n-1]; // 제일 마지막 수가 몇 번 등장했는지를 별도로 확인 29 | cout << mxval; 30 | } 31 | -------------------------------------------------------------------------------- /0x0F/15688.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/eeee207545644480a1971a2723769d93 2 | #include 3 | using namespace std; 4 | 5 | int freq[2000001]; 6 | int main() { 7 | ios_base::sync_with_stdio(0); 8 | cin.tie(0); 9 | int n; 10 | cin >> n; 11 | for(int i = 0; i < n; i++){ 12 | int a; 13 | cin >> a; 14 | freq[a+1000000]++; 15 | } 16 | for(int i = 0; i <= 2000000; i++){ 17 | while(freq[i]--){ // cnt[i]번 반복 18 | cout << i-1000000 << '\n'; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x0F/solutions/10814.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/039530fbae654100939d10d8a7c10bd7 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | vector> members; 14 | for (int i = 0; i < N; i++) { 15 | int age; 16 | string name; 17 | cin >> age >> name; 18 | members.push_back({age, i, name}); 19 | } 20 | sort(members.begin(), members.end()); 21 | for (auto [age, _, name] : members) 22 | cout << age << " " << name << '\n'; 23 | } -------------------------------------------------------------------------------- /0x0F/solutions/10825.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/9383c0972bbe43c28706a98f9d3e84c4 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | cin >> N; 13 | vector> students; 14 | while (N--) { 15 | string name; 16 | int kor, eng, math; 17 | cin >> name >> kor >> eng >> math; 18 | students.push_back({-kor, eng, -math, name}); 19 | } 20 | sort(students.begin(), students.end()); 21 | for (auto& s : students) 22 | cout << get<3>(s) << '\n'; 23 | } -------------------------------------------------------------------------------- /0x0F/solutions/11656.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : std-freejia 2 | // Co-authored by : - 3 | //http://boj.kr/21378a10916b42d19dce4bc7c841a73c 4 | #include 5 | using namespace std; 6 | 7 | string st; 8 | vector v; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> st; 15 | int stringlen = st.length(); 16 | for(int i = 0; i < stringlen; i++) { 17 | string temp = st.substr(i); 18 | v.push_back(temp); 19 | } 20 | sort(v.begin(), v.end()); 21 | for(auto i : v) cout << i << '\n'; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /0x0F/solutions/1181.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tongnamuu 2 | // Co-authored by : - 3 | // http://boj.kr/e365634189b1497a95abaf856df7758f 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n; 11 | cin>>n; 12 | vectora(n); 13 | for(int i=0;i>a[i]; 14 | sort(a.begin(), a.end(), [](const string& u, const string& v){ 15 | int ul = u.length(); 16 | int vl = v.length(); 17 | if(ul!=vl) return ul < vl; 18 | return u < v; 19 | }); 20 | a.erase(unique(a.begin(), a.end()), a.end()); // a에서 중복된 원소를 제거하는 명령 21 | for(string& s : a) cout< 5 | using namespace std; 6 | 7 | int n; 8 | string st; 9 | vector v; 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | cin >> n; 15 | for(int i = 0; i < n; i++) { 16 | cin >> st; 17 | reverse(st.begin(), st.end()); 18 | v.push_back(stoll(st)); 19 | } 20 | sort(v.begin(), v.end()); 21 | for(auto i : v) cout << i << '\n'; 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /0x0F/solutions/7795_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tongnamuu 2 | // Co-authored by : - 3 | // http://boj.kr/c1c7cd2d6487442f83a3fc8f1267c058 4 | 5 | #include 6 | using namespace std; 7 | int a[20001]; 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int T;cin>>T; 12 | while(T--){ 13 | int n,m;cin>>n>>m; 14 | for(int i=0;i>a[i]; 15 | sort(a, a+n); 16 | int ans = 0; 17 | for(int i=0;i>num; 19 | int index = upper_bound(a, a+n, num) - a; 20 | ans += n - index; 21 | } 22 | cout< 3 | using namespace std; 4 | 5 | int d[1005][3]; 6 | int r[1005], g[1005], b[1005]; 7 | 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int n; 12 | cin >> n; 13 | for(int i = 1; i <= n; i++) cin >> r[i] >> g[i] >> b[i]; 14 | d[1][0] = r[1]; 15 | d[1][1] = g[1]; 16 | d[1][2] = b[1]; 17 | for(int i = 2; i <= n; i++){ 18 | d[i][0] = min(d[i-1][1],d[i-1][2])+r[i]; 19 | d[i][1] = min(d[i-1][0],d[i-1][2])+g[i]; 20 | d[i][2] = min(d[i-1][0],d[i-1][1])+b[i]; 21 | } 22 | cout << *min_element(d[n], d[n]+3); 23 | // cout << min({d[n][0], d[n][1], d[n][2]}); 도 가능 24 | } 25 | -------------------------------------------------------------------------------- /0x10/11659.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/7df92c8710f24a799c1f862fc4cc9269 2 | #include 3 | using namespace std; 4 | 5 | int n, m; 6 | int a[100004], d[100004]; 7 | 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n >> m; 12 | d[0] = 0; 13 | for(int i = 1; i <= n; i++){ 14 | cin >> a[i]; 15 | d[i] = d[i-1] + a[i]; 16 | } 17 | while(m--){ 18 | int i, j; 19 | cin >> i >> j; 20 | cout << d[j] - d[i-1] << '\n'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /0x10/11726.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/516ca512ed9d4b5bb32b28ab50bbf349 2 | #include 3 | using namespace std; 4 | 5 | int d[10005]; 6 | int mod = 10007; 7 | 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int n; 12 | cin >> n; 13 | d[1] = 1; 14 | d[2] = 2; 15 | for(int i = 3; i <= n; i++) d[i] = (d[i-1]+d[i-2])%mod; 16 | cout << d[n]; 17 | } 18 | -------------------------------------------------------------------------------- /0x10/12852.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/da0497aabb26436c9ae613785cb439f7 2 | #include 3 | using namespace std; 4 | 5 | int d[1000005]; 6 | int pre[1000005]; 7 | int n; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | cin >> n; 13 | d[1] = 0; 14 | for(int i = 2; i <= n; i++){ 15 | d[i] = d[i-1] + 1; 16 | pre[i] = i-1; 17 | if(i%2 == 0 && d[i] > d[i/2] + 1){ 18 | d[i] = d[i/2] + 1; 19 | pre[i] = i/2; 20 | } 21 | if(i%3 == 0 && d[i] > d[i/3] + 1){ 22 | d[i] = d[i/3] + 1; 23 | pre[i] = i/3; 24 | } 25 | } 26 | cout << d[n] << '\n'; 27 | int cur = n; 28 | while(true){ 29 | cout << cur << ' '; 30 | if(cur == 1) break; 31 | cur = pre[cur]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /0x10/1463.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/161694ef04f04d8dbe826e253622c1cb 2 | #include 3 | using namespace std; 4 | 5 | int d[1000005]; 6 | int n; 7 | 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n; 12 | d[1] = 0; 13 | for(int i = 2; i <= n; i++){ 14 | d[i] = d[i-1]+1; 15 | if(i%2 == 0) d[i] = min(d[i],d[i/2]+1); 16 | if(i%3 == 0) d[i] = min(d[i],d[i/3]+1); 17 | } 18 | cout << d[n]; 19 | } 20 | -------------------------------------------------------------------------------- /0x10/2579_1.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/2b21f929cae94416a00de3ed8c5417ff 2 | #include 3 | using namespace std; 4 | 5 | int s[305]; 6 | int n; 7 | int d[305][3]; 8 | 9 | int main(void){ 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | cin >> n; 13 | for(int i = 1; i <= n; i++) cin >> s[i]; 14 | if(n == 1){ 15 | cout << s[1]; 16 | return 0; 17 | } 18 | d[1][1] = s[1]; 19 | d[1][2] = 0; 20 | d[2][1] = s[2]; 21 | d[2][2] = s[1]+s[2]; 22 | for(int i = 3; i <= n; i++){ 23 | d[i][1] = max(d[i-2][1],d[i-2][2])+s[i]; 24 | d[i][2] = d[i-1][1]+s[i]; 25 | } 26 | cout << max(d[n][1],d[n][2]); 27 | } 28 | -------------------------------------------------------------------------------- /0x10/2579_2.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/e93e56bb850a46378cf8f53486233cdc 2 | #include 3 | using namespace std; 4 | 5 | int s[305]; 6 | int n; 7 | int d[305]; 8 | 9 | int main(void){ 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | cin >> n; 13 | int tot = 0; 14 | for(int i = 1; i <= n; i++){ 15 | cin >> s[i]; 16 | tot += s[i]; 17 | } 18 | if(n <= 2){ 19 | cout << tot; 20 | return 0; 21 | } 22 | d[1] = s[1]; 23 | d[2] = s[2]; 24 | d[3] = s[3]; 25 | for(int i = 4; i <= n-1; i++) d[i] = min(d[i-2],d[i-3])+s[i]; 26 | cout << tot - min(d[n-1],d[n-2]); 27 | } 28 | -------------------------------------------------------------------------------- /0x10/9095.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/8b763a1df15a4cb3936f7a181f3db97c 2 | #include 3 | using namespace std; 4 | 5 | // d[i] = i를 1, 2, 3의 합으로 나타내는 방법의 수 6 | int d[20]; 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | d[1] = 1; d[2] = 2; d[3] = 4; 12 | for(int i = 4; i < 11; i++) 13 | d[i] = d[i-1] + d[i-2] + d[i-3]; 14 | 15 | int t; 16 | cin >> t; 17 | while(t--){ 18 | int n; 19 | cin >> n; 20 | cout << d[n] << '\n'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /0x10/solutions/1003.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/0a669ebf1000436b94e3067bdda26575 4 | #include 5 | using namespace std; 6 | 7 | int fibo[42][2]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | fibo[0][0] = 1; 13 | fibo[1][1] = 1; 14 | for (int i = 2; i <= 40; i++) { 15 | fibo[i][0] = fibo[i - 1][0] + fibo[i - 2][0]; 16 | fibo[i][1] = fibo[i - 1][1] + fibo[i - 2][1]; 17 | } 18 | int T; 19 | cin >> T; 20 | while (T--) { 21 | int N; 22 | cin >> N; 23 | cout << fibo[N][0] << " " << fibo[N][1] << endl; 24 | } 25 | } 26 | /* 27 | 1. 테이블 정하기 28 | fibo[i][k] = 숫자 i가 k(0 or 1)를 호출한 횟수 29 | 2. 점화식 찾기 30 | fibo[i][k] = fibo[i - 1][k] + fibo[i - 2][k] 31 | 3. 초기값 정하기 32 | fibo[0][0] = 1, fibo[1][1] = 1 33 | */ -------------------------------------------------------------------------------- /0x10/solutions/10844.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tongnamuu 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/03ae0f4b94fb463f9b0426fad0a82244 4 | #include 5 | using namespace std; 6 | long long d[101][10]; 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n; 11 | cin >> n; 12 | for (int i = 1; i <= 9; ++i) d[1][i] = 1; 13 | 14 | for (int i = 2; i <= n; ++i) { 15 | for (int k = 0; k <= 9; ++k) { 16 | if (k != 0) d[i][k] += d[i - 1][k - 1]; 17 | if (k != 9) d[i][k] += d[i - 1][k + 1]; 18 | d[i][k] %= 1000000000; 19 | } 20 | } 21 | long long ans = 0; 22 | for (int i = 0; i <= 9; ++i) { 23 | ans += d[n][i]; 24 | } 25 | ans %= 1000000000; 26 | cout << ans; 27 | } 28 | -------------------------------------------------------------------------------- /0x10/solutions/11052.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tongnamuu 2 | // Co-authored by : - 3 | // http://boj.kr/a9eee96f33c54876b9d5ba0b1c3bb246 4 | #include 5 | using namespace std; 6 | int d[1001]; 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n;cin>>n; 11 | for(int i=1;i<=n;++i) cin>>d[i]; 12 | for(int i=1;i<=n;++i) for(int j=1;j 6 | using namespace std; 7 | 8 | int n; 9 | int a[1010], d[1010]; 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n; 16 | for (int i = 0; i < n; ++i) cin >> a[i]; 17 | fill(d, d + n, 1); 18 | for (int i = 0; i < n; ++i) 19 | for (int j = 0; j < i; ++j) 20 | if (a[j] < a[i]) d[i] = max(d[i], d[j] + 1); 21 | 22 | cout << *max_element(d, d + n); 23 | } 24 | -------------------------------------------------------------------------------- /0x10/solutions/11055.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/d478c2a6be29437f80e4e280de054d12 4 | 5 | #include 6 | using namespace std; 7 | 8 | int n; 9 | int a[1010], d[1010]; 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n; 16 | for (int i = 0; i < n; ++i) { 17 | cin >> a[i]; 18 | d[i] = a[i]; 19 | } 20 | for (int i = 0; i < n; ++i) 21 | for (int j = 0; j < i; ++j) 22 | if (a[j] < a[i]) d[i] = max(d[i], d[j] + a[i]); 23 | 24 | cout << *max_element(d, d + n); 25 | } 26 | -------------------------------------------------------------------------------- /0x10/solutions/11057.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : hgmhc 2 | // Co-authored by : - 3 | // http://boj.kr/89025e1f01224efd8a5ddb2f5dd01ca4 4 | #include 5 | using namespace std; 6 | 7 | const int N = 1003; 8 | long long dp[N][10]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | int n; cin >> n; 14 | for (int i = 1; i <= n; ++i) { 15 | dp[i][0] = 1; 16 | for (int j = 1; j < 10; ++j) 17 | dp[i][j] = (dp[i][j-1]+dp[i-1][j])%10007; 18 | } 19 | cout << accumulate(dp[n],dp[n]+10,0)%10007; 20 | } 21 | -------------------------------------------------------------------------------- /0x10/solutions/11057_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : SciEm 2 | // Co-authored by : - 3 | // http://boj.kr/581d0c95a5fc40aba608214528b21a75 4 | #include 5 | using namespace std; 6 | 7 | const int mod = 10007; 8 | int n; 9 | int comb[1010][10]; 10 | 11 | int main() { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n; 16 | 17 | for (int i = 1; i <= 9; i++) 18 | comb[i][i] = 1; 19 | 20 | for (int i = 1; i <= n + 9; i++) { 21 | comb[i][0] = 1; 22 | for (int j = 1; j < min(i, 10); j++) 23 | comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod; 24 | } 25 | 26 | cout << comb[n + 9][9]; 27 | } 28 | /* 29 | n 오르막 수의 개수는 0부터 9까지 10개의 수 중에서 n개를 중복하여 택하는 경우의 수와 같다. 30 | H(10, n) = C(n + 9, n) = C(n + 9, 9)를 comb[n][r]배열을 통해 구한다. (0x12강 참고) 31 | 또한, 매번 C(i, 9)까지만 계산했다. 32 | */ 33 | -------------------------------------------------------------------------------- /0x10/solutions/1149.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/8f068222731440b58498bb7e2b2234c9 4 | #include 5 | using namespace std; 6 | 7 | int d[1005][3]; 8 | int r[1005], g[1005], b[1005]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | int n; 14 | cin >> n; 15 | for(int i = 1; i <= n; i++) cin >> r[i] >> g[i] >> b[i]; 16 | d[1][0] = r[1]; 17 | d[1][1] = g[1]; 18 | d[1][2] = b[1]; 19 | for(int i = 2; i <= n; i++){ 20 | d[i][0] = min(d[i-1][1],d[i-1][2])+r[i]; 21 | d[i][1] = min(d[i-1][0],d[i-1][2])+g[i]; 22 | d[i][2] = min(d[i-1][0],d[i-1][1])+b[i]; 23 | } 24 | cout << *min_element(d[n], d[n]+3); 25 | // cout << min({d[n][0], d[n][1], d[n][2]}); 도 가능 26 | } 27 | -------------------------------------------------------------------------------- /0x10/solutions/11659.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/7df92c8710f24a799c1f862fc4cc9269 4 | #include 5 | using namespace std; 6 | 7 | int n, m; 8 | int a[100004], d[100004]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> n >> m; 14 | d[0] = 0; 15 | for(int i = 1; i <= n; i++){ 16 | cin >> a[i]; 17 | d[i] = d[i-1] + a[i]; 18 | } 19 | while(m--){ 20 | int i, j; 21 | cin >> i >> j; 22 | cout << d[j] - d[i-1] << '\n'; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x10/solutions/11660.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/4464384189904471b2a6b8d65681bbd4 4 | 5 | #include 6 | using namespace std; 7 | 8 | int n, m; 9 | int a[1030][1030], d[1030][1030]; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n >> m; 16 | for (int i = 1; i <= n; ++i){ 17 | for (int j = 1; j <= n; ++j){ 18 | cin >> a[i][j]; 19 | d[i][j] = d[i-1][j] + d[i][j-1] - d[i-1][j-1] + a[i][j]; 20 | } 21 | } 22 | 23 | while(m--){ 24 | int x1, y1, x2, y2; 25 | cin >> x1 >> y1 >> x2 >> y2; 26 | cout << d[x2][y2] - d[x1-1][y2] - d[x2][y1-1] + d[x1-1][y1-1] << '\n'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /0x10/solutions/11726.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/516ca512ed9d4b5bb32b28ab50bbf349 4 | #include 5 | using namespace std; 6 | 7 | int d[10005]; 8 | int mod = 10007; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | int n; 14 | cin >> n; 15 | d[1] = 1; 16 | d[2] = 2; 17 | for(int i = 3; i <= n; i++) d[i] = (d[i-1]+d[i-2])%mod; 18 | cout << d[n]; 19 | } 20 | -------------------------------------------------------------------------------- /0x10/solutions/11727.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/c4c958496ccf4f808bd6fddf24c2876a 4 | 5 | #include 6 | using namespace std; 7 | 8 | int n; 9 | int d[1010]; 10 | int mod = 10007; 11 | 12 | int main(void){ 13 | ios::sync_with_stdio(0); 14 | cin.tie(0); 15 | 16 | cin >> n; 17 | d[1] = 1; 18 | d[2] = 3; 19 | for(int i = 3; i <= n; ++i) d[i] = (d[i-1] + d[i-2] * 2) % mod; 20 | cout << d[n]; 21 | } 22 | -------------------------------------------------------------------------------- /0x10/solutions/12852.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/da0497aabb26436c9ae613785cb439f7 4 | #include 5 | using namespace std; 6 | 7 | int d[1000005]; 8 | int pre[1000005]; 9 | int n; 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | cin >> n; 15 | d[1] = 0; 16 | for(int i = 2; i <= n; i++){ 17 | d[i] = d[i-1] + 1; 18 | pre[i] = i-1; 19 | if(i%2 == 0 && d[i] > d[i/2] + 1){ 20 | d[i] = d[i/2] + 1; 21 | pre[i] = i/2; 22 | } 23 | if(i%3 == 0 && d[i] > d[i/3] + 1){ 24 | d[i] = d[i/3] + 1; 25 | pre[i] = i/3; 26 | } 27 | } 28 | cout << d[n] << '\n'; 29 | int cur = n; 30 | while(true){ 31 | cout << cur << ' '; 32 | if(cur == 1) break; 33 | cur = pre[cur]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /0x10/solutions/14501.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : sukam09 2 | // Co-authored by : - 3 | // http://boj.kr/f954e10df8224f1189c74c9a8566396d 4 | #include 5 | using namespace std; 6 | 7 | int t[20]; 8 | int p[20]; 9 | int d[20]; // i번째 일에 상담을 시작했을 때 얻을 수 있는 최대 수익 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | int n; 16 | cin >> n; 17 | 18 | for (int i = 1; i <= n; i++) cin >> t[i] >> p[i]; 19 | 20 | for (int i = n; i >= 1; i--) { 21 | // i번째 일에 상담을 할 수 있을 경우 22 | if (i + t[i] <= n + 1) { 23 | // i번째 일에 상담을 했을 때와 상담을 하지 않았을 때 얻을 수 있는 수익 중 최대 수익을 취함 24 | d[i] = max(d[i + t[i]] + p[i], d[i + 1]); 25 | } 26 | else d[i] = d[i + 1]; 27 | } 28 | 29 | cout << *max_element(d, d + n + 1); 30 | } 31 | -------------------------------------------------------------------------------- /0x10/solutions/1463.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/161694ef04f04d8dbe826e253622c1cb 4 | #include 5 | using namespace std; 6 | 7 | int d[1000005]; 8 | int n; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> n; 14 | d[1] = 0; 15 | for(int i = 2; i <= n; i++){ 16 | d[i] = d[i-1]+1; 17 | if(i%2 == 0) d[i] = min(d[i],d[i/2]+1); 18 | if(i%3 == 0) d[i] = min(d[i],d[i/3]+1); 19 | } 20 | cout << d[n]; 21 | } 22 | -------------------------------------------------------------------------------- /0x10/solutions/15486.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : sukam09 2 | // Co-authored by : - 3 | // http://boj.kr/d0ec552a80384cf8b26ae4b29c78ccb4 4 | #include 5 | using namespace std; 6 | 7 | int t[1500005]; 8 | int p[1500005]; 9 | int d[1500005]; // i번째 일에 상담을 시작했을 때 얻을 수 있는 최대 수익 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | int n; 16 | cin >> n; 17 | 18 | for (int i = 1; i <= n; i++) cin >> t[i] >> p[i]; 19 | 20 | for (int i = n; i >= 1; i--) { 21 | // i번째 일에 상담을 할 수 있을 경우 22 | if (i + t[i] <= n + 1) { 23 | // i번째 일에 상담을 했을 때와 상담을 하지 않았을 때 얻을 수 있는 수익 중 최대 수익을 취함 24 | d[i] = max(d[i + t[i]] + p[i], d[i + 1]); 25 | } 26 | else d[i] = d[i + 1]; 27 | } 28 | 29 | cout << *max_element(d + 1, d + n + 1); 30 | } -------------------------------------------------------------------------------- /0x10/solutions/15988.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/945b646aaf504415a5efd80a21dff6b7 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int d[1000010]; 9 | int mod = 1e9 + 9; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | d[1] = 1; d[2] = 2; d[3] = 4; 16 | for(int i = 4; i <= 1000000; ++i) 17 | for(int j = 1; j <= 3; ++j) 18 | d[i] = (d[i] + d[i-j]) % mod; 19 | 20 | int t; 21 | cin >> t; 22 | while(t--){ 23 | cin >> n; 24 | cout << d[n] << '\n'; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x10/solutions/1699.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/56aaa902f66645c58a86798d210d1dd1 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int d[100010]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n; 15 | for(int i = 1; i <= n; ++i){ 16 | d[i] = i; 17 | for(int j = 1; j * j <= i; ++j) 18 | d[i] = min(d[i], d[i - j * j] + 1); 19 | } 20 | cout << d[n]; 21 | } 22 | -------------------------------------------------------------------------------- /0x10/solutions/1788.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/d9e1409ef9b5495cb1cb818ff94d9203 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int d[1000010]; 9 | int mod = 1e9; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n; 16 | d[0] = 0; d[1] = 1; 17 | if(n >= 0){ 18 | for(int i = 2; i <= n; ++i) 19 | d[i] = (d[i-1] + d[i-2]) % mod; 20 | } 21 | else{ 22 | n = abs(n); 23 | for(int i = 2; i <= n; ++i) 24 | d[i] = (d[i-2] - d[i-1]) % mod; 25 | } 26 | if(d[n] > 0) cout << "1\n"; 27 | else if(d[n] < 0) cout << "-1\n"; 28 | else cout << "0\n"; 29 | cout << abs(d[n]); 30 | } 31 | -------------------------------------------------------------------------------- /0x10/solutions/1904.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/5fa43d98481c4d3f9f1d8e55bdb5ed6b 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int d[1000010]; 9 | int mod = 15746; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n; 16 | d[1] = 1; d[2] = 2; 17 | for(int i = 3; i <= n; ++i) d[i] = (d[i-1] + d[i-2]) % mod; 18 | cout << d[n]; 19 | } 20 | -------------------------------------------------------------------------------- /0x10/solutions/1912.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/1fb4beecefac47d7a7f45f97f3189806 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[100010]; 9 | int d[100010]; // d[i] : i번째 항으로 끝나는 연속합 중 최대 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n; 16 | for(int i = 1; i <= n; ++i){ 17 | cin >> a[i]; 18 | } 19 | for(int i = 1; i <= n; ++i) 20 | d[i] = max(0, d[i-1]) + a[i]; 21 | cout << *max_element(d + 1, d + n + 1); 22 | } 23 | -------------------------------------------------------------------------------- /0x10/solutions/1915.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/e5fe7cb3d25e4e4d8e1d94eeb95f04c1 4 | #include 5 | using namespace std; 6 | 7 | int n, m; 8 | int board[1010][1010], d[1010][1010]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n >> m; 15 | for(int i = 1; i <= n; ++i){ 16 | string s; 17 | cin >> s; 18 | for(int j = 1; j <= m; ++j) 19 | board[i][j] = s[j-1] - '0'; 20 | } 21 | int ans = 0; 22 | for(int i = 1; i <= n; ++i){ 23 | for(int j = 1; j <= m; ++j){ 24 | if(board[i][j]){ 25 | d[i][j] = min({d[i-1][j], d[i][j-1], d[i-1][j-1]}) + 1; 26 | ans = max(ans, d[i][j]); 27 | } 28 | } 29 | } 30 | cout << ans * ans; 31 | } 32 | -------------------------------------------------------------------------------- /0x10/solutions/1932.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/b5c330a8f8684bca91511e8ea2a19a34 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[505][505], d[505][505]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n; 15 | for(int i = 1; i <= n; ++i) 16 | for(int j = 1; j <= i; ++j) 17 | cin >> a[i][j]; 18 | d[1][1] = a[1][1]; 19 | for(int i = 2; i <= n; ++i) 20 | for(int j = 1; j <= i; ++j) 21 | d[i][j] = max(d[i-1][j-1], d[i-1][j]) + a[i][j]; 22 | cout << *max_element(d[n] + 1, d[n] + n + 1); 23 | } 24 | -------------------------------------------------------------------------------- /0x10/solutions/2011.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/04239b41012a4a41bb36c1a00c62b5ec 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[5010], d[5010]; 9 | int mod = 1000000; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | string s; cin>>s; 16 | n = s.size(); 17 | for(int i = 1; i <= n; ++i) a[i] = s[i-1] - '0'; 18 | d[0] = 1; 19 | for(int i = 1; i <= n; ++i){ 20 | if(a[i] > 0) d[i] = (d[i] + d[i-1]) % mod; 21 | int x = a[i-1] * 10 + a[i]; 22 | if(x >= 10 && x <= 26) d[i] = (d[i] + d[i-2]) % mod; 23 | } 24 | cout << d[n]; 25 | } 26 | -------------------------------------------------------------------------------- /0x10/solutions/2133.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/221ce74cdbde4516af72bc435b3de8bd 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int d[35]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n; 15 | d[0] = 1; d[2] = 3; 16 | for(int i = 3; i <= n; ++i){ 17 | d[i] += d[i-2] * 3; 18 | for(int j = i - 4; j >= 0; j -= 2){ 19 | d[i] += d[j] * 2; 20 | } 21 | } 22 | cout << d[n]; 23 | } 24 | -------------------------------------------------------------------------------- /0x10/solutions/2156.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/99a5276b487143f2995ef461b49edc1c 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[10010], d[10010]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n; 15 | for(int i = 1; i <= n; ++i) cin >> a[i]; 16 | d[1] = a[1]; d[2] = a[1] + a[2]; 17 | for(int i = 3; i <= n; ++i) 18 | d[i] = max({d[i-1], d[i-2] + a[i], d[i-3] + a[i-1] + a[i]}); 19 | cout << d[n]; 20 | } 21 | -------------------------------------------------------------------------------- /0x10/solutions/2156_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/9eab1f0076b4447fb0b9b5dda85660c3 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[10010], d[10010][3]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n; 15 | for(int i = 1; i <= n; ++i) cin >> a[i]; 16 | d[1][1] = a[1]; 17 | for(int i = 2; i <= n; ++i){ 18 | d[i][0] = max({d[i-1][0], d[i-1][1], d[i-1][2]}); 19 | d[i][1] = d[i-1][0] + a[i]; 20 | d[i][2] = d[i-1][1] + a[i]; 21 | } 22 | cout << max({d[n][0], d[n][1], d[n][2]}); 23 | } 24 | -------------------------------------------------------------------------------- /0x10/solutions/2193.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/62b94c1ad9254f87a1f6e37323f2c5bf 4 | #include 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | 9 | int n; 10 | ll d[100][2]; 11 | 12 | int main(void){ 13 | ios::sync_with_stdio(0); 14 | cin.tie(0); 15 | 16 | cin >> n; 17 | d[1][1] = 1LL; 18 | for(int i = 2; i <= n; ++i){ 19 | d[i][0] = d[i-1][0] + d[i-1][1]; 20 | d[i][1] = d[i-1][0]; 21 | } 22 | cout << d[n][0] + d[n][1]; 23 | } 24 | -------------------------------------------------------------------------------- /0x10/solutions/2293.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/84f97d22cd54454da34b0f0e51aeb94a 4 | #include 5 | using namespace std; 6 | int n, k; 7 | int a[10005], d[10005]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n >> k; 12 | for (int i = 0; i < n; i++) 13 | cin >> a[i]; 14 | 15 | d[0] = 1; 16 | for (int i = 0; i < n; i++) 17 | for (int j = a[i]; j <= k; j++) 18 | d[j] += d[j - a[i]]; 19 | 20 | cout << d[k] << '\n'; 21 | } -------------------------------------------------------------------------------- /0x10/solutions/2294.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/a4f1202ad58a4973badecdf41c75c186 4 | #include 5 | using namespace std; 6 | int n, k; 7 | int a[10005], d[10005]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n >> k; 12 | for (int i = 0; i < n; i++) 13 | cin >> a[i]; 14 | fill(d, d + 10005, 100005); 15 | d[0] = 0; // 0원: 0개 16 | for (int i = 0; i < n; i++) { 17 | for (int j = a[i]; j <= k; j++) 18 | // 동전 하나 추가한 값과 기존 값 중 작은값 19 | d[j] = min(d[j], d[j - a[i]] + 1); 20 | } 21 | 22 | cout << (d[k] == 100005 ? -1 : d[k]) << '\n'; 23 | } -------------------------------------------------------------------------------- /0x10/solutions/2482.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/f238e914a2b2492ba3bcff9f82879d63 4 | #include 5 | using namespace std; 6 | 7 | int d[1005][1005]; // d[i][j] : i개의 색 중 j개의 색 선택하는 경우의 수 8 | const int mod = 1e9 + 3; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | int n, k; 14 | cin >> n >> k; 15 | for (int i = 1; i <= n; i++) d[i][1] = i; // i개중 1개 고르는 방법: i개 16 | for (int i = 4; i <= n; i++) 17 | for (int j = 2; j <= k; j++) { 18 | if (j > i / 2) break; // n개 중에서 n/2개 초과로 선택 불가 19 | // i-1개중 j개 선택 + n번째 색 선택 x 20 | // i-2개중 j-1개 선택 + n번째 색 선택 o 21 | d[i][j] = (d[i - 1][j] + d[i - 2][j - 1]) % mod; 22 | } 23 | cout << d[n][k]; 24 | } 25 | -------------------------------------------------------------------------------- /0x10/solutions/2579.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/2b21f929cae94416a00de3ed8c5417ff 4 | #include 5 | using namespace std; 6 | 7 | int s[305]; 8 | int n; 9 | int d[305][3]; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | cin >> n; 15 | for(int i = 1; i <= n; i++) cin >> s[i]; 16 | if(n == 1){ 17 | cout << s[1]; 18 | return 0; 19 | } 20 | d[1][1] = s[1]; 21 | d[1][2] = 0; 22 | d[2][1] = s[2]; 23 | d[2][2] = s[1]+s[2]; 24 | for(int i = 3; i <= n; i++){ 25 | d[i][1] = max(d[i-2][1],d[i-2][2])+s[i]; 26 | d[i][2] = d[i-1][1]+s[i]; 27 | } 28 | cout << max(d[n][1],d[n][2]); 29 | } 30 | -------------------------------------------------------------------------------- /0x10/solutions/2579_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/e93e56bb850a46378cf8f53486233cdc 4 | #include 5 | using namespace std; 6 | 7 | int s[305]; 8 | int n; 9 | int d[305]; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | cin >> n; 15 | int tot = 0; 16 | for(int i = 1; i <= n; i++){ 17 | cin >> s[i]; 18 | tot += s[i]; 19 | } 20 | if(n <= 2){ 21 | cout << tot; 22 | return 0; 23 | } 24 | d[1] = s[1]; 25 | d[2] = s[2]; 26 | d[3] = s[3]; 27 | for(int i = 4; i <= n-1; i++) d[i] = min(d[i-2],d[i-3])+s[i]; 28 | cout << tot - min(d[n-1],d[n-2]); 29 | } 30 | -------------------------------------------------------------------------------- /0x10/solutions/2579_2.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : JaeraeKim 2 | // Co-authored by : - 3 | // http://boj.kr/e0b425a934924e3da795d4e0c7e61b7c 4 | #include 5 | using namespace std; 6 | 7 | int step[305]; 8 | int dp[305]; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | int n; 14 | cin >> n; 15 | for (int i = 1; i <= n; i++) 16 | cin >> step[i]; 17 | dp[1] = step[1]; 18 | if (n > 1) dp[2] = step[2] + step[1]; 19 | if (n > 2) dp[3] = step[3] + max(step[2], step[1]); 20 | for (int i = 4; i <= n; i++) 21 | dp[i] = step[i] + max(step[i - 1] + dp[i - 3], dp[i - 2]); 22 | cout << dp[n]; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /0x10/solutions/2748.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/fca58deb2214447782fe6483572acdb8 4 | #include 5 | using namespace std; 6 | typedef long long ll; 7 | ll d[100]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int n; 12 | cin >> n; 13 | d[1] = 1, d[2] = 1; 14 | for (int i = 3; i <= n; i++) 15 | d[i] = d[i - 1] + d[i - 2]; 16 | cout << d[n]; 17 | } -------------------------------------------------------------------------------- /0x10/solutions/9084.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/4b93b3cef4514d12be63f71be03ec2ee 4 | #include 5 | using namespace std; 6 | int n, m; 7 | int a[10005], d[10005]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int t; 12 | cin >> t; 13 | while (t--) { 14 | fill(d, d + 10005, 0); 15 | cin >> n; 16 | for (int i = 0; i < n; i++) 17 | cin >> a[i]; 18 | cin >> m; 19 | d[0] = 1; 20 | for (int i = 0; i < n; i++) 21 | for (int j = a[i]; j <= m; j++) 22 | d[j] += d[j - a[i]]; // j - a[i]에 a[i] 동전 추가 23 | cout << d[m] << '\n'; 24 | } 25 | } -------------------------------------------------------------------------------- /0x10/solutions/9095.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/8b763a1df15a4cb3936f7a181f3db97c 4 | #include 5 | using namespace std; 6 | 7 | // d[i] = i를 1, 2, 3의 합으로 나타내는 방법의 수 8 | int d[20]; 9 | int main(void){ 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | d[1] = 1; d[2] = 2; d[3] = 4; 14 | for(int i = 4; i < 11; i++) 15 | d[i] = d[i-1] + d[i-2] + d[i-3]; 16 | 17 | int t; 18 | cin >> t; 19 | while(t--){ 20 | int n; 21 | cin >> n; 22 | cout << d[n] << '\n'; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x10/solutions/9461.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/0143a4f9fd8b44be972815c0288286a5 4 | #include 5 | using namespace std; 6 | typedef long long ll; 7 | ll d[105]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | d[1] = 1, d[2] = 1, d[3] = 1; 12 | 13 | for (int i = 4; i <= 100; i++) 14 | d[i] = d[i - 2] + d[i - 3]; 15 | 16 | int t; 17 | cin >> t; 18 | while (t--) { 19 | int n; 20 | cin >> n; 21 | cout << d[n] << '\n'; 22 | } 23 | } -------------------------------------------------------------------------------- /0x10/solutions/9655.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : sukam09 2 | // Co-authored by : - 3 | // http://boj.kr/4d323fbd173e42989008bafd8e62f5df 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n; 12 | cin >> n; 13 | cout << (n % 2 ? "SK" : "CY"); 14 | /* 15 | 홀수 + 홀수 = 짝수, 짝수 + 홀수 = 홀수이므로 가져간 돌의 총 합이 n이 됐을 때 게임을 이긴다고 하면 16 | 돌을 몇 개를 가져가든 n이 홀수일 때는 상근이, 짝수일 때는 창영이가 무조건 이김을 알 수 있다. 17 | */ 18 | } -------------------------------------------------------------------------------- /0x10/solutions/9655_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : 0000000000 2 | // Co-authored by : - 3 | // http://boj.kr/97ae59164b45494fa916d3a4fe2511bc 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n; cin >> n; 12 | 13 | cout << (n % 2 ? "SK" : "CY"); 14 | } 15 | 16 | /* 17 | 두 사람이 가져가는 돌의 수가 홀수개이기 때문에 n의 기우성에 따라 답이 정해진다. 18 | */ 19 | -------------------------------------------------------------------------------- /0x11/1026.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/70c1305581914397aec5ce799ab69efb 2 | #include 3 | using namespace std; 4 | 5 | int a[105], b[105]; 6 | int n; 7 | 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n; 12 | for (int i = 0; i < n; i++) cin >> a[i]; 13 | for (int i = 0; i < n; i++) cin >> b[i]; 14 | sort(a, a + n); 15 | sort(b, b + n); 16 | int ans = 0; 17 | for (int i = 0; i < n; i++) 18 | ans += a[i] * b[n-1-i]; 19 | cout << ans; 20 | } 21 | -------------------------------------------------------------------------------- /0x11/11047.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/4b1e24f072cd4db7afabd09ee437da11 2 | #include 3 | using namespace std; 4 | 5 | int n, k; 6 | int a[15]; 7 | 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int ans = 0; 12 | cin >> n >> k; 13 | for(int i = 0; i < n; i++) cin >> a[i]; 14 | for(int i = n-1; i >= 0; i--){ 15 | ans += k / a[i]; 16 | k %= a[i]; 17 | } 18 | cout << ans; 19 | } 20 | -------------------------------------------------------------------------------- /0x11/1931.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/78a1da4606a04caab418333f8fa4f001 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | pair s[100005]; // schedule, 정렬의 편의를 위해 {끝 시간, 시작 시간}으로 저장 7 | 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n; 12 | for(int i = 0; i < n; i++) 13 | cin >> s[i].second >> s[i].first; 14 | sort(s,s+n); // 먼저 끝나는 시간을 비교하고, 끝나는 시간이 동일하면 시작 시간 순으로 정렬 15 | int ans = 0; 16 | int t = 0; // 현재 시간 17 | for(int i = 0; i < n; i++){ 18 | if(t > s[i].second) continue; // 시작 시간이 현재 시간보다 이전인 회의라면 무시 19 | ans++; // 시작 시간이 현재 시간 이후인 회의를 찾았으므로 회의의 수에 1 증가 20 | t = s[i].first; // 현재 시간을 s[i]의 끝나는 시간으로 변경한다. 21 | } 22 | cout << ans; 23 | } 24 | -------------------------------------------------------------------------------- /0x11/2217.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/266b45d9568a4addbcefad6ac3aec39d 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | int w[100005]; 7 | 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n; 12 | for(int i = 0; i < n; i++) cin >> w[i]; 13 | sort(w, w+n); 14 | int ans = 0; 15 | for(int i = 1; i <= n; i++) 16 | ans = max(ans, w[n-i]*i); 17 | cout << ans; 18 | } 19 | -------------------------------------------------------------------------------- /0x11/solutions/1026.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/70c1305581914397aec5ce799ab69efb 4 | #include 5 | using namespace std; 6 | 7 | int a[105], b[105]; 8 | int n; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> n; 14 | for (int i = 0; i < n; i++) cin >> a[i]; 15 | for (int i = 0; i < n; i++) cin >> b[i]; 16 | sort(a, a + n); 17 | sort(b, b + n); 18 | int ans = 0; 19 | for (int i = 0; i < n; i++) 20 | ans += a[i] * b[n-1-i]; 21 | cout << ans; 22 | } -------------------------------------------------------------------------------- /0x11/solutions/11000_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/422c1bde5a5b422082829cd06a7565a1 4 | 5 | #include 6 | using namespace std; 7 | 8 | int N; 9 | pair lecture[200'002]; 10 | priority_queue, greater<>> pQ; 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> N; 16 | int a, b; 17 | for (int i = 0; i < N; i++) { 18 | cin >> a >> b; 19 | lecture[i] = {a, b}; 20 | } 21 | pQ.push(0); 22 | sort(lecture, lecture + N); 23 | for (int i = 0; i < N; i++) { 24 | int s, e, c = pQ.top(); 25 | tie(s, e) = lecture[i]; 26 | pQ.pop(); 27 | if (s < c) pQ.push(c); 28 | pQ.push(e); 29 | } 30 | cout << pQ.size(); 31 | } 32 | 33 | /* 34 | 우선순위 큐를 이용한 풀이 35 | */ 36 | -------------------------------------------------------------------------------- /0x11/solutions/11047.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/4b1e24f072cd4db7afabd09ee437da11 4 | #include 5 | using namespace std; 6 | 7 | int n, k; 8 | int a[15]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | int ans = 0; 14 | cin >> n >> k; 15 | for(int i = 0; i < n; i++) cin >> a[i]; 16 | for(int i = n-1; i >= 0; i--){ 17 | ans += k / a[i]; 18 | k %= a[i]; 19 | } 20 | cout << ans; 21 | } -------------------------------------------------------------------------------- /0x11/solutions/11399.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/2422d605017041259db67ccc36416aad 4 | #include 5 | using namespace std; 6 | 7 | int N, ans; 8 | int P[1002]; 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N; 14 | for (int i = 0; i < N; i++) cin >> P[i]; 15 | sort(P, P + N); 16 | for (int i = 0; i < N; i++) ans += P[i] * (N - i); 17 | cout << ans; 18 | } -------------------------------------------------------------------------------- /0x11/solutions/11501.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tongnamuu 2 | // Co-authored by : - 3 | // http://boj.kr/4b28aa2d9ef5448bb63d304f769f0c34 4 | #include 5 | using namespace std; 6 | 7 | int a[1000001]; 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int T;cin>>T; 12 | while(T--){ 13 | int n; 14 | cin>>n; 15 | for(int i=0;i>a[i]; 16 | int max_val = a[n-1]; 17 | long long ans = 0; 18 | for(int i=n-2;i>=0;--i) { 19 | if(a[i] > max_val) max_val = a[i]; 20 | ans += max_val - a[i]; 21 | } 22 | cout< 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | string s; 11 | cin>>s; 12 | int len = s.length(); 13 | int cnt[2] = {0,0}; 14 | cnt[s[0]-'0']++; 15 | for(int i=1;i 5 | using namespace std; 6 | 7 | int tmp, ans; 8 | int sign = 1; 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | string input; 14 | cin >> input; 15 | for (char c: input){ 16 | if (c == '+' || c == '-'){ 17 | ans += tmp * sign; 18 | if (c == '-') sign = -1; 19 | tmp = 0; 20 | } 21 | else{ 22 | tmp *= 10; 23 | tmp += c - '0'; 24 | } 25 | } 26 | ans += tmp * sign; 27 | cout << ans; 28 | } -------------------------------------------------------------------------------- /0x11/solutions/15903.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/bf6d94e4ef624d2b864723a6933f0733 4 | #include 5 | using namespace std; 6 | typedef long long ll; 7 | ll a[1001]; 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int n, m; 12 | cin >> n >> m; 13 | for (int i=0; i> a[i]; 14 | while (m--) { 15 | swap(a[0], *min_element(a, a+n)); 16 | swap(a[1], *min_element(a+1, a+n)); 17 | ll tmp = a[0] + a[1]; 18 | a[0] = tmp; 19 | a[1] = tmp; 20 | } 21 | ll ans = 0; 22 | for (int i=0; i 5 | using namespace std; 6 | typedef long long ll; 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n, m; 11 | cin >> n >> m; 12 | priority_queue, greater> pq; 13 | while(n--) { 14 | int x; 15 | cin >> x; 16 | pq.push(x); 17 | } 18 | while(m--){ 19 | ll a = pq.top(); pq.pop(); 20 | ll b = pq.top(); pq.pop(); 21 | pq.push(a+b); 22 | pq.push(a+b); 23 | } 24 | ll ans = 0; 25 | while (!pq.empty()){ 26 | ans += pq.top(); 27 | pq.pop(); 28 | } 29 | cout << ans; 30 | } 31 | /* 32 | 매번 최소인 두 원소를 O(N)에 찾는 대신 우선순위 큐를 이용해 O(lg N)에 탐색 가능 33 | */ 34 | -------------------------------------------------------------------------------- /0x11/solutions/1931.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/78a1da4606a04caab418333f8fa4f001 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | pair s[100005]; // schedule, 정렬의 편의를 위해 {끝 시간, 시작 시간}으로 저장 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> n; 14 | for(int i = 0; i < n; i++) 15 | cin >> s[i].second >> s[i].first; 16 | sort(s,s+n); // 먼저 끝나는 시간을 비교하고, 끝나는 시간이 동일하면 시작 시간 순으로 정렬 17 | int ans = 0; 18 | int t = 0; // 현재 시간 19 | for(int i = 0; i < n; i++){ 20 | if(t > s[i].second) continue; // 시작 시간이 현재 시간보다 이전인 회의라면 무시 21 | ans++; // 시작 시간이 현재 시간 이후인 회의를 찾았으므로 회의의 수에 1 증가 22 | t = s[i].first; // 현재 시간을 s[i]의 끝나는 시간으로 변경한다. 23 | } 24 | cout << ans; 25 | } -------------------------------------------------------------------------------- /0x11/solutions/2217.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/266b45d9568a4addbcefad6ac3aec39d 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int w[100005]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> n; 14 | for(int i = 0; i < n; i++) cin >> w[i]; 15 | sort(w, w+n); 16 | int ans = 0; 17 | for(int i = 1; i <= n; i++) 18 | ans = max(ans, w[n-i]*i); 19 | cout << ans; 20 | } -------------------------------------------------------------------------------- /0x11/solutions/2847.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : tongnamuu 2 | // Co-authored by : - 3 | // http://boj.kr/463f7849219d4db6a9740a40f381cbfb 4 | #include 5 | using namespace std; 6 | int a[101]; 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n;cin>>n; 11 | for(int i=0;i>a[i]; 12 | int prev = a[n-1]; 13 | int ans = 0; 14 | for(int i=n-2;i>=0;--i) { 15 | if(a[i]>= prev) { 16 | ans += a[i] - prev + 1; 17 | a[i] = prev - 1; 18 | } 19 | prev = a[i]; 20 | } 21 | cout< 3 | using namespace std; 4 | 5 | int main(void){ 6 | ios::sync_with_stdio(0); 7 | cin.tie(0); 8 | int n,k; 9 | cin >> n >> k; 10 | int ret = 1; 11 | for(int i = 1; i <= n; i++) ret *= i; 12 | for(int i = 1; i <= k; i++) ret /= i; 13 | for(int i = 1; i <= n-k; i++) ret /= i; 14 | cout << ret; 15 | } 16 | -------------------------------------------------------------------------------- /0x12/11051.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/4d33c0a441344bf0b631fdbf7825a7c2 2 | #include 3 | using namespace std; 4 | 5 | int comb[1002][1002]; 6 | int mod = 10007; 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | for(int i = 1; i <= 1000; i++){ 11 | comb[i][0] = comb[i][i] = 1; 12 | for(int j = 1; j < i; j++) 13 | comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%mod; 14 | } 15 | int n, m; 16 | cin >> n >> m; 17 | cout << comb[n][m]; 18 | } 19 | -------------------------------------------------------------------------------- /0x12/11653.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/696af1c8af554ba793349d4b1aa762ef 2 | #include 3 | using namespace std; 4 | 5 | int main(void){ 6 | ios::sync_with_stdio(0); 7 | cin.tie(0); 8 | int n; 9 | cin >> n; 10 | for(int i = 2; i*i <= n; i++){ 11 | while(n % i == 0){ 12 | cout << i << '\n'; 13 | n /= i; 14 | } 15 | } 16 | if(n != 1) cout << n; 17 | } 18 | -------------------------------------------------------------------------------- /0x12/1929.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/afe866fc48534adbada3f4d41e7427b5 2 | #include 3 | using namespace std; 4 | 5 | vector state(1000001, true); 6 | void sieve(int n){ 7 | state[1] = false; 8 | for(int i = 2; i*i <= n; i++){ 9 | if(!state[i]) continue; 10 | for(int j = i*i; j <= n; j += i) 11 | state[j] = false; 12 | } 13 | } 14 | 15 | int main(void){ 16 | ios::sync_with_stdio(0); 17 | cin.tie(0); 18 | int m, n; 19 | cin >> m >> n; 20 | sieve(n); 21 | for(int i = m; i <= n; i++){ 22 | if(state[i]) cout << i << '\n'; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x12/1978.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/ed4da1d53a504c21805253b185513a9a 2 | #include 3 | using namespace std; 4 | 5 | bool isprime(int n){ 6 | if(n == 1) return 0; 7 | for(int i = 2; i*i <= n; i++){ 8 | if(n % i == 0) return 0; 9 | } 10 | return 1; 11 | } 12 | 13 | int main(void){ 14 | ios::sync_with_stdio(0); 15 | cin.tie(0); 16 | int n; 17 | cin >> n; 18 | int cnt = 0; 19 | while(n--){ 20 | int x; 21 | cin >> x; 22 | cnt += isprime(x); 23 | } 24 | cout << cnt << '\n'; 25 | } 26 | -------------------------------------------------------------------------------- /0x12/6064.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/a4aee25a9bbf4f739b3da815b625b3fd 2 | #include 3 | using namespace std; 4 | 5 | int gcd(int a, int b){ 6 | if(a == 0) return b; 7 | return gcd(b%a, a); 8 | } 9 | 10 | int lcm(int a, int b){ 11 | return a / gcd(a, b) * b; 12 | } 13 | 14 | int solve(int m, int n, int x, int y){ 15 | if(x == m) x = 0; 16 | if(y == n) y = 0; 17 | int l = lcm(m, n); 18 | for(int i = x; i <= l; i += m){ 19 | if(i == 0) continue; 20 | if(i % n == y) 21 | return i; 22 | } 23 | return -1; 24 | } 25 | 26 | int main(void){ 27 | ios::sync_with_stdio(0); 28 | cin.tie(0); 29 | int n; 30 | cin >> n; 31 | while(n--){ 32 | int m,n,x,y; 33 | cin >> m >> n >> x >> y; 34 | cout << solve(m, n, x, y) << '\n'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /0x12/solutions/1011.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/50fe25ca96ad4e8d8484f3a336d06db9 4 | #include 5 | using namespace std; 6 | 7 | using ll = long long; 8 | ll solve(ll k) { 9 | return floor(2 * sqrt(k) - 1e-9); 10 | } 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | int tc; 16 | cin >> tc; 17 | ll x, y; 18 | while (tc--) { 19 | cin >> x >> y; 20 | cout << solve(y - x) << '\n'; 21 | } 22 | } 23 | /* 24 | 다음 공간이동으로 이동할 수 있는 최대 거리의 역 25 | A033638 Quarter-squares plus 1 26 | https://oeis.org/A033638 27 | */ -------------------------------------------------------------------------------- /0x12/solutions/1019.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x12/solutions/1057_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : haneulkimdev 2 | // Co-authored by : - 3 | // http://boj.kr/ad7d6ee177654e6dbc83931bc7265b7a 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n, a, b; 11 | cin >> n >> a >> b; 12 | int ans = 0; 13 | while (a != b) { 14 | a = (a + 1) / 2; 15 | b = (b + 1) / 2; 16 | ans++; 17 | } 18 | cout << ans; 19 | } 20 | 21 | /* 22 | 모든 참가자의 경기를 시뮬레이션하는 대신 두 명의 번호만 관리하는 풀이 23 | */ 24 | -------------------------------------------------------------------------------- /0x12/solutions/10610.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/8e68f1b3f5684e9ca58fb356ea86aa2f 4 | #include 5 | using namespace std; 6 | 7 | string N; 8 | vector nums; 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> N; 14 | for (char c : N) 15 | nums.push_back(c - '0'); 16 | 17 | sort(nums.begin(), nums.end(), greater()); 18 | int sum = accumulate(nums.begin(), nums.end(), 0); 19 | if (sum % 3 == 0 && nums.back() == 0) 20 | for (int n : nums) cout << n; 21 | else 22 | cout << -1; 23 | } 24 | /* 25 | 30의 배수가 되려면 10의 배수인 동시에 3의 배수이어야 합니다. 26 | 10의 배수는 숫자 안에 0이 존재하는지로 판별하고, 27 | 3의 배수는 각 숫자의 자릿수의 합이 3의 배수인지로 28 | 판별할 수 있습니다. 29 | 만약 30의 배수가 될 수 있음이 확인된다면, 30 | 큰 숫자부터 출력합니다. 31 | */ 32 | -------------------------------------------------------------------------------- /0x12/solutions/11050.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/88189dab63974f8e9446dd9d960aea56 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n,k; 11 | cin >> n >> k; 12 | int ret = 1; 13 | for(int i = 1; i <= n; i++) ret *= i; 14 | for(int i = 1; i <= k; i++) ret /= i; 15 | for(int i = 1; i <= n-k; i++) ret /= i; 16 | cout << ret; 17 | } 18 | -------------------------------------------------------------------------------- /0x12/solutions/11051.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/4d33c0a441344bf0b631fdbf7825a7c2 4 | #include 5 | using namespace std; 6 | 7 | int comb[1002][1002]; 8 | int mod = 10007; 9 | int main(void){ 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | for(int i = 1; i <= 1000; i++){ 13 | comb[i][0] = comb[i][i] = 1; 14 | for(int j = 1; j < i; j++) 15 | comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%mod; 16 | } 17 | int n, m; 18 | cin >> n >> m; 19 | cout << comb[n][m]; 20 | } 21 | -------------------------------------------------------------------------------- /0x12/solutions/11653.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/696af1c8af554ba793349d4b1aa762ef 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n; 11 | cin >> n; 12 | for(int i = 2; i*i <= n; i++){ 13 | while(n % i == 0){ 14 | cout << i << '\n'; 15 | n /= i; 16 | } 17 | } 18 | if(n != 1) cout << n; 19 | } 20 | -------------------------------------------------------------------------------- /0x12/solutions/1193.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : SciEm 2 | // Co-authored by : - 3 | // http://boj.kr/4786afbccbb148098938f248823abd35 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int x; 12 | cin >> x; 13 | 14 | // x에서 1 2 3 ...을 빼다보면 찾는 수가 i 번째 군의 x 번째 수가 된다. 15 | int i = 1; 16 | while (x > i) { 17 | x -= i; 18 | i++; 19 | } 20 | 21 | int nume = x; 22 | int deno = i + 1 - x; 23 | if (i % 2) swap(nume, deno); // 홀수 번째 군의 순서가 문제와 반대이므로 뒤집는다. 24 | cout << nume << '/' << deno; 25 | } 26 | /* 27 | 수열을 (1/1) (1/2 2/1) (1/3 2/2 3/1) ... 과 같이 묶으면 i번째 군의 개수는 28 | i개 이고 분자와 분모의 합이 i + 1로 일정함을 알 수 있다. 29 | */ 30 | -------------------------------------------------------------------------------- /0x12/solutions/1292.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : SciEm 2 | // Co-authored by : - 3 | // http://boj.kr/2fe6deab624e4c83b409ab234ee8aa48 4 | #include 5 | using namespace std; 6 | 7 | int func(int n) { 8 | int i = 1, sum = 0; 9 | while (n > i) sum += i * i, n -= i++; 10 | return sum + i * n; 11 | } 12 | 13 | int main() { 14 | ios::sync_with_stdio(0); 15 | cin.tie(0); 16 | 17 | int a, b; 18 | cin >> a >> b; 19 | cout << func(b) - func(a - 1); 20 | } 21 | /* 22 | 수열을 (1) (2 2) (3 3 3) ... 과 같이 묶으면 i 번째 군의 합은 i * i임을 이용했다. 23 | */ 24 | -------------------------------------------------------------------------------- /0x12/solutions/1476.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : SciEm 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/802e3e33606e4782872c101b44c20e18 4 | #include 5 | using namespace std; 6 | 7 | int e, s, m; 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> e >> s >> m; 14 | e--, s--, m--; 15 | 16 | int i = e; 17 | while(i % 28 != s) i += 15; 18 | 19 | int l = lcm(15, 28); 20 | while(i % 19 != m) i += l; 21 | cout << i + 1; 22 | } 23 | /* 24 | C++17부터 numeric 헤더에 lcm 함수가 내장되어 있음 25 | */ 26 | -------------------------------------------------------------------------------- /0x12/solutions/15894.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/ebecc4bfc76c4a4dace118b27d949c7e 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n; 12 | cin >> n; 13 | cout << 4ll * n; 14 | } 15 | /* 16 | 윗면에 해당하는 변을 위로 붙이고, 옆면을 각 옆면으로 붙이면 17 | 하나의 정사각형의 둘레로 생각할 수 있습니다. 18 | 또한, n의 최대값으로는 1e9까지 들어갈 수 있으므로 19 | long long으로 캐스팅하여 출력합니다. 20 | */ -------------------------------------------------------------------------------- /0x12/solutions/1676.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/357ccbb40d504081b55f2d3f98590af4 4 | #include 5 | using namespace std; 6 | int main(void) { 7 | ios::sync_with_stdio(0); 8 | cin.tie(0); 9 | int n; 10 | cin >> n; 11 | int ans = 0; 12 | while (n) { 13 | ans += n / 5; 14 | n /= 5; 15 | } 16 | cout << ans; 17 | } 18 | /* 19 | 10을 곱해야 0이 추가되므로 10이 몇번 곱해지는지 세면 된다. 20 | 10은 2 x 5 로 소인수 분해가 되는데 2의 배수가 5의 배수보다 많기 때문에 5의 개수만 세면 된다. 21 | */ -------------------------------------------------------------------------------- /0x12/solutions/1735.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : scsc3204 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/ed2a89937cce44aba6b1a18869dd16bc 4 | #include 5 | using namespace std; 6 | 7 | int gcd(int a, int b) { 8 | if(a == 0) return b; 9 | return gcd(b%a, a); 10 | } 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(0); 18 | cin.tie(0); 19 | 20 | int a, b, c, d; 21 | cin >> a >> b >> c >> d; // a/b + c/d 22 | 23 | int l = lcm(b, d); // 분모 24 | a = l / b * a; // al / bl = (al / b) / l 25 | c = l / d * c; // cl / dl = (cl / d) / l 26 | 27 | int sum = a + c; // {(al / b) + (cl / d)} / l, 분자 28 | int g = gcd(l, sum); 29 | 30 | cout << sum / g << ' ' << l / g; // 기약분수의 분자 분모 형태로 만듦 31 | } 32 | -------------------------------------------------------------------------------- /0x12/solutions/1790.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : SciEm 2 | // Co-authored by : - 3 | // http://boj.kr/5715f646f10e48e2b367b294f99ad43a 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n, k; 12 | cin >> n >> k; 13 | 14 | int len = 1, exp = 1; 15 | while (k > 9LL * len * exp) { 16 | k -= 9LL * len * exp; 17 | exp *= 10; 18 | len++; 19 | } 20 | int target = exp + (k - 1) / len; 21 | if (target > n) cout << -1; 22 | else cout << to_string(target)[(k - 1) % len]; 23 | } 24 | /* 25 | 숫자들을 길이가 같은 것으로 묶으면 9(1~9), 180(10~99), 2700(100~999) 26 | 과 같이 자리를 차지하므로 k에서 9 * i * 10^(i - 1)을 순차적으로 빼주고 27 | k번째 숫자를 포함하는 수 target을 찾는다. 28 | */ 29 | -------------------------------------------------------------------------------- /0x12/solutions/1929.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/afe866fc48534adbada3f4d41e7427b5 4 | #include 5 | using namespace std; 6 | 7 | vector state(1000001, true); 8 | void sieve(int n){ 9 | state[1] = false; 10 | for(int i = 2; i*i <= n; i++){ 11 | if(!state[i]) continue; 12 | for(int j = i*i; j <= n; j += i) 13 | state[j] = false; 14 | } 15 | } 16 | 17 | int main(void){ 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | int m, n; 21 | cin >> m >> n; 22 | sieve(n); 23 | for(int i = m; i <= n; i++){ 24 | if(state[i]) cout << i << '\n'; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x12/solutions/1978.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/ed4da1d53a504c21805253b185513a9a 4 | #include 5 | using namespace std; 6 | 7 | bool isprime(int n){ 8 | if(n == 1) return 0; 9 | for(int i = 2; i*i <= n; i++){ 10 | if(n % i == 0) return 0; 11 | } 12 | return 1; 13 | } 14 | 15 | int main(void){ 16 | ios::sync_with_stdio(0); 17 | cin.tie(0); 18 | int n; 19 | cin >> n; 20 | int cnt = 0; 21 | while(n--){ 22 | int x; 23 | cin >> x; 24 | cnt += isprime(x); 25 | } 26 | cout << cnt << '\n'; 27 | } 28 | -------------------------------------------------------------------------------- /0x12/solutions/2004.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/11adde96fad94208aa79c918e89e3a9e 4 | #include 5 | using namespace std; 6 | typedef long long ll; 7 | 8 | ll n, m, two, five; 9 | ll find(ll num, int p){ 10 | ll rtn = 0, div = p; 11 | while (num / div) { 12 | rtn += (num / div); 13 | div *= p; 14 | } 15 | return rtn; 16 | } 17 | int main(void) { 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | 21 | cin >> n >> m; 22 | two = find(n, 2) - find(m, 2) - find((n - m), 2); 23 | five = find(n, 5) - find(m, 5) - find((n - m), 5); 24 | cout << min(two, five); 25 | } -------------------------------------------------------------------------------- /0x12/solutions/2292.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/c17a84c98cdc40b1a3a72b249decca79 4 | #include 5 | using namespace std; 6 | 7 | int n, layer; 8 | int main(void) { 9 | cin >> n; 10 | n--; 11 | while (0 < (n -= 6*layer)) layer += 1; 12 | cout << ++layer; 13 | } -------------------------------------------------------------------------------- /0x12/solutions/2312.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : scsc3204 2 | // Co-authored by : - 3 | // http://boj.kr/e507624dfaa04cc59c6fabf061ccb5e3 4 | #include 5 | using namespace std; 6 | 7 | void solve() { 8 | int n; cin >> n; 9 | for(int i = 2; i * i <= n; i++) { 10 | int cnt = 0; 11 | while(n % i == 0) { 12 | cnt++; 13 | n /= i; 14 | } 15 | if(cnt) cout << i << ' ' << cnt << '\n'; 16 | } 17 | if(n != 1) cout << n << ' ' << 1 << '\n'; 18 | } 19 | 20 | int main() { 21 | ios::sync_with_stdio(0); 22 | cin.tie(0); 23 | 24 | int t; cin >> t; 25 | while(t--) solve(); 26 | } -------------------------------------------------------------------------------- /0x12/solutions/2839.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : haneulkimdev 2 | // Co-authored by : - 3 | // http://boj.kr/3649d2bc821d41be958cb51fc82946d3 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n; 11 | cin >> n; 12 | int ans = 0; 13 | while (n >= 0) { 14 | if (n % 5 == 0) { 15 | ans += n / 5; 16 | cout << ans; 17 | return 0; 18 | } 19 | n -= 3; 20 | ans++; 21 | } 22 | cout << -1; 23 | } 24 | 25 | /* 26 | 3킬로그램 5개는 5킬로그램 3개로 치환이 되기 때문에 3킬로그램은 4개 이하로 사용하면 된다. 27 | n이 5의 배수가 될 때 까지 3으로 빼주면 되는데, 이 때 n이 음수가 된다면 28 | 정확하게 n킬로그램을 만들 수 없는 상황이다. 29 | */ 30 | -------------------------------------------------------------------------------- /0x12/solutions/2960.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/c980507acdc34d5ea79e397129f664c5 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int n, k; 11 | cin >> n >> k; 12 | vector state(n+1, true); 13 | for (int i=2; i<=n; i++){ 14 | if (!state[i]) continue; 15 | for (int j=i; j<=n; j+=i){ 16 | if (!state[j]) continue; 17 | state[j] = false; 18 | k--; 19 | if (k == 0){ 20 | cout << j; 21 | return 0; 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /0x12/solutions/3036.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : SciEm 2 | // Co-authored by : - 3 | // http://boj.kr/6812e13888884382b73d53b4dcdbe11a 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n, R; 12 | cin >> n >> R; 13 | 14 | while (--n) { 15 | int r; 16 | cin >> r; 17 | int g = gcd(R, r); // C++17 18 | cout << R / g << '/' << r / g << '\n'; 19 | } 20 | } 21 | /* 22 | 반지름이 R인 원을 1회 회전시키면 반지름이 r인 원은 R/r회 회전한다. 23 | 사이에 다른 원 r'이 있더라도 (R/r') * (r'/r)이 적용되어 소거된다. 24 | */ 25 | -------------------------------------------------------------------------------- /0x12/solutions/4796.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/d52d24386b4f4b1a9b3afe25dfc3eea2 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int i = 1; 12 | while (1) { 13 | int L, P, V; 14 | cin >> L >> P >> V; 15 | if (V == 0) break; 16 | cout << "Case " << i++ << ": " << V / P * L + min(V % P, L) << '\n'; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x12/solutions/4948.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/1e50fd9692f645148720fa5f61929dba 4 | #include 5 | using namespace std; 6 | const int m = 123456 * 2; 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | vector state(m + 1, true); 11 | state[1] = false; 12 | for (int i=2; i*i<=m; i++){ 13 | if (!state[i]) continue; 14 | for (int j=i*i; j<=m; j+=i) 15 | state[j] = false; 16 | } 17 | int n, cnt; 18 | while(1){ 19 | cin >> n; 20 | if (n==0) break; 21 | cnt = 0; 22 | for (int i=n+1; i<=2*n; i++) 23 | if (state[i]) cnt++; 24 | cout << cnt << '\n'; 25 | } 26 | } -------------------------------------------------------------------------------- /0x12/solutions/5347.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : scsc3204 2 | // Co-authored by : - 3 | // http://boj.kr/11eb08243f224bfeb34e75ba14b42229 4 | #include 5 | using namespace std; 6 | using ll = long long; 7 | 8 | ll gcd(ll a, ll b) { 9 | if(a == 0) return b; 10 | return gcd(b % a, a); 11 | } 12 | 13 | ll lcm(ll a, ll b) { 14 | return a / gcd(a, b) * b; 15 | } 16 | 17 | int main(){ 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | 21 | int n; cin >> n; 22 | while(n--){ 23 | ll a, b; 24 | cin >> a >> b; 25 | cout << lcm(a, b) << '\n'; 26 | } 27 | } -------------------------------------------------------------------------------- /0x12/solutions/6064.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/a4aee25a9bbf4f739b3da815b625b3fd 4 | #include 5 | using namespace std; 6 | 7 | int gcd(int a, int b){ 8 | if(a == 0) return b; 9 | return gcd(b%a, a); 10 | } 11 | 12 | int lcm(int a, int b){ 13 | return a / gcd(a, b) * b; 14 | } 15 | 16 | int solve(int m, int n, int x, int y){ 17 | if(x == m) x = 0; 18 | if(y == n) y = 0; 19 | int l = lcm(m, n); 20 | for(int i = x; i <= l; i += m){ 21 | if(i == 0) continue; 22 | if(i % n == y) 23 | return i; 24 | } 25 | return -1; 26 | } 27 | 28 | int main(void){ 29 | ios::sync_with_stdio(0); 30 | cin.tie(0); 31 | int n; 32 | cin >> n; 33 | while(n--){ 34 | int m,n,x,y; 35 | cin >> m >> n >> x >> y; 36 | cout << solve(m, n, x, y) << '\n'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /0x12/solutions/6359_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : haneulkimdev 2 | // Co-authored by : - 3 | // http://boj.kr/cbc162afb18b43c78c27a4b7e6ee3524 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | int t; 11 | cin >> t; 12 | while (t--) { 13 | int n; 14 | cin >> n; 15 | cout << (int)sqrt(n) << '\n'; 16 | } 17 | } 18 | 19 | /* 20 | 열리거나 닫히는 횟수는 그 수의 약수의 개수와 일치하는데, 21 | 열려있는 번호는 약수의 개수가 홀수 개다. 22 | 이는 제곱수의 특징인 약수가 홀수 개라는 것을 보여준다. 23 | 1부터 n까지의 자연수 중 제곱수의 개수는 ⌊n⌋개이다. 24 | */ 25 | -------------------------------------------------------------------------------- /0x12/solutions/9020.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/45e26df635a140df9354fb7d3fbf0497 4 | #include 5 | using namespace std; 6 | 7 | const int MXN = 10'002; 8 | vector sieve(MXN, 1); 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | for (int i = 2; i*i < MXN ; i++){ 14 | if (!sieve[i]) continue; 15 | for (int j = i * i; j <= MXN; j += i) sieve[j] = false; 16 | } 17 | 18 | int tc; 19 | cin >> tc; 20 | for (int i = 0; i < tc; i++) { 21 | int c; 22 | cin >> c; 23 | for (int a = c/2; 0 < a; a--){ 24 | int b = c - a; 25 | if (sieve[a] && sieve[b]){ 26 | cout << a << ' ' << b << '\n'; 27 | break; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /0x12/solutions/9613.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/3bedce60dc434e269b34408f25873ced 4 | #include 5 | using namespace std; 6 | int a[102]; 7 | int gcd(int a, int b){ 8 | if (a==0) return b; 9 | return gcd(b % a, a); 10 | } 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin >> t; 16 | while (t--) { 17 | int n; 18 | cin >> n; 19 | long long ans = 0; 20 | for (int i=0; i> a[i]; 21 | for (int i=0; i 3 | using namespace std; 4 | 5 | int a[500005]; 6 | int n; 7 | 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n; 12 | for(int i = 0; i < n; i++) cin >> a[i]; 13 | sort(a,a+n); 14 | int m; 15 | cin >> m; 16 | while(m--){ 17 | int t; 18 | cin >> t; 19 | cout << upper_bound(a,a+n,t)-lower_bound(a,a+n,t) << '\n'; 20 | } 21 | } -------------------------------------------------------------------------------- /0x13/1654.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/7ef4724676e24629a0bf7bf297b67541 4 | #include 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | int k, n; 9 | int arr[10005]; 10 | 11 | bool solve(ll x){ 12 | ll cur = 0; 13 | for(int i = 0; i < k; i++) cur += arr[i] / x; 14 | return cur >= n; 15 | } 16 | 17 | int main(void) { 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | cin >> k >> n; 21 | for(int i = 0; i < k; i++) cin >> arr[i]; 22 | ll st = 1; 23 | ll en = 0x7fffffff; // 2^31 - 1 24 | while(st < en){ 25 | ll mid = (st+en+1)/2; 26 | if(solve(mid)) st = mid; 27 | else en = mid-1; 28 | } 29 | cout << st; 30 | } -------------------------------------------------------------------------------- /0x13/18870.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/a658bcc95d8b4322b0559462193fdc43 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | int x[1000005]; 7 | vector tmp, uni; // unique 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> n; 13 | for(int i = 0; i < n; i++){ 14 | cin >> x[i]; 15 | tmp.push_back(x[i]); 16 | } 17 | sort(tmp.begin(), tmp.end()); 18 | for(int i = 0; i < n; i++){ 19 | if(i == 0 || tmp[i-1] != tmp[i]) 20 | uni.push_back(tmp[i]); 21 | } 22 | for(int i = 0; i < n; i++) 23 | cout << lower_bound(uni.begin(), uni.end(), x[i]) - uni.begin() << ' '; 24 | } -------------------------------------------------------------------------------- /0x13/18870_1.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/ee7936483d9848d9b6a7a14243656eed 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | int x[1000005]; 7 | vector uni; // unique 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> n; 13 | for(int i = 0; i < n; i++){ 14 | cin >> x[i]; 15 | uni.push_back(x[i]); 16 | } 17 | sort(uni.begin(), uni.end()); 18 | uni.erase(unique(uni.begin(), uni.end()), uni.end()); 19 | for(int i = 0; i < n; i++) 20 | cout << lower_bound(uni.begin(), uni.end(), x[i]) - uni.begin() << ' '; 21 | } -------------------------------------------------------------------------------- /0x13/1920.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/e8e4c3e6a0f94f43bc21a192492c34a8 2 | #include 3 | using namespace std; 4 | 5 | int a[100005]; 6 | int n; 7 | 8 | int binarysearch(int target){ 9 | int st = 0; 10 | int en = n-1; 11 | while(st <= en){ 12 | int mid = (st+en)/2; 13 | if(a[mid] < target) 14 | st = mid+1; 15 | else if(a[mid] > target) 16 | en = mid-1; 17 | else 18 | return 1; 19 | } 20 | return 0; // st > en일 경우 while문을 탈출 21 | } 22 | 23 | int main(void) { 24 | ios::sync_with_stdio(0); 25 | cin.tie(0); 26 | cin >> n; 27 | for(int i = 0; i < n; i++) cin >> a[i]; 28 | sort(a, a+n); 29 | int m; 30 | cin >> m; 31 | while(m--){ 32 | int t; 33 | cin >> t; 34 | cout << binarysearch(t) << '\n'; 35 | } 36 | } -------------------------------------------------------------------------------- /0x13/1920_1.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/0d0917e336ac4d709029df43a9127ace 2 | #include 3 | using namespace std; 4 | int a[100005]; 5 | int n; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | cin >> n; 11 | for(int i = 0; i < n; i++) cin >> a[i]; 12 | sort(a,a+n); 13 | int m; 14 | cin >> m; 15 | while(m--){ 16 | int t; 17 | cin >> t; 18 | cout << binary_search(a, a+n, t) << '\n'; 19 | } 20 | } -------------------------------------------------------------------------------- /0x13/2295.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/f19cd7f505434920a0a4a9aa86454364 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | int a[1005]; 7 | vector two; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | cin >> n; 13 | for(int i = 0; i < n; i++) cin >> a[i]; 14 | sort(a, a+n); 15 | for(int i = 0; i < n; i++){ 16 | for(int j = i; j < n; j++) 17 | two.push_back(a[i]+a[j]); 18 | } 19 | sort(two.begin(), two.end()); 20 | for(int i = n-1; i > 0; i--){ 21 | for(int j = 0; j < i; j++){ 22 | if(binary_search(two.begin(), two.end(), a[i]-a[j])){ 23 | cout << a[i]; 24 | return 0; 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /0x13/solutions/10815.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/51a6cef2473c4eb5ac5a3f9399afdc31 4 | #include 5 | using namespace std; 6 | 7 | int N, M, sg[500002], card[500002]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> N; 13 | for (int i = 0; i < N; i++) cin >> sg[i]; 14 | cin >> M; 15 | for (int i = 0; i < M; i++) cin >> card[i]; 16 | sort(sg, sg + N); 17 | for (int i = 0; i < M; i++) 18 | cout << binary_search(sg, sg + N, card[i]) << ' '; 19 | } 20 | 21 | /* 22 | 굳이 card[i]로 저장하지 않고 각 카드를 매번 입력받으면서 바로 binary_search를 실행해도 됨 23 | */ 24 | -------------------------------------------------------------------------------- /0x13/solutions/10816.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/78ba45c70b3c4128ae11ded0b1015d71 4 | #include 5 | using namespace std; 6 | 7 | int a[500005]; 8 | int n; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | cin >> n; 14 | for(int i = 0; i < n; i++) cin >> a[i]; 15 | sort(a,a+n); 16 | int m; 17 | cin >> m; 18 | while(m--){ 19 | int t; 20 | cin >> t; 21 | cout << upper_bound(a,a+n,t)-lower_bound(a,a+n,t) << '\n'; 22 | } 23 | } -------------------------------------------------------------------------------- /0x13/solutions/12015.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x13/solutions/14921.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : HJPark 2 | // Co-authored by : - 3 | // http://boj.kr/3b73c9a75b7c4d44be56fd6af6fc9fed 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[100005]; 9 | int ans = 1e9 + 1; 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n; 16 | for (int i = 0; i < n; i++) cin >> a[i]; 17 | 18 | int st = 0, en = n - 1; 19 | while (st < en) { 20 | int val = a[st] + a[en]; 21 | if (abs(val) < abs(ans)) ans = val; 22 | if (val < 0) st++; 23 | else en--; 24 | } 25 | 26 | cout << ans; 27 | } 28 | 29 | /* 30 | 투포인터를 이용한 풀이 31 | st, en이 입력된 배열의 양 끝을 가르킨다. 32 | a[st]와 a[en]을 혼합한 특성값의 절대값이 ans의 절대값보다 낮을 경우 ans를 갱신한다. 33 | 만약 혼합한 특성값이 0보다 작은 경우 st를 1만큼 증가시키고 34 | 0보다 큰 경우 en을 1만큼 감소시킨다. 35 | */ 36 | -------------------------------------------------------------------------------- /0x13/solutions/1654.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/7ef4724676e24629a0bf7bf297b67541 4 | #include 5 | using namespace std; 6 | 7 | typedef long long ll; 8 | int k, n; 9 | int arr[10005]; 10 | 11 | bool solve(ll x){ 12 | ll cur = 0; 13 | for(int i = 0; i < k; i++) cur += arr[i] / x; 14 | return cur >= n; 15 | } 16 | 17 | int main(void) { 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | cin >> k >> n; 21 | for(int i = 0; i < k; i++) cin >> arr[i]; 22 | ll st = 1; 23 | ll en = 0x7fffffff; // 2^31 - 1 24 | while(st < en){ 25 | ll mid = (st+en+1)/2; 26 | if(solve(mid)) st = mid; 27 | else en = mid-1; 28 | } 29 | cout << st; 30 | } -------------------------------------------------------------------------------- /0x13/solutions/18870.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/ee7936483d9848d9b6a7a14243656eed 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | int x[1000005]; 7 | vector uni; // unique 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> n; 13 | for(int i = 0; i < n; i++){ 14 | cin >> x[i]; 15 | uni.push_back(x[i]); 16 | } 17 | sort(uni.begin(), uni.end()); 18 | uni.erase(unique(uni.begin(), uni.end()), uni.end()); 19 | for(int i = 0; i < n; i++) 20 | cout << lower_bound(uni.begin(), uni.end(), x[i]) - uni.begin() << ' '; 21 | } -------------------------------------------------------------------------------- /0x13/solutions/18870_1.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/a658bcc95d8b4322b0559462193fdc43 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | int x[1000005]; 7 | vector tmp, uni; // unique 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | cin >> n; 13 | for(int i = 0; i < n; i++){ 14 | cin >> x[i]; 15 | tmp.push_back(x[i]); 16 | } 17 | sort(tmp.begin(), tmp.end()); 18 | for(int i = 0; i < n; i++){ 19 | if(i == 0 || tmp[i-1] != tmp[i]) 20 | uni.push_back(tmp[i]); 21 | } 22 | for(int i = 0; i < n; i++) 23 | cout << lower_bound(uni.begin(), uni.end(), x[i]) - uni.begin() << ' '; 24 | } -------------------------------------------------------------------------------- /0x13/solutions/1920.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/0d0917e336ac4d709029df43a9127ace 4 | #include 5 | using namespace std; 6 | int a[100005]; 7 | int n; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | cin >> n; 13 | for(int i = 0; i < n; i++) cin >> a[i]; 14 | sort(a,a+n); 15 | int m; 16 | cin >> m; 17 | while(m--){ 18 | int t; 19 | cin >> t; 20 | cout << binary_search(a, a+n, t) << '\n'; 21 | } 22 | } -------------------------------------------------------------------------------- /0x13/solutions/2110.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : scsc3204 2 | // Co-authored by : - 3 | // http://boj.kr/3d2598bea2f140f483a479705c51c111 4 | #include 5 | using namespace std; 6 | 7 | int n, c; 8 | int x[200002]; 9 | 10 | bool solve(int len){ 11 | int idx = 0, cnt = 0; 12 | while(idx != n) { 13 | idx = lower_bound(x + idx, x + n, x[idx] + len) - x; 14 | cnt++; 15 | } 16 | return cnt >= c; 17 | } 18 | 19 | int main(){ 20 | ios::sync_with_stdio(0); 21 | cin.tie(0); 22 | 23 | cin >> n >> c; 24 | for(int i = 0; i < n; i++) cin >> x[i]; 25 | sort(x, x + n); 26 | 27 | int st = 1, en = 1000000000; 28 | int mid; 29 | while(st < en) { 30 | mid = (st + en + 1)/2; 31 | if(solve(mid)) st = mid; 32 | else en = mid - 1; 33 | } 34 | cout << st; 35 | } -------------------------------------------------------------------------------- /0x13/solutions/2295.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/f19cd7f505434920a0a4a9aa86454364 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[1005]; 9 | vector two; 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | cin >> n; 15 | for(int i = 0; i < n; i++) cin >> a[i]; 16 | sort(a, a+n); 17 | for(int i = 0; i < n; i++){ 18 | for(int j = i; j < n; j++) 19 | two.push_back(a[i]+a[j]); 20 | } 21 | sort(two.begin(), two.end()); 22 | for(int i = n-1; i > 0; i--){ 23 | for(int j = 0; j < i; j++){ 24 | if(binary_search(two.begin(), two.end(), a[i]-a[j])){ 25 | cout << a[i]; 26 | return 0; 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /0x13/solutions/2467_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : qhsl1213 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/1bc740daba1f42199b2b8c79e5a5797f 4 | #include 5 | using namespace std; 6 | typedef long long ll; 7 | 8 | ll a[100005]; 9 | 10 | int ans1 = 1e9+5; 11 | int ans2 = 1e9+5; 12 | 13 | int main(void) { 14 | ios::sync_with_stdio(0); 15 | cin.tie(0); 16 | int N; 17 | cin >> N; 18 | for(int i=0; i> a[i]; 20 | int st = 0; 21 | int en = N-1; 22 | while(st < en){ 23 | if(abs(ans1+ans2) > abs(a[st]+a[en])){ 24 | ans1 = a[st]; 25 | ans2 = a[en]; 26 | } 27 | if(abs(a[st] + a[en-1]) <= abs(a[st+1] + a[en])) en = en - 1; 28 | else st = st + 1; 29 | } 30 | cout << ans1 << " " << ans2; 31 | } 32 | 33 | /* 34 | 투 포인터를 이용한 풀이 35 | */ 36 | -------------------------------------------------------------------------------- /0x13/solutions/2512.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : scsc3204 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/339693b81eda4095a2520f89099c77d9 4 | #include 5 | using namespace std; 6 | 7 | int n, budget; 8 | int a[100'002]; 9 | 10 | bool solve(int uplim) { 11 | int sum = 0; 12 | for(int i = 0; i < n; i++) 13 | sum += min(a[i], uplim); 14 | return budget >= sum; 15 | } 16 | 17 | int main() { 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | 21 | cin >> n; 22 | int st = 1, en = 1; 23 | for(int i = 0; i < n; i++) { 24 | cin >> a[i]; 25 | en = max(a[i], en); 26 | } 27 | cin >> budget; 28 | 29 | while(st < en) { 30 | int mid = (st + en + 1) / 2; 31 | if(solve(mid)) st = mid; 32 | else en = mid - 1; 33 | } 34 | cout << st; 35 | } 36 | -------------------------------------------------------------------------------- /0x13/solutions/3151.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : SciEm 2 | // Co-authored by : - 3 | // http://boj.kr/b830d64c3ecd434ba3e554cc709dba3e 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[10002]; 9 | 10 | int main() { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n; 15 | for (int i = 0; i < n; i++) cin >> a[i]; 16 | sort(a, a + n); 17 | 18 | long long ans = 0; 19 | for (int i = 0; i < n - 1; i++) { 20 | for (int j = i + 1; j < n; j++) { 21 | auto ub = upper_bound(a + j + 1, a + n, -a[i] - a[j]); 22 | auto lb = lower_bound(a + j + 1, a + n, -a[i] - a[j]); 23 | ans += ub - lb; 24 | } 25 | } 26 | cout << ans; 27 | } 28 | /* 29 | 두 명을 선택하고 나머지 한 명을 이분탐색으로 찾되 여러 개 있는 경우를 30 | 고려하여 upper_bound와 lower_bound를 이용한다. 31 | */ 32 | -------------------------------------------------------------------------------- /0x14/1806.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/ecc7d7f58ceb4679a1bb67adbb79088c 2 | #include 3 | using namespace std; 4 | 5 | int n, s, tot; 6 | int a[100005]; 7 | int mn = 0x7fffffff; 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | cin >> n >> s; 13 | for(int i = 0; i < n; i++) cin >> a[i]; 14 | tot = a[0]; 15 | int en = 0; 16 | for(int st = 0; st < n; st++){ 17 | while(en < n && tot < s){ 18 | en++; 19 | if(en != n) tot += a[en]; 20 | } 21 | if(en == n) break; // en이 범위를 벗어날시 종료 22 | mn = min(mn, en - st + 1); 23 | tot -= a[st]; 24 | } 25 | if(mn == 0x7fffffff) mn = 0; 26 | cout << mn; 27 | } -------------------------------------------------------------------------------- /0x14/2230.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/b2658483a12c47c9b0e54c64f8ac898f 2 | #include 3 | using namespace std; 4 | 5 | int n, m; 6 | int a[100005]; 7 | int mn = 0x7fffffff; 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | cin >> n >> m; 13 | for(int i = 0; i < n; i++) cin >> a[i]; 14 | sort(a, a+n); 15 | int en = 0; 16 | for(int st = 0; st < n; st++){ 17 | while(en < n && a[en] - a[st] < m) en++; 18 | if(en == n) break; // en이 범위를 벗어날 시 종료 19 | mn = min(mn, a[en] - a[st]); 20 | } 21 | cout << mn; 22 | } -------------------------------------------------------------------------------- /0x14/solutions/13144.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/20b3510ea5384c78a6e1c34aae40b267 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n; 12 | cin >> n; 13 | vector arr(n); 14 | vector chk(100'002); 15 | for (int i = 0; i < n; i++) cin >> arr[i]; 16 | 17 | long long ans = 0; 18 | chk[arr[0]] = 1; 19 | int en = 0; 20 | for(int st = 0; st < n; st++){ 21 | // en에는 arr[st] to arr[en]에 같은 수가 등장하지 않는 가장 큰 값이 저장됨 22 | while (en < n-1 && !chk[arr[en+1]]){ 23 | en++; 24 | chk[arr[en]] = 1; 25 | } 26 | ans += (en-st+1); 27 | chk[arr[st]] = 0; 28 | } 29 | cout << ans; 30 | } 31 | -------------------------------------------------------------------------------- /0x14/solutions/1806.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/ecc7d7f58ceb4679a1bb67adbb79088c 4 | #include 5 | using namespace std; 6 | 7 | int n, s, tot; 8 | int a[100005]; 9 | int mn = 0x7fffffff; 10 | 11 | int main() { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | cin >> n >> s; 15 | for(int i = 0; i < n; i++) cin >> a[i]; 16 | tot = a[0]; 17 | int en = 0; 18 | for(int st = 0; st < n; st++){ 19 | while(en < n && tot < s){ 20 | en++; 21 | if(en != n) tot += a[en]; 22 | } 23 | if(en == n) break; // en이 범위를 벗어날시 종료 24 | mn = min(mn, en - st + 1); 25 | tot -= a[st]; 26 | } 27 | if(mn == 0x7fffffff) mn = 0; 28 | cout << mn; 29 | } -------------------------------------------------------------------------------- /0x14/solutions/2003.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : pjshwa 2 | // Co-authored by : - 3 | // http://boj.kr/b7ec5531223f449f99942515f10fb39b 4 | #include 5 | typedef long long ll; 6 | using namespace std; 7 | 8 | ll pf_sum[10005]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | int n, m; 15 | cin >> n >> m; 16 | 17 | pf_sum[0] = 0; 18 | for (int i = 1; i <= n; i++) cin >> pf_sum[i], pf_sum[i] += pf_sum[i - 1]; 19 | 20 | int lp = 0, rp = 0; 21 | int ans = 0; 22 | 23 | while (rp <= n) { 24 | ll csum = pf_sum[rp] - pf_sum[lp]; 25 | if (csum <= m) { 26 | if (csum == m) ans++; 27 | rp++; 28 | } 29 | else lp++; 30 | } 31 | 32 | cout << ans; 33 | } 34 | 35 | /* 36 | 구간의 합을 관리할 때 강의 내에서 소개한 방법과 같이 tot 변수를 하나 들고 있어도 되고 이 코드와 같이 prefix sum을 이용해도 됨 37 | */ 38 | -------------------------------------------------------------------------------- /0x14/solutions/2230.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/b2658483a12c47c9b0e54c64f8ac898f 4 | #include 5 | using namespace std; 6 | 7 | int n, m; 8 | int a[100005]; 9 | int mn = 0x7fffffff; 10 | 11 | int main() { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | cin >> n >> m; 15 | for(int i = 0; i < n; i++) cin >> a[i]; 16 | sort(a, a+n); 17 | int en = 0; 18 | for(int st = 0; st < n; st++){ 19 | while(en < n && a[en] - a[st] < m) en++; 20 | if(en == n) break; // en이 범위를 벗어날 시 종료 21 | mn = min(mn, a[en] - a[st]); 22 | } 23 | cout << mn; 24 | } -------------------------------------------------------------------------------- /0x14/solutions/22862.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/54b50eddaf3f4f1289c03a0f8b3ff229 4 | #include 5 | using namespace std; 6 | 7 | int n, k, ans; 8 | int arr[1000005]; 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> n >> k; 14 | for (int i = 0; i < n; i++) 15 | cin >> arr[i]; 16 | 17 | int cnt = 0; // 현재 보고 있는 arr[st] to arr[en] 구간에서 홀수의 개수 18 | if(arr[0] % 2 == 1) cnt++; 19 | int en = 0; 20 | for(int st = 0; st < n; st++){ 21 | while(en < n-1 && cnt + arr[en+1] % 2 <= k){ 22 | en++; 23 | cnt += arr[en] % 2; 24 | } 25 | ans = max(ans, en - st + 1 - cnt); 26 | cnt -= arr[st] % 2; 27 | } 28 | cout << ans; 29 | } 30 | -------------------------------------------------------------------------------- /0x15/1620.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/6c00940e0dab4c4e994d524d38e5582c 2 | #include 3 | using namespace std; 4 | 5 | unordered_map s2i; 6 | string i2s[100005]; 7 | 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int n, m; 12 | cin >> n >> m; 13 | for(int i = 1; i <= n; i++){ 14 | cin >> i2s[i]; 15 | s2i[i2s[i]] = i; 16 | } 17 | while(m--){ 18 | string query; 19 | cin >> query; 20 | if(isdigit(query[0])) 21 | cout << i2s[stoi(query)] << '\n'; 22 | else 23 | cout << s2i[query] << '\n'; 24 | } 25 | } -------------------------------------------------------------------------------- /0x15/7785.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/b88f0e4817f94b0fa6080d56952fd1fe 2 | #include 3 | using namespace std; 4 | 5 | unordered_set s; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n; 12 | cin >> n; 13 | while(n--){ 14 | string name, log; 15 | cin >> name >> log; 16 | if(log == "enter") s.insert(name); 17 | else s.erase(name); 18 | } 19 | vector ans(s.begin(), s.end()); 20 | sort(ans.begin(), ans.end(), greater()); 21 | for(auto x : ans) cout << x << '\n'; 22 | } -------------------------------------------------------------------------------- /0x15/solutions/11478.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/53721d7a7c1d4eeebc912cba8930dcf1 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | string s; 12 | unordered_set uset; 13 | 14 | cin >> s; 15 | for (int st = 0; st < s.length(); st++) 16 | for (int len = 1; st + len <= s.length(); len++) 17 | uset.insert(s.substr(st, len)); 18 | cout << uset.size(); 19 | } -------------------------------------------------------------------------------- /0x15/solutions/1620.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/6c00940e0dab4c4e994d524d38e5582c 2 | #include 3 | using namespace std; 4 | 5 | unordered_map s2i; 6 | string i2s[100005]; 7 | 8 | int main(void){ 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | int n, m; 12 | cin >> n >> m; 13 | for(int i = 1; i <= n; i++){ 14 | cin >> i2s[i]; 15 | s2i[i2s[i]] = i; 16 | } 17 | while(m--){ 18 | string query; 19 | cin >> query; 20 | if(isdigit(query[0])) 21 | cout << i2s[stoi(query)] << '\n'; 22 | else 23 | cout << s2i[query] << '\n'; 24 | } 25 | } -------------------------------------------------------------------------------- /0x15/solutions/17219.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/6dbb1711d18a41e48fa54edfcb93cc7c 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N, M; 12 | string s, p; 13 | unordered_map umap; 14 | 15 | cin >> N >> M; 16 | while (N--) { 17 | cin >> s >> p; 18 | umap[s] = p; 19 | } 20 | while (M--) { 21 | cin >> s; 22 | cout << umap[s] << '\n'; 23 | } 24 | } -------------------------------------------------------------------------------- /0x15/solutions/7785.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/b88f0e4817f94b0fa6080d56952fd1fe 2 | #include 3 | using namespace std; 4 | 5 | unordered_set s; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n; 12 | cin >> n; 13 | while(n--){ 14 | string name, log; 15 | cin >> name >> log; 16 | if(log == "enter") s.insert(name); 17 | else s.erase(name); 18 | } 19 | vector ans(s.begin(), s.end()); 20 | sort(ans.begin(), ans.end(), greater()); 21 | for(auto x : ans) cout << x << '\n'; 22 | } -------------------------------------------------------------------------------- /0x15/solutions/9375.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/20eb099e71a94245b5ef25f23214130a 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int tc; 12 | cin >> tc; 13 | while (tc--) { 14 | unordered_map clothings; 15 | int N, ans = 1; 16 | cin >> N; 17 | string a, b; 18 | while (N--) { 19 | cin >> a >> b; 20 | clothings[b]++; 21 | } 22 | for (auto v : clothings) ans *= v.second + 1; 23 | cout << ans - 1 << '\n'; // 알몸인 경우를 제외합니다. 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /0x16/7662.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/c34ee5c887ee4ab1b913692c92ab56cc 2 | #include 3 | using namespace std; 4 | 5 | int main(void){ 6 | ios::sync_with_stdio(0); 7 | cin.tie(0); 8 | int t; 9 | cin >> t; 10 | while(t--){ 11 | int k; 12 | cin >> k; 13 | multiset ms; 14 | while(k--){ 15 | char com; 16 | cin >> com; 17 | if(com == 'D'){ 18 | int q; 19 | cin >> q; 20 | if(ms.empty()) continue; 21 | if(q == 1) ms.erase(prev(ms.end())); 22 | else ms.erase(ms.begin()); 23 | } 24 | else{ 25 | int q; 26 | cin >> q; 27 | ms.insert(q); 28 | } 29 | } 30 | if(ms.empty()) cout << "EMPTY\n"; 31 | else{ 32 | cout << *prev(ms.end()) << ' ' << *ms.begin() << '\n'; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /0x17/11286.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/b8343775a2df428d8747759b7da51550 2 | #include 3 | using namespace std; 4 | 5 | class cmp { 6 | public: 7 | bool operator() (int a, int b) { 8 | if(abs(a) != abs(b)) return abs(a) > abs(b); 9 | return a > 0 && b < 0; 10 | } 11 | }; 12 | 13 | int main(){ 14 | ios::sync_with_stdio(0); 15 | cin.tie(0); 16 | priority_queue, cmp> pq; 17 | int n; 18 | cin >> n; 19 | while(n--){ 20 | int x; 21 | cin >> x; 22 | if(x == 0){ 23 | if(pq.empty()) cout << "0\n"; 24 | else{ 25 | cout << pq.top() << '\n'; 26 | pq.pop(); 27 | } 28 | } 29 | else pq.push(x); 30 | } 31 | } -------------------------------------------------------------------------------- /0x17/1715.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/16d83e7cd636499ba665703eb00ea213 2 | #include 3 | using namespace std; 4 | 5 | int main(){ 6 | ios::sync_with_stdio(0); 7 | cin.tie(0); 8 | priority_queue, greater> pq; 9 | int n; 10 | cin >> n; 11 | while(n--){ 12 | int x; 13 | cin >> x; 14 | pq.push(x); 15 | } 16 | int ans = 0; 17 | while(pq.size() > 1){ 18 | int a = pq.top(); pq.pop(); 19 | int b = pq.top(); pq.pop(); 20 | ans += a + b; 21 | pq.push(a+b); 22 | } 23 | cout << ans; 24 | } -------------------------------------------------------------------------------- /0x17/heap_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(void){ 5 | priority_queue pq; // 최대 힙 6 | // priority_queue, greater>로 선언시 최소 힙 7 | pq.push(10); pq.push(2); pq.push(5); pq.push(9); // {10, 2, 5, 9} 8 | cout << pq.top() << '\n'; // 10 9 | pq.pop(); // {2, 5, 9} 10 | cout << pq.size() << '\n'; // 3 11 | if(pq.empty()) cout << "PQ is empty\n"; 12 | else cout << "PQ is not empty\n"; 13 | pq.pop(); // {2, 5} 14 | cout << pq.top() << '\n'; // 5 15 | pq.push(5); pq.push(15); // {2, 5, 5, 15} 16 | cout << pq.top() << '\n'; // 15 17 | } 18 | -------------------------------------------------------------------------------- /0x17/heap_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int heap[100005]; 5 | int sz = 0; // heap에 들어있는 원소의 수 6 | 7 | void push(int x){ 8 | 9 | } 10 | 11 | int top(){ 12 | 13 | } 14 | 15 | void pop(){ 16 | 17 | } 18 | 19 | void test(){ 20 | push(10); push(2); push(5); push(9); // {10, 2, 5, 9} 21 | cout << top() << '\n'; // 2 22 | pop(); // {10, 5, 9} 23 | pop(); // {10, 9} 24 | cout << top() << '\n'; // 9 25 | push(5); push(15); // {10, 9, 5, 15} 26 | cout << top() << '\n'; // 5 27 | pop(); // {10, 9, 15} 28 | cout << top() << '\n'; // 9 29 | } 30 | 31 | int main(){ 32 | test(); 33 | } -------------------------------------------------------------------------------- /0x17/solutions/11279.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/b532e352f7854147babe1369d32b15c8 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | unsigned int t; 13 | priority_queue pq; 14 | 15 | cin >> N; 16 | for (int i = 0; i < N; i++) { 17 | cin >> t; 18 | if (t) 19 | pq.push(t); 20 | else { 21 | if (pq.empty()) 22 | cout << "0\n"; 23 | else { 24 | cout << pq.top() << '\n'; 25 | pq.pop(); 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /0x17/solutions/11286.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/b8343775a2df428d8747759b7da51550 4 | #include 5 | using namespace std; 6 | 7 | class cmp { 8 | public: 9 | bool operator() (int a, int b) { 10 | if(abs(a) != abs(b)) return abs(a) > abs(b); 11 | return a > 0 && b < 0; 12 | } 13 | }; 14 | 15 | int main(){ 16 | ios::sync_with_stdio(0); 17 | cin.tie(0); 18 | priority_queue, cmp> pq; 19 | int n; 20 | cin >> n; 21 | while(n--){ 22 | int x; 23 | cin >> x; 24 | if(x == 0){ 25 | if(pq.empty()) cout << "0\n"; 26 | else{ 27 | cout << pq.top() << '\n'; 28 | pq.pop(); 29 | } 30 | } 31 | else pq.push(x); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /0x17/solutions/13975.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/9653f21d6b2a4f87ad5bab8f56a4be35 4 | #include 5 | using namespace std; 6 | using ll = long long; 7 | 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | 12 | int tc, N; 13 | ll ans, left, right; 14 | cin >> tc; 15 | while (tc--) { 16 | ans = 0; 17 | priority_queue, greater<>> pq; 18 | 19 | cin >> N; 20 | while (N--) { 21 | cin >> left; 22 | pq.push(left); 23 | } 24 | while (pq.size() != 1) { 25 | left = pq.top(); 26 | pq.pop(); 27 | right = pq.top(); 28 | pq.pop(); 29 | ans += left + right; 30 | pq.push(left + right); 31 | } 32 | cout << ans << '\n'; 33 | } 34 | } -------------------------------------------------------------------------------- /0x17/solutions/1715.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/16d83e7cd636499ba665703eb00ea213 4 | #include 5 | using namespace std; 6 | 7 | int main(){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | priority_queue, greater> pq; 11 | int n; 12 | cin >> n; 13 | while(n--){ 14 | int x; 15 | cin >> x; 16 | pq.push(x); 17 | } 18 | int ans = 0; 19 | while(pq.size() > 1){ 20 | int a = pq.top(); pq.pop(); 21 | int b = pq.top(); pq.pop(); 22 | ans += a + b; 23 | pq.push(a+b); 24 | } 25 | cout << ans; 26 | } 27 | -------------------------------------------------------------------------------- /0x17/solutions/1927.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/d81d3f19d85f4fe0af638ff30181a16c 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N; 12 | unsigned int t; 13 | priority_queue, greater<>> pq; 14 | 15 | cin >> N; 16 | for (int i = 0; i < N; i++) { 17 | cin >> t; 18 | if (t) 19 | pq.push(t); 20 | else { 21 | if (pq.empty()) 22 | cout << "0\n"; 23 | else { 24 | cout << pq.top() << '\n'; 25 | pq.pop(); 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /0x17/solutions/2075.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : heheHwang 2 | // Co-authored by : - 3 | // http://boj.kr/45e1c40b488544b89ca5d9c966a6cdc0 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int N, num; 12 | priority_queue, greater<>> pq; 13 | cin >> N; 14 | for (int i = 0; i < N * N; i++) { 15 | cin >> num; 16 | pq.push(num); 17 | if (N < (int)pq.size()) pq.pop(); 18 | } 19 | cout << pq.top() << '\n'; 20 | } 21 | 22 | /* 23 | 문제의 메모리 제한을 고려해 우선순위 큐에 상위 N개의 값만 가지고 있는다. 24 | */ 25 | -------------------------------------------------------------------------------- /0x18/solutions/2606.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : yongjunleeme 2 | // Co-authored by : - 3 | // http://boj.kr/7cc2b9d75f4845f4a59c62a829a50bd3 4 | #include 5 | using namespace std; 6 | 7 | int v, e, a, b; 8 | vector adj[105]; 9 | int vis[105]; 10 | int ans = 0; 11 | 12 | void dfs(int cur){ 13 | vis[cur] = 1; 14 | for(auto nxt: adj[cur]){ 15 | if(vis[nxt]) continue; 16 | ans++; 17 | dfs(nxt); 18 | } 19 | } 20 | 21 | int main(void){ 22 | ios::sync_with_stdio(0); 23 | cin.tie(0); 24 | 25 | cin >> v >> e; 26 | while(e--){ 27 | cin >> a >> b; 28 | adj[a].push_back(b); 29 | adj[b].push_back(a); 30 | } 31 | 32 | dfs(1); 33 | cout << ans; 34 | } 35 | -------------------------------------------------------------------------------- /0x19/11725.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/ba2ccffa99514399aebf4bcc9e391a48 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | vector adj[100001]; 9 | int p[100001]; 10 | 11 | void dfs(int cur) { 12 | for (int nxt : adj[cur]) { 13 | if (p[cur] == nxt) continue; 14 | p[nxt] = cur; 15 | dfs(nxt); 16 | } 17 | } 18 | 19 | int main(void) { 20 | ios::sync_with_stdio(0); 21 | cin.tie(0); 22 | 23 | cin >> n; 24 | for(int i = 0; i < n-1; i++){ 25 | int u, v; 26 | cin >> u >> v; 27 | adj[u].push_back(v); 28 | adj[v].push_back(u); 29 | } 30 | dfs(1); 31 | for(int i = 2; i <= n; i++) cout << p[i] << '\n'; 32 | } -------------------------------------------------------------------------------- /0x19/solutions/11725.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/ba2ccffa99514399aebf4bcc9e391a48 2 | #include 3 | using namespace std; 4 | 5 | int n; 6 | vector adj[100001]; 7 | int p[100001]; 8 | 9 | void dfs(int cur) { 10 | for (int nxt : adj[cur]) { 11 | if (p[cur] == nxt) continue; 12 | p[nxt] = cur; 13 | dfs(nxt); 14 | } 15 | } 16 | 17 | int main(void) { 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | 21 | cin >> n; 22 | for(int i = 0; i < n-1; i++){ 23 | int u, v; 24 | cin >> u >> v; 25 | adj[u].push_back(v); 26 | adj[v].push_back(u); 27 | } 28 | dfs(1); 29 | for(int i = 2; i <= n; i++) cout << p[i] << '\n'; 30 | } -------------------------------------------------------------------------------- /0x1A/2252.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/51351692972f4da78400de750267acc6 2 | #include 3 | using namespace std; 4 | 5 | vector adj[32001]; 6 | int deg[32001]; 7 | int n, m; 8 | 9 | int main(void){ 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | cin >> n >> m; 13 | while(m--){ 14 | int a, b; 15 | cin >> a >> b; 16 | adj[a].push_back(b); 17 | deg[b]++; 18 | } 19 | queue q; 20 | for(int i = 1; i <= n; i++){ 21 | if(deg[i] == 0) q.push(i); 22 | } 23 | while(!q.empty()){ 24 | int cur = q.front(); q.pop(); 25 | cout << cur << ' '; 26 | for(int nxt : adj[cur]){ 27 | deg[nxt]--; 28 | if(deg[nxt] == 0) q.push(nxt); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /0x1A/solutions/2252.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/51351692972f4da78400de750267acc6 4 | #include 5 | using namespace std; 6 | 7 | vector adj[32001]; 8 | int deg[32001]; 9 | int n, m; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | cin >> n >> m; 15 | while(m--){ 16 | int a, b; 17 | cin >> a >> b; 18 | adj[a].push_back(b); 19 | deg[b]++; 20 | } 21 | queue q; 22 | for(int i = 1; i <= n; i++){ 23 | if(deg[i] == 0) q.push(i); 24 | } 25 | while(!q.empty()){ 26 | int cur = q.front(); q.pop(); 27 | cout << cur << ' '; 28 | for(int nxt : adj[cur]){ 29 | deg[nxt]--; 30 | if(deg[nxt] == 0) q.push(nxt); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /0x1B/solutions/9372.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : scsc3204 2 | // Co-authored by : - 3 | // http://boj.kr/a41bcccb4c724fbba5ed3bf54a418948 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int t; cin >> t; 12 | while(t--) { 13 | int n, m; 14 | cin >> n >> m; 15 | 16 | int a, b; 17 | while(m--) cin >> a >> b; 18 | cout << (n-1) << '\n'; 19 | } 20 | } 21 | 22 | /* 23 | MST 문제라는 것을 파악했다면 (정점의 수)-1개의 간선이 필요하기 때문에 24 | 주어지는 입력을 받고 간선의 수를 출력하면 된다. 25 | */ -------------------------------------------------------------------------------- /0x1C/solutions/1602.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x1D/solutions/1854.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x1D/solutions/22870.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /0x1E/16916.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/0f6ccbe50dc14c47a364912fb56eb42e 2 | #include 3 | using namespace std; 4 | 5 | vector failure(string& s){ 6 | vector f(s.size()); 7 | int j = 0; 8 | for(int i = 1; i < s.size(); i++){ 9 | while(j > 0 && s[i] != s[j]) j = f[j-1]; 10 | if(s[i] == s[j]) f[i] = ++j; 11 | } 12 | return f; 13 | } 14 | 15 | 16 | int main(void) { 17 | ios::sync_with_stdio(0); 18 | cin.tie(0); 19 | 20 | string s, p; 21 | cin >> s >> p; 22 | vector f = failure(p); 23 | int j = 0; 24 | for(int i = 0; i < s.size(); i++){ 25 | while(j > 0 && s[i] != p[j]) j = f[j-1]; 26 | if(s[i] == p[j]) j++; 27 | if(j == p.size()){ 28 | cout << 1; 29 | return 0; 30 | } 31 | } 32 | cout << 0; 33 | } 34 | -------------------------------------------------------------------------------- /0x1E/solutions/16916.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/0f6ccbe50dc14c47a364912fb56eb42e 4 | #include 5 | using namespace std; 6 | 7 | vector failure(string& s){ 8 | vector f(s.size()); 9 | int j = 0; 10 | for(int i = 1; i < s.size(); i++){ 11 | while(j > 0 && s[i] != s[j]) j = f[j-1]; 12 | if(s[i] == s[j]) f[i] = ++j; 13 | } 14 | return f; 15 | } 16 | 17 | 18 | int main(void) { 19 | ios::sync_with_stdio(0); 20 | cin.tie(0); 21 | 22 | string s, p; 23 | cin >> s >> p; 24 | vectorf = failure(p); 25 | int j = 0; 26 | for(int i = 0; i < s.size(); i++){ 27 | while(j > 0 && s[i] != p[j]) j = f[j-1]; 28 | if(s[i] == p[j]) j++; 29 | if(j == p.size()){ 30 | cout << 1; 31 | return 0; 32 | } 33 | } 34 | cout << 0; 35 | } 36 | -------------------------------------------------------------------------------- /Appendix A/1543.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/80c18d63aed84be4af35b307433dc5db 2 | #include 3 | using namespace std; 4 | 5 | int main(void) { 6 | ios::sync_with_stdio(0); 7 | cin.tie(0); 8 | string t, p; 9 | getline(cin, t); 10 | getline(cin, p); 11 | int cnt = 0; 12 | int f = t.find(p); 13 | while(f != string::npos){ 14 | cnt++; 15 | f = t.find(p, f + p.size()); 16 | } 17 | cout << cnt; 18 | } 19 | -------------------------------------------------------------------------------- /Appendix A/2941.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/5295ed05414b482692b3eb2e0a9c2a42 2 | #include 3 | using namespace std; 4 | 5 | vector alphas = {"c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="}; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | string w; 11 | cin >> w; 12 | for(auto alpha : alphas){ 13 | while(true){ 14 | int pos = w.find(alpha); 15 | if(pos == string::npos) break; 16 | w.replace(pos, alpha.size(), "1"); 17 | } 18 | } 19 | cout << w.size(); 20 | } 21 | -------------------------------------------------------------------------------- /Appendix A/solutions/1543.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/80c18d63aed84be4af35b307433dc5db 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | string t, p; 11 | getline(cin, t); 12 | getline(cin, p); 13 | int cnt = 0; 14 | int f = t.find(p); 15 | while(f != string::npos){ 16 | cnt++; 17 | f = t.find(p, f + p.size()); 18 | } 19 | cout << cnt; 20 | } 21 | -------------------------------------------------------------------------------- /Appendix A/solutions/16719.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix A/solutions/17413.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix A/solutions/2941.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/5295ed05414b482692b3eb2e0a9c2a42 4 | #include 5 | using namespace std; 6 | 7 | vector alphas = {"c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="}; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | string w; 13 | cin >> w; 14 | for(auto alpha : alphas){ 15 | while(true){ 16 | int pos = w.find(alpha); 17 | if(pos == string::npos) break; 18 | w.replace(pos, alpha.size(), "1"); 19 | } 20 | } 21 | cout << w.size(); 22 | } 23 | -------------------------------------------------------------------------------- /Appendix A/solutions/2999.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : scsc3204 2 | // Co-authored by : - 3 | // http://boj.kr/a13260c60f3d48a7993da9221d228ab0 4 | #include 5 | using namespace std; 6 | 7 | char b[100][100]; 8 | string s; 9 | 10 | int main() { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> s; 15 | int rc = s.length(), r = 1, c = rc; 16 | for(int i = 1; i*i <= rc; i++) { 17 | if(rc % i != 0) continue; 18 | r = i; c = rc / r; 19 | } 20 | 21 | int idx = 0; 22 | for(int j = 0; j < c; j++) 23 | for(int i = 0; i < r; i++) 24 | b[i][j] = s[idx++]; 25 | 26 | for(int i = 0; i < r; i++) 27 | for(int j = 0; j < c; j++) 28 | cout << b[i][j]; 29 | } -------------------------------------------------------------------------------- /Appendix A/solutions/3107.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix C/solutions/15787.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix C/solutions/17114.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix C/solutions/2064.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix C/solutions/24389.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix C/solutions/2961.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix D/solutions/10775.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix D/solutions/14595.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix D/solutions/17619.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix D/solutions/18116.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix D/solutions/1976.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix D/solutions/20040.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix D/solutions/2162.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix D/union-find.cpp: -------------------------------------------------------------------------------- 1 | vector p(1000001, -1); 2 | 3 | int find(int x){ 4 | if(p[x] < 0) 5 | return x; 6 | return p[x] = find(p[x]); 7 | } 8 | 9 | bool uni(int u, int v){ 10 | u = find(u); 11 | v = find(v); 12 | if(u == v) 13 | return false; 14 | if(p[v] < p[u]) // v의 랭크가 더 큰 경우 15 | swap(u, v); // u, v를 swap 16 | // 위의 if문으로 인해 u의 랭크 >= v의 랭크이다 17 | if(p[u] == p[v]) // 랭크가 같은 경우에 대한 처리 18 | p[u]--; 19 | p[v] = u; // v를 u의 자식으로 만든다 20 | return true; 21 | } 22 | -------------------------------------------------------------------------------- /Appendix E/12865.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/485b69efb085449ca4c64d848656498b 2 | #include 3 | using namespace std; 4 | 5 | int n, k; 6 | int d[102][100002]; 7 | int w[102]; 8 | int v[102]; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n >> k; 15 | for(int i = 0; i < n; i++) 16 | cin >> w[i] >> v[i]; 17 | 18 | for(int i = 0; i < n; i++){ 19 | for(int j = 1; j <= k; j++){ 20 | if(i-1 >= 0) 21 | d[i][j] = d[i-1][j]; 22 | if(j-w[i] >= 0){ 23 | if(i-1 >= 0) 24 | d[i][j] = max(d[i][j], d[i-1][j-w[i]] + v[i]); 25 | else 26 | d[i][j] = v[i]; 27 | } 28 | } 29 | } 30 | cout << d[n-1][k]; 31 | } 32 | -------------------------------------------------------------------------------- /Appendix E/1351.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/5a8c26a75fd7433da8b814fc477b0317 2 | #include 3 | using namespace std; 4 | 5 | using ll = long long; 6 | ll n, p, q; 7 | map a; 8 | 9 | ll go(ll x){ 10 | if(a[x] != 0) 11 | return a[x]; 12 | if(x == 0) 13 | return a[x] = 1; 14 | return a[x] = go(x/p) + go(x/q); 15 | } 16 | 17 | int main(void) { 18 | ios::sync_with_stdio(0); 19 | cin.tie(0); 20 | 21 | cin >> n >> p >> q; 22 | cout << go(n); 23 | } 24 | -------------------------------------------------------------------------------- /Appendix E/9084.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/d50d4f41d3364267bbc1c4bd5821a11d 2 | #include 3 | using namespace std; 4 | 5 | int t, n, m; 6 | int coin[22]; 7 | int d[22][10002]; 8 | 9 | int main(void) { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> t; 14 | while(t--){ 15 | cin >> n; 16 | for(int i = 0; i < n; i++){ 17 | cin >> coin[i]; 18 | d[i][0] = 1; 19 | } 20 | cin >> m; 21 | for(int i = 0; i < n; i++){ 22 | for(int j = 1; j <= m; j++){ 23 | d[i][j] = 0; 24 | if(i-1 >= 0) 25 | d[i][j] += d[i-1][j]; 26 | if(j-coin[i] >= 0) 27 | d[i][j] += d[i][j-coin[i]]; 28 | } 29 | } 30 | cout << d[n-1][m] << '\n'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Appendix E/9251.cpp: -------------------------------------------------------------------------------- 1 | // http://boj.kr/cf49db3b3f394eb192a482da5f7a8f84 2 | #include 3 | using namespace std; 4 | 5 | string a, b; 6 | int n, m; 7 | int d[1005][1005]; 8 | 9 | int main() { 10 | ios::sync_with_stdio(0); 11 | cin.tie(0); 12 | 13 | cin >> a >> b; 14 | n = a.size(); 15 | m = b.size(); 16 | 17 | for(int i = 1; i <= n; i++){ 18 | for(int j = 1; j <= m; j++){ 19 | if(a[i-1] == b[j-1]) 20 | d[i][j] = d[i-1][j-1] + 1; 21 | d[i][j] = max({d[i][j], d[i-1][j], d[i][j-1]}); 22 | } 23 | } 24 | cout << d[n][m]; 25 | } 26 | -------------------------------------------------------------------------------- /Appendix E/solutions/11660.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/4464384189904471b2a6b8d65681bbd4 4 | 5 | #include 6 | using namespace std; 7 | 8 | int n, m; 9 | int a[1030][1030], d[1030][1030]; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> n >> m; 16 | for (int i = 1; i <= n; ++i){ 17 | for (int j = 1; j <= n; ++j){ 18 | cin >> a[i][j]; 19 | d[i][j] = d[i-1][j] + d[i][j-1] - d[i-1][j-1] + a[i][j]; 20 | } 21 | } 22 | 23 | while(m--){ 24 | int x1, y1, x2, y2; 25 | cin >> x1 >> y1 >> x2 >> y2; 26 | cout << d[x2][y2] - d[x1-1][y2] - d[x2][y1-1] + d[x1-1][y1-1] << '\n'; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Appendix E/solutions/12784.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix E/solutions/12865.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/485b69efb085449ca4c64d848656498b 4 | #include 5 | using namespace std; 6 | 7 | int n, k; 8 | int d[102][100002]; 9 | int w[102]; 10 | int v[102]; 11 | 12 | int main(void) { 13 | ios::sync_with_stdio(0); 14 | cin.tie(0); 15 | 16 | cin >> n >> k; 17 | for(int i = 0; i < n; i++) 18 | cin >> w[i] >> v[i]; 19 | 20 | for(int i = 0; i < n; i++){ 21 | for(int j = 1; j <= k; j++){ 22 | if(i-1 >= 0) 23 | d[i][j] = d[i-1][j]; 24 | if(j-w[i] >= 0){ 25 | if(i-1 >= 0) 26 | d[i][j] = max(d[i][j], d[i-1][j-w[i]] + v[i]); 27 | else 28 | d[i][j] = v[i]; 29 | } 30 | } 31 | } 32 | cout << d[n-1][k]; 33 | } 34 | -------------------------------------------------------------------------------- /Appendix E/solutions/1351.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/5a8c26a75fd7433da8b814fc477b0317 4 | #include 5 | using namespace std; 6 | 7 | using ll = long long; 8 | ll n, p, q; 9 | map a; 10 | 11 | ll go(ll x){ 12 | if(a[x] != 0) 13 | return a[x]; 14 | if(x == 0) 15 | return a[x] = 1; 16 | return a[x] = go(x/p) + go(x/q); 17 | } 18 | 19 | int main(void) { 20 | ios::sync_with_stdio(0); 21 | cin.tie(0); 22 | 23 | cin >> n >> p >> q; 24 | cout << go(n); 25 | } 26 | -------------------------------------------------------------------------------- /Appendix E/solutions/1699.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/56aaa902f66645c58a86798d210d1dd1 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int d[100010]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n; 15 | for(int i = 1; i <= n; ++i){ 16 | d[i] = i; 17 | for(int j = 1; j * j <= i; ++j) 18 | d[i] = min(d[i], d[i - j * j] + 1); 19 | } 20 | cout << d[n]; 21 | } 22 | -------------------------------------------------------------------------------- /Appendix E/solutions/2011.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/04239b41012a4a41bb36c1a00c62b5ec 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int a[5010], d[5010]; 9 | int mod = 1000000; 10 | 11 | int main(void){ 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | string s; cin>>s; 16 | n = s.size(); 17 | for(int i = 1; i <= n; ++i) a[i] = s[i-1] - '0'; 18 | d[0] = 1; 19 | for(int i = 1; i <= n; ++i){ 20 | if(a[i] > 0) d[i] = (d[i] + d[i-1]) % mod; 21 | int x = a[i-1] * 10 + a[i]; 22 | if(x >= 10 && x <= 26) d[i] = (d[i] + d[i-2]) % mod; 23 | } 24 | cout << d[n]; 25 | } 26 | -------------------------------------------------------------------------------- /Appendix E/solutions/21276.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix E/solutions/2133.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : Hot6Mania 2 | // Co-authored by : - 3 | // http://boj.kr/221ce74cdbde4516af72bc435b3de8bd 4 | #include 5 | using namespace std; 6 | 7 | int n; 8 | int d[35]; 9 | 10 | int main(void){ 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | 14 | cin >> n; 15 | d[0] = 1; d[2] = 3; 16 | for(int i = 3; i <= n; ++i){ 17 | d[i] += d[i-2] * 3; 18 | for(int j = i - 4; j >= 0; j -= 2){ 19 | d[i] += d[j] * 2; 20 | } 21 | } 22 | cout << d[n]; 23 | } 24 | -------------------------------------------------------------------------------- /Appendix E/solutions/2294.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : - 3 | // http://boj.kr/a4f1202ad58a4973badecdf41c75c186 4 | #include 5 | using namespace std; 6 | int n, k; 7 | int a[10005], d[10005]; 8 | int main(void) { 9 | ios::sync_with_stdio(0); 10 | cin.tie(0); 11 | cin >> n >> k; 12 | for (int i = 0; i < n; i++) 13 | cin >> a[i]; 14 | fill(d, d + 10005, 100005); 15 | d[0] = 0; // 0원: 0개 16 | for (int i = 0; i < n; i++) { 17 | for (int j = a[i]; j <= k; j++) 18 | // 동전 하나 추가한 값과 기존 값 중 작은값 19 | d[j] = min(d[j], d[j - a[i]] + 1); 20 | } 21 | 22 | cout << (d[k] == 100005 ? -1 : d[k]) << '\n'; 23 | } -------------------------------------------------------------------------------- /Appendix E/solutions/24232.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix E/solutions/2482.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : jihwan0123 2 | // Co-authored by : BaaaaaaaaaaarkingDog 3 | // http://boj.kr/f238e914a2b2492ba3bcff9f82879d63 4 | #include 5 | using namespace std; 6 | 7 | int d[1005][1005]; // d[i][j] : i개의 색 중 j개의 색 선택하는 경우의 수 8 | const int mod = 1e9 + 3; 9 | 10 | int main(void) { 11 | ios::sync_with_stdio(0); 12 | cin.tie(0); 13 | int n, k; 14 | cin >> n >> k; 15 | for (int i = 1; i <= n; i++) d[i][1] = i; // i개중 1개 고르는 방법: i개 16 | for (int i = 4; i <= n; i++) 17 | for (int j = 2; j <= k; j++) { 18 | if (j > i / 2) break; // n개 중에서 n/2개 초과로 선택 불가 19 | // i-1개중 j개 선택 + n번째 색 선택 x 20 | // i-2개중 j-1개 선택 + n번째 색 선택 o 21 | d[i][j] = (d[i - 1][j] + d[i - 2][j - 1]) % mod; 22 | } 23 | cout << d[n][k]; 24 | } 25 | -------------------------------------------------------------------------------- /Appendix E/solutions/25515.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix E/solutions/2611.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix E/solutions/27501.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix E/solutions/3665.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /Appendix E/solutions/9084.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/d50d4f41d3364267bbc1c4bd5821a11d 4 | #include 5 | using namespace std; 6 | 7 | int t, n, m; 8 | int coin[22]; 9 | int d[22][10002]; 10 | 11 | int main(void) { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> t; 16 | while(t--){ 17 | cin >> n; 18 | for(int i = 0; i < n; i++){ 19 | cin >> coin[i]; 20 | d[i][0] = 1; 21 | } 22 | cin >> m; 23 | for(int i = 0; i < n; i++){ 24 | for(int j = 1; j <= m; j++){ 25 | d[i][j] = 0; 26 | if(i-1 >= 0) 27 | d[i][j] += d[i-1][j]; 28 | if(j-coin[i] >= 0) 29 | d[i][j] += d[i][j-coin[i]]; 30 | } 31 | } 32 | cout << d[n-1][m] << '\n'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Appendix E/solutions/9251.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/cf49db3b3f394eb192a482da5f7a8f84 4 | #include 5 | using namespace std; 6 | 7 | string a, b; 8 | int n, m; 9 | int d[1005][1005]; 10 | 11 | int main() { 12 | ios::sync_with_stdio(0); 13 | cin.tie(0); 14 | 15 | cin >> a >> b; 16 | n = a.size(); 17 | m = b.size(); 18 | 19 | for(int i = 1; i <= n; i++){ 20 | for(int j = 1; j <= m; j++){ 21 | if(a[i-1] == b[j-1]) 22 | d[i][j] = d[i-1][j-1] + 1; 23 | d[i][j] = max({d[i][j], d[i-1][j], d[i][j-1]}); 24 | } 25 | } 26 | cout << d[n][m]; 27 | } 28 | -------------------------------------------------------------------------------- /Appendix E/solutions/9655.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : sukam09 2 | // Co-authored by : - 3 | // http://boj.kr/4d323fbd173e42989008bafd8e62f5df 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n; 12 | cin >> n; 13 | cout << (n % 2 ? "SK" : "CY"); 14 | /* 15 | 홀수 + 홀수 = 짝수, 짝수 + 홀수 = 홀수이므로 가져간 돌의 총 합이 n이 됐을 때 게임을 이긴다고 하면 16 | 돌을 몇 개를 가져가든 n이 홀수일 때는 상근이, 짝수일 때는 창영이가 무조건 이김을 알 수 있다. 17 | */ 18 | } -------------------------------------------------------------------------------- /Appendix E/solutions/9655_1.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : 0000000000 2 | // Co-authored by : - 3 | // http://boj.kr/97ae59164b45494fa916d3a4fe2511bc 4 | #include 5 | using namespace std; 6 | 7 | int main(void) { 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | int n; cin >> n; 12 | 13 | cout << (n % 2 ? "SK" : "CY"); 14 | } 15 | 16 | /* 17 | 두 사람이 가져가는 돌의 수가 홀수개이기 때문에 n의 기우성에 따라 답이 정해진다. 18 | */ 19 | -------------------------------------------------------------------------------- /Appendix E/solutions/9665.cpp: -------------------------------------------------------------------------------- 1 | // Authored by : BaaaaaaaaaaarkingDog 2 | // Co-authored by : - 3 | // http://boj.kr/**************** 4 | #include 5 | using namespace std; 6 | 7 | int main(void){ 8 | ios::sync_with_stdio(0); 9 | cin.tie(0); 10 | 11 | } -------------------------------------------------------------------------------- /workbook/0x04.md: -------------------------------------------------------------------------------- 1 | # 연결 리스트 2 | 3 | ![100%](https://progress-bar.xyz/3/?scale=3&title=progress&width=500&color=babaca&suffix=/3) 4 | 5 | [문제집 링크](https://www.acmicpc.net/workbook/view/7308) 6 | 7 | | 문제 분류 | 문제 | 문제 제목 | 정답 코드 | 8 | | :--: | :--: | :--: | :--: | 9 | | 연습 문제 | 1406 | [에디터](https://www.acmicpc.net/problem/1406) | [정답 코드](../0x04/solutions/1406.cpp) | 10 | | 기본 문제✔ | 5397 | [키로거](https://www.acmicpc.net/problem/5397) | [정답 코드](../0x04/solutions/5397.cpp) | 11 | | 기본 문제✔ | 1158 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | [정답 코드](../0x04/solutions/1158.cpp), [별해 1](../0x04/solutions/1158_1.cpp), [별해 2](../0x04/solutions/1158_2.cpp) | 12 | -------------------------------------------------------------------------------- /workbook/0x06.md: -------------------------------------------------------------------------------- 1 | # 큐 2 | 3 | ![100%](https://progress-bar.xyz/3/?scale=3&title=progress&width=500&color=babaca&suffix=/3) 4 | 5 | [문제집 링크](https://www.acmicpc.net/workbook/view/7310) 6 | 7 | | 문제 분류 | 문제 | 문제 제목 | 정답 코드 | 8 | | :--: | :--: | :--: | :--: | 9 | | 연습 문제 | 10845 | [큐](https://www.acmicpc.net/problem/10845) | [정답 코드](../0x06/solutions/10845.cpp) | 10 | | 기본 문제✔ | 18258 | [큐 2](https://www.acmicpc.net/problem/18258) | [정답 코드](../0x06/solutions/18258.cpp), [별해 1](../0x06/solutions/18258_1.cpp) | 11 | | 기본 문제✔ | 2164 | [카드2](https://www.acmicpc.net/problem/2164) | [정답 코드](../0x06/solutions/2164.cpp) | 12 | -------------------------------------------------------------------------------- /workbook/0x07.md: -------------------------------------------------------------------------------- 1 | # 덱 2 | 3 | ![100%](https://progress-bar.xyz/4/?scale=4&title=progress&width=500&color=babaca&suffix=/4) 4 | 5 | [문제집 링크](https://www.acmicpc.net/workbook/view/7311) 6 | 7 | | 문제 분류 | 문제 | 문제 제목 | 정답 코드 | 8 | | :--: | :--: | :--: | :--: | 9 | | 연습 문제 | 10866 | [덱](https://www.acmicpc.net/problem/10866) | [정답 코드](../0x07/solutions/10866.cpp) | 10 | | 기본 문제✔ | 1021 | [회전하는 큐](https://www.acmicpc.net/problem/1021) | [정답 코드](../0x07/solutions/1021.cpp) | 11 | | 응용 문제✔ | 5430 | [AC](https://www.acmicpc.net/problem/5430) | [정답 코드](../0x07/solutions/5430.cpp), [별해 1](../0x07/solutions/5430_1.cpp) | 12 | | 응용 문제 | 11003 | [최솟값 찾기](https://www.acmicpc.net/problem/11003) | [정답 코드](../0x07/solutions/11003.cpp), [별해 1](../0x07/solutions/11003_1.cpp) | 13 | -------------------------------------------------------------------------------- /workbook/0x08.md: -------------------------------------------------------------------------------- 1 | # 스택의 활용(수식의 괄호 쌍) 2 | 3 | ![100%](https://progress-bar.xyz/5/?scale=5&title=progress&width=500&color=babaca&suffix=/5) 4 | 5 | [문제집 링크](https://www.acmicpc.net/workbook/view/7312) 6 | 7 | | 문제 분류 | 문제 | 문제 제목 | 정답 코드 | 8 | | :--: | :--: | :--: | :--: | 9 | | 연습 문제 | 4949 | [균형잡힌 세상](https://www.acmicpc.net/problem/4949) | [정답 코드](../0x08/solutions/4949.cpp) | 10 | | 기본 문제✔ | 3986 | [좋은 단어](https://www.acmicpc.net/problem/3986) | [정답 코드](../0x08/solutions/3986.cpp) | 11 | | 기본 문제 | 9012 | [괄호](https://www.acmicpc.net/problem/9012) | [정답 코드](../0x08/solutions/9012.cpp) | 12 | | 응용 문제✔ | 10799 | [쇠막대기](https://www.acmicpc.net/problem/10799) | [정답 코드](../0x08/solutions/10799.cpp) | 13 | | 응용 문제✔ | 2504 | [괄호의 값](https://www.acmicpc.net/problem/2504) | [정답 코드](../0x08/solutions/2504.cpp) | 14 | --------------------------------------------------------------------------------