From 3bd1aab7559bc46937f9d0a7834cda05f679d2bb Mon Sep 17 00:00:00 2001 From: DarianTr Date: Tue, 4 Jun 2024 16:41:13 +0200 Subject: [PATCH] unordered_map sometimes better than map: got TLE with map on Collecting_Numbers_II.cpp but AC with unordered_map -unordered is good for a lot of requests and a lot of data --- .autocp | 2 +- .../Collecting_Numbers.cpp | 19 +++++++++ .../Collecting_Numbers_II.cpp | 39 +++++++++++++++++++ CSES - CSES Problem Set/Missing_Coin_Sum.cpp | 27 +++++++++++++ CSES - CSES Problem Set/Stick_Lengths.cpp | 24 ++++++++++++ 5 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 CSES - CSES Problem Set/Collecting_Numbers.cpp create mode 100644 CSES - CSES Problem Set/Collecting_Numbers_II.cpp create mode 100644 CSES - CSES Problem Set/Missing_Coin_Sum.cpp create mode 100644 CSES - CSES Problem Set/Stick_Lengths.cpp diff --git a/.autocp b/.autocp index cb12d5c..a608063 100644 --- a/.autocp +++ b/.autocp @@ -1 +1 @@ -{"version":1,"problems":{"CSES - CSES Problem Set":{"Weird Algorithm":{"name":"Weird Algorithm","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1068/","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n","output":"3 10 5 16 8 4 2 1\n"}],"memoryLimit":512,"timeLimit":1000},"Missing Number":{"name":"Missing Number","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1083","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5\n","output":"4\n"}],"memoryLimit":512,"timeLimit":1000},"Repetitions":{"name":"Repetitions","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1069","sampleTestcases":[{"name":"Sample Testcase #1","input":"ATTCGGGA\n","output":"3\n"}],"memoryLimit":512,"timeLimit":1000},"Increasing Array":{"name":"Increasing Array","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1094","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n3 2 5 1 7\n","output":"5\n"}],"memoryLimit":512,"timeLimit":1000},"Permutations":{"name":"Permutations","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1070","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n","output":"4 2 5 3 1\n"},{"name":"Sample Testcase #2","input":"3\n","output":"NO SOLUTION\n"}],"memoryLimit":512,"timeLimit":1000},"Number Spiral":{"name":"Number Spiral","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1071","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n2 3\n1 1\n4 2\n","output":"8\n1\n15\n"}],"memoryLimit":512,"timeLimit":1000},"Two Knights":{"name":"Two Knights","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1072","sampleTestcases":[{"name":"Sample Testcase #1","input":"8\n","output":"0\n6\n28\n96\n252\n550\n1056\n1848\n"}],"memoryLimit":512,"timeLimit":1000},"Two Sets":{"name":"Two Sets","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1092","sampleTestcases":[{"name":"Sample Testcase #1","input":"7\n","output":"YES\n4\n1 2 4 7\n3\n3 5 6\n"},{"name":"Sample Testcase #2","input":"6\n","output":"NO\n"}],"memoryLimit":512,"timeLimit":1000},"Bit Strings":{"name":"Bit Strings","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1617","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n","output":"8\n"}],"memoryLimit":512,"timeLimit":1000},"Trailing Zeros":{"name":"Trailing Zeros","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1618","sampleTestcases":[{"name":"Sample Testcase #1","input":"20\n","output":"4\n"}],"memoryLimit":512,"timeLimit":1000},"Coin Piles":{"name":"Coin Piles","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1754","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n2 1\n2 2\n3 3\n","output":"YES\nNO\nYES\n"}],"memoryLimit":512,"timeLimit":1000},"Palindrome Reorder":{"name":"Palindrome Reorder","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1755","sampleTestcases":[{"name":"Sample Testcase #1","input":"AAAACACBA\n","output":"AACABACAA\n"}],"memoryLimit":512,"timeLimit":1000},"Gray Code":{"name":"Gray Code","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2205","sampleTestcases":[{"name":"Sample Testcase #1","input":"2\n","output":"00\n01\n11\n10\n"}],"memoryLimit":512,"timeLimit":1000},"Tower of Hanoi":{"name":"Tower of Hanoi","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2165","sampleTestcases":[{"name":"Sample Testcase #1","input":"2\n","output":"3\n1 2\n1 3\n2 3\n"}],"memoryLimit":512,"timeLimit":1000},"Creating Strings":{"name":"Creating Strings","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1622","sampleTestcases":[{"name":"Sample Testcase #1","input":"aabac\n","output":"20\naaabc\naaacb\naabac\naabca\naacab\naacba\nabaac\nabaca\nabcaa\nacaab\nacaba\nacbaa\nbaaac\nbaaca\nbacaa\nbcaaa\ncaaab\ncaaba\ncabaa\ncbaaa\n"}],"memoryLimit":512,"timeLimit":1000},"Apple Division":{"name":"Apple Division","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1623","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n3 2 7 4 1\n","output":"1\n"}],"memoryLimit":512,"timeLimit":1000},"Chessboard and Queens":{"name":"Chessboard and Queens","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1624","sampleTestcases":[{"name":"Sample Testcase #1","input":"........\n........\n..*.....\n........\n........\n.....**.\n...*....\n........\n","output":"65\n"}],"memoryLimit":512,"timeLimit":1000},"Digit Queries":{"name":"Digit Queries","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2431","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n7\n19\n12\n","output":"7\n4\n1\n"}],"memoryLimit":512,"timeLimit":1000},"Grid Paths":{"name":"Grid Paths","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1625","sampleTestcases":[{"name":"Sample Testcase #1","input":"??????R??????U??????????????????????????LD????D?\n","output":"201\n"}],"memoryLimit":512,"timeLimit":1000},"Distinct Numbers":{"name":"Distinct Numbers","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1621","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n2 3 2 2 3\n","output":"2\n"}],"memoryLimit":512,"timeLimit":1000},"Apartments":{"name":"Apartments","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1084","sampleTestcases":[{"name":"Sample Testcase #1","input":"4 3 5\n60 45 80 60\n30 60 75\n","output":"2\n"}],"memoryLimit":512,"timeLimit":1000},"Ferris Wheel":{"name":"Ferris Wheel","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1090","sampleTestcases":[{"name":"Sample Testcase #1","input":"4 10\n7 2 3 9\n","output":"3\n"}],"memoryLimit":512,"timeLimit":1000},"Concert Tickets":{"name":"Concert Tickets","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1091","sampleTestcases":[{"name":"Sample Testcase #1","input":"5 3\n5 3 7 8 5\n4 8 3\n","output":"3\n8\n-1\n"}],"memoryLimit":512,"timeLimit":1000},"Restaurant Customers":{"name":"Restaurant Customers","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1619","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n5 8\n2 4\n3 9\n","output":"2\n"}],"memoryLimit":512,"timeLimit":1000},"Movie Festival":{"name":"Movie Festival","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1629","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n3 5\n4 9\n5 8\n","output":"2\n"}],"memoryLimit":512,"timeLimit":1000},"Sum of Two Values":{"name":"Sum of Two Values","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1640","sampleTestcases":[{"name":"Sample Testcase #1","input":"4 8\n2 7 5 1\n","output":"2 4\n"}],"memoryLimit":512,"timeLimit":1000},"Maximum Subarray Sum":{"name":"Maximum Subarray Sum","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1643","sampleTestcases":[{"name":"Sample Testcase #1","input":"8\n-1 3 -2 5 3 -5 2 2\n","output":"9\n"}],"memoryLimit":512,"timeLimit":1000}}},"solutionFiles":{"CSES - CSES Problem Set/Weird_Algorithm.cpp":{"pathString":"CSES - CSES Problem Set/Weird_Algorithm.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Weird Algorithm"},"testcases":[{"name":"Sample Testcase #1","input":"3\n","output":"3 10 5 16 8 4 2 1\n"}]},"CSES - CSES Problem Set/Missing_Number.cpp":{"pathString":"CSES - CSES Problem Set/Missing_Number.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Missing Number"},"testcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5\n","output":"4\n"}]},"CSES - CSES Problem Set/Repetitions.cpp":{"pathString":"CSES - CSES Problem Set/Repetitions.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Repetitions"},"testcases":[{"name":"Sample Testcase #1","input":"ATTCGGGA\n","output":"3\n"}]},"CSES - CSES Problem Set/Increasing_Array.cpp":{"pathString":"CSES - CSES Problem Set/Increasing_Array.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Increasing Array"},"testcases":[{"name":"Sample Testcase #1","input":"5\n3 2 5 1 7\n","output":"5\n"}]},"CSES - CSES Problem Set/Permutations.cpp":{"pathString":"CSES - CSES Problem Set/Permutations.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Permutations"},"testcases":[{"name":"Sample Testcase #1","input":"5\n","output":"4 2 5 3 1\n"},{"name":"Sample Testcase #2","input":"3\n","output":"NO SOLUTION\n"}]},"CSES - CSES Problem Set/Number_Spiral.cpp":{"pathString":"CSES - CSES Problem Set/Number_Spiral.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Number Spiral"},"testcases":[{"name":"Sample Testcase #1","input":"3\n2 3\n1 1\n4 2\n","output":"8\n1\n15\n"}]},"CSES - CSES Problem Set/Two_Knights.cpp":{"pathString":"CSES - CSES Problem Set/Two_Knights.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Two Knights"},"testcases":[{"name":"Sample Testcase #1","input":"8\n","output":"0\n6\n28\n96\n252\n550\n1056\n1848\n"}]},"CSES - CSES Problem Set/Two_Sets.cpp":{"pathString":"CSES - CSES Problem Set/Two_Sets.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Two Sets"},"testcases":[{"name":"Sample Testcase #1","input":"7\n","output":"YES\n4\n1 2 4 7\n3\n3 5 6\n"},{"name":"Sample Testcase #2","input":"6\n","output":"NO\n"}]},"CSES - CSES Problem Set/Bit_Strings.cpp":{"pathString":"CSES - CSES Problem Set/Bit_Strings.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Bit Strings"},"testcases":[{"name":"Sample Testcase #1","input":"3\n","output":"8\n"}]},"CSES - CSES Problem Set/Trailing_Zeros.cpp":{"pathString":"CSES - CSES Problem Set/Trailing_Zeros.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Trailing Zeros"},"testcases":[{"name":"Sample Testcase #1","input":"20\n","output":"4\n"}]},"CSES - CSES Problem Set/Coin_Piles.cpp":{"pathString":"CSES - CSES Problem Set/Coin_Piles.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Coin Piles"},"testcases":[{"name":"Sample Testcase #1","input":"3\n2 1\n2 2\n3 3\n","output":"YES\nNO\nYES\n"}]},"CSES - CSES Problem Set/Palindrome_Reorder.cpp":{"pathString":"CSES - CSES Problem Set/Palindrome_Reorder.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Palindrome Reorder"},"testcases":[{"name":"Sample Testcase #1","input":"AAAACACBA\n","output":"AACABACAA\n"}]},"CSES - CSES Problem Set/Gray_Code.cpp":{"pathString":"CSES - CSES Problem Set/Gray_Code.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Gray Code"},"testcases":[{"name":"Sample Testcase #1","input":"2\n","output":"00\n01\n11\n10\n"}]},"CSES - CSES Problem Set/Tower_of_Hanoi.cpp":{"pathString":"CSES - CSES Problem Set/Tower_of_Hanoi.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Tower of Hanoi"},"testcases":[{"name":"Sample Testcase #1","input":"2\n","output":"3\n1 2\n1 3\n2 3\n"}]},"CSES - CSES Problem Set/Creating_Strings.cpp":{"pathString":"CSES - CSES Problem Set/Creating_Strings.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Creating Strings"},"testcases":[{"name":"Sample Testcase #1","input":"aabac\n","output":"20\naaabc\naaacb\naabac\naabca\naacab\naacba\nabaac\nabaca\nabcaa\nacaab\nacaba\nacbaa\nbaaac\nbaaca\nbacaa\nbcaaa\ncaaab\ncaaba\ncabaa\ncbaaa\n"}]},"CSES - CSES Problem Set/Apple_Division.cpp":{"pathString":"CSES - CSES Problem Set/Apple_Division.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Apple Division"},"testcases":[{"name":"Sample Testcase #1","input":"5\n3 2 7 4 1\n","output":"1\n"}]},"CSES - CSES Problem Set/Chessboard_and_Queens.cpp":{"pathString":"CSES - CSES Problem Set/Chessboard_and_Queens.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Chessboard and Queens"},"testcases":[{"name":"Sample Testcase #1","input":"........\n........\n..*.....\n........\n........\n.....**.\n...*....\n........\n","output":"65\n"}]},"CSES - CSES Problem Set/Digit_Queries.cpp":{"pathString":"CSES - CSES Problem Set/Digit_Queries.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Digit Queries"},"testcases":[{"name":"Sample Testcase #1","input":"3\n7\n19\n12\n","output":"7\n4\n1\n"}]},"CSES - CSES Problem Set/Grid_Paths.cpp":{"pathString":"CSES - CSES Problem Set/Grid_Paths.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Grid Paths"},"testcases":[{"name":"Sample Testcase #1","input":"??????R??????U??????????????????????????LD????D?\n","output":"201\n"}]},"CSES - CSES Problem Set/Distinct_Numbers.cpp":{"pathString":"CSES - CSES Problem Set/Distinct_Numbers.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Distinct Numbers"},"testcases":[{"name":"Sample Testcase #1","input":"5\n2 3 2 2 3\n","output":"2\n"}]},"CSES - CSES Problem Set/Apartments.cpp":{"pathString":"CSES - CSES Problem Set/Apartments.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Apartments"},"testcases":[{"name":"Sample Testcase #1","input":"4 3 5\n60 45 80 60\n30 60 75\n","output":"2\n"}]},"CSES - CSES Problem Set/Ferris_Wheel.cpp":{"pathString":"CSES - CSES Problem Set/Ferris_Wheel.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Ferris Wheel"},"testcases":[{"name":"Sample Testcase #1","input":"4 10\n7 2 3 9\n","output":"3\n"}]},"CSES - CSES Problem Set/Concert_Tickets.cpp":{"pathString":"CSES - CSES Problem Set/Concert_Tickets.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Concert Tickets"},"testcases":[{"name":"Sample Testcase #1","input":"5 3\n5 3 7 8 5\n4 8 3\n","output":"3\n8\n-1\n"}]},"CSES - CSES Problem Set/Restaurant_Customers.cpp":{"pathString":"CSES - CSES Problem Set/Restaurant_Customers.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Restaurant Customers"},"testcases":[{"name":"Sample Testcase #1","input":"3\n5 8\n2 4\n3 9\n","output":"2\n"}]},"CSES - CSES Problem Set/Movie_Festival.cpp":{"pathString":"CSES - CSES Problem Set/Movie_Festival.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Movie Festival"},"testcases":[{"name":"Sample Testcase #1","input":"3\n3 5\n4 9\n5 8\n","output":"2\n"}]},"CSES - CSES Problem Set/Sum_of_Two_Values.cpp":{"pathString":"CSES - CSES Problem Set/Sum_of_Two_Values.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Sum of Two Values"},"testcases":[{"name":"Sample Testcase #1","input":"4 8\n2 7 5 1\n","output":"2 4\n"}]},"CSES - CSES Problem Set/Maximum_Subarray_Sum.cpp":{"pathString":"CSES - CSES Problem Set/Maximum_Subarray_Sum.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Maximum Subarray Sum"},"testcases":[{"name":"Sample Testcase #1","input":"8\n-1 3 -2 5 3 -5 2 2\n","output":"9\n"}]}}} \ No newline at end of file +{"version":1,"problems":{"CSES - CSES Problem Set":{"Weird Algorithm":{"name":"Weird Algorithm","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1068/","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n","output":"3 10 5 16 8 4 2 1\n"}],"memoryLimit":512,"timeLimit":1000},"Missing Number":{"name":"Missing Number","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1083","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5\n","output":"4\n"}],"memoryLimit":512,"timeLimit":1000},"Repetitions":{"name":"Repetitions","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1069","sampleTestcases":[{"name":"Sample Testcase #1","input":"ATTCGGGA\n","output":"3\n"}],"memoryLimit":512,"timeLimit":1000},"Increasing Array":{"name":"Increasing Array","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1094","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n3 2 5 1 7\n","output":"5\n"}],"memoryLimit":512,"timeLimit":1000},"Permutations":{"name":"Permutations","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1070","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n","output":"4 2 5 3 1\n"},{"name":"Sample Testcase #2","input":"3\n","output":"NO SOLUTION\n"}],"memoryLimit":512,"timeLimit":1000},"Number Spiral":{"name":"Number Spiral","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1071","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n2 3\n1 1\n4 2\n","output":"8\n1\n15\n"}],"memoryLimit":512,"timeLimit":1000},"Two Knights":{"name":"Two Knights","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1072","sampleTestcases":[{"name":"Sample Testcase #1","input":"8\n","output":"0\n6\n28\n96\n252\n550\n1056\n1848\n"}],"memoryLimit":512,"timeLimit":1000},"Two Sets":{"name":"Two Sets","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1092","sampleTestcases":[{"name":"Sample Testcase #1","input":"7\n","output":"YES\n4\n1 2 4 7\n3\n3 5 6\n"},{"name":"Sample Testcase #2","input":"6\n","output":"NO\n"}],"memoryLimit":512,"timeLimit":1000},"Bit Strings":{"name":"Bit Strings","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1617","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n","output":"8\n"}],"memoryLimit":512,"timeLimit":1000},"Trailing Zeros":{"name":"Trailing Zeros","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1618","sampleTestcases":[{"name":"Sample Testcase #1","input":"20\n","output":"4\n"}],"memoryLimit":512,"timeLimit":1000},"Coin Piles":{"name":"Coin Piles","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1754","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n2 1\n2 2\n3 3\n","output":"YES\nNO\nYES\n"}],"memoryLimit":512,"timeLimit":1000},"Palindrome Reorder":{"name":"Palindrome Reorder","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1755","sampleTestcases":[{"name":"Sample Testcase #1","input":"AAAACACBA\n","output":"AACABACAA\n"}],"memoryLimit":512,"timeLimit":1000},"Gray Code":{"name":"Gray Code","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2205","sampleTestcases":[{"name":"Sample Testcase #1","input":"2\n","output":"00\n01\n11\n10\n"}],"memoryLimit":512,"timeLimit":1000},"Tower of Hanoi":{"name":"Tower of Hanoi","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2165","sampleTestcases":[{"name":"Sample Testcase #1","input":"2\n","output":"3\n1 2\n1 3\n2 3\n"}],"memoryLimit":512,"timeLimit":1000},"Creating Strings":{"name":"Creating Strings","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1622","sampleTestcases":[{"name":"Sample Testcase #1","input":"aabac\n","output":"20\naaabc\naaacb\naabac\naabca\naacab\naacba\nabaac\nabaca\nabcaa\nacaab\nacaba\nacbaa\nbaaac\nbaaca\nbacaa\nbcaaa\ncaaab\ncaaba\ncabaa\ncbaaa\n"}],"memoryLimit":512,"timeLimit":1000},"Apple Division":{"name":"Apple Division","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1623","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n3 2 7 4 1\n","output":"1\n"}],"memoryLimit":512,"timeLimit":1000},"Chessboard and Queens":{"name":"Chessboard and Queens","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1624","sampleTestcases":[{"name":"Sample Testcase #1","input":"........\n........\n..*.....\n........\n........\n.....**.\n...*....\n........\n","output":"65\n"}],"memoryLimit":512,"timeLimit":1000},"Digit Queries":{"name":"Digit Queries","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2431","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n7\n19\n12\n","output":"7\n4\n1\n"}],"memoryLimit":512,"timeLimit":1000},"Grid Paths":{"name":"Grid Paths","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1625","sampleTestcases":[{"name":"Sample Testcase #1","input":"??????R??????U??????????????????????????LD????D?\n","output":"201\n"}],"memoryLimit":512,"timeLimit":1000},"Distinct Numbers":{"name":"Distinct Numbers","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1621","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n2 3 2 2 3\n","output":"2\n"}],"memoryLimit":512,"timeLimit":1000},"Apartments":{"name":"Apartments","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1084","sampleTestcases":[{"name":"Sample Testcase #1","input":"4 3 5\n60 45 80 60\n30 60 75\n","output":"2\n"}],"memoryLimit":512,"timeLimit":1000},"Ferris Wheel":{"name":"Ferris Wheel","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1090","sampleTestcases":[{"name":"Sample Testcase #1","input":"4 10\n7 2 3 9\n","output":"3\n"}],"memoryLimit":512,"timeLimit":1000},"Concert Tickets":{"name":"Concert Tickets","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1091","sampleTestcases":[{"name":"Sample Testcase #1","input":"5 3\n5 3 7 8 5\n4 8 3\n","output":"3\n8\n-1\n"}],"memoryLimit":512,"timeLimit":1000},"Restaurant Customers":{"name":"Restaurant Customers","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1619","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n5 8\n2 4\n3 9\n","output":"2\n"}],"memoryLimit":512,"timeLimit":1000},"Movie Festival":{"name":"Movie Festival","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1629","sampleTestcases":[{"name":"Sample Testcase #1","input":"3\n3 5\n4 9\n5 8\n","output":"2\n"}],"memoryLimit":512,"timeLimit":1000},"Sum of Two Values":{"name":"Sum of Two Values","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1640","sampleTestcases":[{"name":"Sample Testcase #1","input":"4 8\n2 7 5 1\n","output":"2 4\n"}],"memoryLimit":512,"timeLimit":1000},"Maximum Subarray Sum":{"name":"Maximum Subarray Sum","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1643","sampleTestcases":[{"name":"Sample Testcase #1","input":"8\n-1 3 -2 5 3 -5 2 2\n","output":"9\n"}],"memoryLimit":512,"timeLimit":1000},"Stick Lengths":{"name":"Stick Lengths","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/1074","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5 2\n","output":"5\n"}],"memoryLimit":512,"timeLimit":1000},"Missing Coin Sum":{"name":"Missing Coin Sum","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2183","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n2 9 1 2 7\n","output":"6\n"}],"memoryLimit":512,"timeLimit":1000},"Collecting Numbers":{"name":"Collecting Numbers","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2216","sampleTestcases":[{"name":"Sample Testcase #1","input":"5\n4 2 1 5 3\n","output":"3\n"}],"memoryLimit":512,"timeLimit":1000},"Collecting Numbers II":{"name":"Collecting Numbers II","groupName":"CSES - CSES Problem Set","url":"https://cses.fi/problemset/task/2217","sampleTestcases":[{"name":"Sample Testcase #1","input":"5 3\n4 2 1 5 3\n2 3\n1 5\n2 3\n","output":"2\n3\n4\n"}],"memoryLimit":512,"timeLimit":1000}}},"solutionFiles":{"CSES - CSES Problem Set/Weird_Algorithm.cpp":{"pathString":"CSES - CSES Problem Set/Weird_Algorithm.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Weird Algorithm"},"testcases":[{"name":"Sample Testcase #1","input":"3\n","output":"3 10 5 16 8 4 2 1\n"}]},"CSES - CSES Problem Set/Missing_Number.cpp":{"pathString":"CSES - CSES Problem Set/Missing_Number.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Missing Number"},"testcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5\n","output":"4\n"}]},"CSES - CSES Problem Set/Repetitions.cpp":{"pathString":"CSES - CSES Problem Set/Repetitions.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Repetitions"},"testcases":[{"name":"Sample Testcase #1","input":"ATTCGGGA\n","output":"3\n"}]},"CSES - CSES Problem Set/Increasing_Array.cpp":{"pathString":"CSES - CSES Problem Set/Increasing_Array.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Increasing Array"},"testcases":[{"name":"Sample Testcase #1","input":"5\n3 2 5 1 7\n","output":"5\n"}]},"CSES - CSES Problem Set/Permutations.cpp":{"pathString":"CSES - CSES Problem Set/Permutations.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Permutations"},"testcases":[{"name":"Sample Testcase #1","input":"5\n","output":"4 2 5 3 1\n"},{"name":"Sample Testcase #2","input":"3\n","output":"NO SOLUTION\n"}]},"CSES - CSES Problem Set/Number_Spiral.cpp":{"pathString":"CSES - CSES Problem Set/Number_Spiral.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Number Spiral"},"testcases":[{"name":"Sample Testcase #1","input":"3\n2 3\n1 1\n4 2\n","output":"8\n1\n15\n"}]},"CSES - CSES Problem Set/Two_Knights.cpp":{"pathString":"CSES - CSES Problem Set/Two_Knights.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Two Knights"},"testcases":[{"name":"Sample Testcase #1","input":"8\n","output":"0\n6\n28\n96\n252\n550\n1056\n1848\n"}]},"CSES - CSES Problem Set/Two_Sets.cpp":{"pathString":"CSES - CSES Problem Set/Two_Sets.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Two Sets"},"testcases":[{"name":"Sample Testcase #1","input":"7\n","output":"YES\n4\n1 2 4 7\n3\n3 5 6\n"},{"name":"Sample Testcase #2","input":"6\n","output":"NO\n"}]},"CSES - CSES Problem Set/Bit_Strings.cpp":{"pathString":"CSES - CSES Problem Set/Bit_Strings.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Bit Strings"},"testcases":[{"name":"Sample Testcase #1","input":"3\n","output":"8\n"}]},"CSES - CSES Problem Set/Trailing_Zeros.cpp":{"pathString":"CSES - CSES Problem Set/Trailing_Zeros.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Trailing Zeros"},"testcases":[{"name":"Sample Testcase #1","input":"20\n","output":"4\n"}]},"CSES - CSES Problem Set/Coin_Piles.cpp":{"pathString":"CSES - CSES Problem Set/Coin_Piles.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Coin Piles"},"testcases":[{"name":"Sample Testcase #1","input":"3\n2 1\n2 2\n3 3\n","output":"YES\nNO\nYES\n"}]},"CSES - CSES Problem Set/Palindrome_Reorder.cpp":{"pathString":"CSES - CSES Problem Set/Palindrome_Reorder.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Palindrome Reorder"},"testcases":[{"name":"Sample Testcase #1","input":"AAAACACBA\n","output":"AACABACAA\n"}]},"CSES - CSES Problem Set/Gray_Code.cpp":{"pathString":"CSES - CSES Problem Set/Gray_Code.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Gray Code"},"testcases":[{"name":"Sample Testcase #1","input":"2\n","output":"00\n01\n11\n10\n"}]},"CSES - CSES Problem Set/Tower_of_Hanoi.cpp":{"pathString":"CSES - CSES Problem Set/Tower_of_Hanoi.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Tower of Hanoi"},"testcases":[{"name":"Sample Testcase #1","input":"2\n","output":"3\n1 2\n1 3\n2 3\n"}]},"CSES - CSES Problem Set/Creating_Strings.cpp":{"pathString":"CSES - CSES Problem Set/Creating_Strings.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Creating Strings"},"testcases":[{"name":"Sample Testcase #1","input":"aabac\n","output":"20\naaabc\naaacb\naabac\naabca\naacab\naacba\nabaac\nabaca\nabcaa\nacaab\nacaba\nacbaa\nbaaac\nbaaca\nbacaa\nbcaaa\ncaaab\ncaaba\ncabaa\ncbaaa\n"}]},"CSES - CSES Problem Set/Apple_Division.cpp":{"pathString":"CSES - CSES Problem Set/Apple_Division.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Apple Division"},"testcases":[{"name":"Sample Testcase #1","input":"5\n3 2 7 4 1\n","output":"1\n"}]},"CSES - CSES Problem Set/Chessboard_and_Queens.cpp":{"pathString":"CSES - CSES Problem Set/Chessboard_and_Queens.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Chessboard and Queens"},"testcases":[{"name":"Sample Testcase #1","input":"........\n........\n..*.....\n........\n........\n.....**.\n...*....\n........\n","output":"65\n"}]},"CSES - CSES Problem Set/Digit_Queries.cpp":{"pathString":"CSES - CSES Problem Set/Digit_Queries.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Digit Queries"},"testcases":[{"name":"Sample Testcase #1","input":"3\n7\n19\n12\n","output":"7\n4\n1\n"}]},"CSES - CSES Problem Set/Grid_Paths.cpp":{"pathString":"CSES - CSES Problem Set/Grid_Paths.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Grid Paths"},"testcases":[{"name":"Sample Testcase #1","input":"??????R??????U??????????????????????????LD????D?\n","output":"201\n"}]},"CSES - CSES Problem Set/Distinct_Numbers.cpp":{"pathString":"CSES - CSES Problem Set/Distinct_Numbers.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Distinct Numbers"},"testcases":[{"name":"Sample Testcase #1","input":"5\n2 3 2 2 3\n","output":"2\n"}]},"CSES - CSES Problem Set/Apartments.cpp":{"pathString":"CSES - CSES Problem Set/Apartments.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Apartments"},"testcases":[{"name":"Sample Testcase #1","input":"4 3 5\n60 45 80 60\n30 60 75\n","output":"2\n"}]},"CSES - CSES Problem Set/Ferris_Wheel.cpp":{"pathString":"CSES - CSES Problem Set/Ferris_Wheel.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Ferris Wheel"},"testcases":[{"name":"Sample Testcase #1","input":"4 10\n7 2 3 9\n","output":"3\n"}]},"CSES - CSES Problem Set/Concert_Tickets.cpp":{"pathString":"CSES - CSES Problem Set/Concert_Tickets.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Concert Tickets"},"testcases":[{"name":"Sample Testcase #1","input":"5 3\n5 3 7 8 5\n4 8 3\n","output":"3\n8\n-1\n"}]},"CSES - CSES Problem Set/Restaurant_Customers.cpp":{"pathString":"CSES - CSES Problem Set/Restaurant_Customers.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Restaurant Customers"},"testcases":[{"name":"Sample Testcase #1","input":"3\n5 8\n2 4\n3 9\n","output":"2\n"}]},"CSES - CSES Problem Set/Movie_Festival.cpp":{"pathString":"CSES - CSES Problem Set/Movie_Festival.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Movie Festival"},"testcases":[{"name":"Sample Testcase #1","input":"3\n3 5\n4 9\n5 8\n","output":"2\n"}]},"CSES - CSES Problem Set/Sum_of_Two_Values.cpp":{"pathString":"CSES - CSES Problem Set/Sum_of_Two_Values.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Sum of Two Values"},"testcases":[{"name":"Sample Testcase #1","input":"4 8\n2 7 5 1\n","output":"2 4\n"}]},"CSES - CSES Problem Set/Maximum_Subarray_Sum.cpp":{"pathString":"CSES - CSES Problem Set/Maximum_Subarray_Sum.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Maximum Subarray Sum"},"testcases":[{"name":"Sample Testcase #1","input":"8\n-1 3 -2 5 3 -5 2 2\n","output":"9\n"}]},"CSES - CSES Problem Set/Stick_Lengths.cpp":{"pathString":"CSES - CSES Problem Set/Stick_Lengths.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Stick Lengths"},"testcases":[{"name":"Sample Testcase #1","input":"5\n2 3 1 5 2\n","output":"5\n"}]},"CSES - CSES Problem Set/Missing_Coin_Sum.cpp":{"pathString":"CSES - CSES Problem Set/Missing_Coin_Sum.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Missing Coin Sum"},"testcases":[{"name":"Sample Testcase #1","input":"5\n2 9 1 2 7\n","output":"6\n"}]},"CSES - CSES Problem Set/Collecting_Numbers.cpp":{"pathString":"CSES - CSES Problem Set/Collecting_Numbers.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Collecting Numbers"},"testcases":[{"name":"Sample Testcase #1","input":"5\n4 2 1 5 3\n","output":"3\n"}]},"CSES - CSES Problem Set/Collecting_Numbers_II.cpp":{"pathString":"CSES - CSES Problem Set/Collecting_Numbers_II.cpp","linkedProblemId":{"first":"CSES - CSES Problem Set","second":"Collecting Numbers II"},"testcases":[{"name":"Sample Testcase #1","input":"5 3\n4 2 1 5 3\n2 3\n1 5\n2 3\n","output":"2\n3\n4\n"}]}}} \ No newline at end of file diff --git a/CSES - CSES Problem Set/Collecting_Numbers.cpp b/CSES - CSES Problem Set/Collecting_Numbers.cpp new file mode 100644 index 0000000..c1213a2 --- /dev/null +++ b/CSES - CSES Problem Set/Collecting_Numbers.cpp @@ -0,0 +1,19 @@ +// Collecting Numbers + +#include + +using namespace std; + +int main() { + int n; cin >> n; + vector in(n); + for (auto &e: in) cin >> e; + int count = 1; + map pos; + for (int i{}; i < n; i++) pos[in[i]] = i; + for (int i = 1; i < n; i++) { + if (pos[i] > pos[i+1]) count ++; + } + cout << count << endl; + return 0; +} diff --git a/CSES - CSES Problem Set/Collecting_Numbers_II.cpp b/CSES - CSES Problem Set/Collecting_Numbers_II.cpp new file mode 100644 index 0000000..7aab5fc --- /dev/null +++ b/CSES - CSES Problem Set/Collecting_Numbers_II.cpp @@ -0,0 +1,39 @@ +// Collecting Numbers II + +#include + +using namespace std; + +int main() { + int n; cin >> n; + int m; cin >> m; + vector in(n); + for (auto &e: in) cin >> e; + int count = 1; + unordered_map pos; + for (int i{}; i < n; i++) pos[in[i]] = i; + for (int i = 1; i < n; i++) { + if (pos[i] > pos[i+1]) count ++; + } +// cout << count << endl; + for (int i{}; i < m; i++) { + int a, b; cin >> a >> b; + + + if (in[a - 1] > 1 && pos[in[a - 1] - 1] > a - 1 && pos[in[a - 1] - 1] <= b - 1) count--; + if (in[a - 1] > 1 && pos[in[a - 1] - 1] < a - 1 && pos[in[a - 1] - 1] >= b - 1) count++; + if (in[a - 1] < n && pos[in[a - 1] + 1] > a - 1 && pos[in[a - 1] + 1] <= b - 1) count++; // + if (in[a - 1] < n && pos[in[a - 1] + 1] < a - 1 && pos[in[a - 1] + 1] >= b - 1) count--; + + if (in[b - 1] > 1 && pos[in[b - 1] - 1] > a - 1 && pos[in[b - 1] - 1] < b - 1) count++; + if (in[b - 1] > 1 && pos[in[b - 1] - 1] < a - 1 && pos[in[b - 1] - 1] > b - 1) count--; + if (in[b - 1] < n && pos[in[b - 1] + 1] > a - 1 && pos[in[b - 1] + 1] < b - 1) count--; + if (in[b - 1] < n && pos[in[b - 1] + 1] < a - 1 && pos[in[b - 1] + 1] > b - 1) count++; + + pos[in[a - 1]] = b - 1; + pos[in[b - 1]] = a - 1; + swap(in[a-1], in[b-1]); + cout << count << endl; + } + return 0; +} diff --git a/CSES - CSES Problem Set/Missing_Coin_Sum.cpp b/CSES - CSES Problem Set/Missing_Coin_Sum.cpp new file mode 100644 index 0000000..986400a --- /dev/null +++ b/CSES - CSES Problem Set/Missing_Coin_Sum.cpp @@ -0,0 +1,27 @@ +// Missing Coin Sum + +#include + +using namespace std; +using ll = long long; + +int main() { + int n; cin >> n; + vector coins(n); + for (auto &e: coins) cin >> e; + std::sort(coins.begin(), coins.end()); + + ll sum = 0; + + for (int i{}; i < n; i++) { + if (coins[i] - 1 > sum) { + break; + } else { + sum += coins[i]; + } + } + + cout << sum + 1 << endl; + + return 0; +} diff --git a/CSES - CSES Problem Set/Stick_Lengths.cpp b/CSES - CSES Problem Set/Stick_Lengths.cpp new file mode 100644 index 0000000..05e858b --- /dev/null +++ b/CSES - CSES Problem Set/Stick_Lengths.cpp @@ -0,0 +1,24 @@ +// Stick Lengths + +#include + +using namespace std; +using ll = long long; + +int main() { + int n; cin >> n; + vector in(n); + for (auto &e: in) cin >> e; + std::sort(in.begin(), in.end()); + ll target = in[n/2]; + ll target2 = in[n/2 + 1]; + ll count = 0, count2 = 0; + for (auto e: in) { + count += abs(target - e); + count2 += abs(target2 - e); + } + cout << min(count, count2) << endl; + + + return 0; +}