|
1 | | -#### Basic Staff Until cf rating <=1300 |
2 | | - |
3 | | -## Some Basics |
4 | | - |
5 | | -https://codeforces.com/blog/entry/111099 |
6 | | - |
7 | | -#to be good at competitive programming, you have to know "what to think" and "how to think" when you try a problem. |
8 | | - |
9 | | -"What to think": |
10 | | - |
11 | | -<pre> |
12 | | -you have to know a decent amount of standard problems / techniques. Sometimes, a problem requires steps / observations that seem obvious if you've already seen them. Other times, you may solve a problem by reducing it to a well-known sub-problem. On the other hand, you may realize you've done something wrong if you "reduce" the problem to something that you know it's unsolvable under the given constraints. All this isn't possible if you don't know those standard problems. |
13 | | -</pre> |
14 | | - |
15 | | -"How to think": |
16 | | - |
17 | | -<pre> |
18 | | -it comes down to "building" a path to the solution. Sometimes, you need to find new insights / observations by analyzing the process in the statement, manipulating math equations, etc. Other times, you need to find a twist to a well-known technique. You can practice "how to think" by solving ad-hoc / non-standard problems. |
19 | | -</pre> |
20 | | - |
21 | | -https://github.com/ShahjalalShohag/Competitive-Programming-A-Complete-Guideline?tab=readme-ov-file#problems-and-algorithms |
22 | | - |
23 | | -### How to Read Problem Statements? |
24 | | - |
25 | | -- Read the problem statement thoroughly. Try to understand what the problem is asking you to do. |
26 | | -- Identify the key information, constraints, and requirements. |
27 | | -- Break the problem down into smaller parts or subproblems. |
28 | | -- Pay attention to input-output limitations and samples provided in the statement. |
29 | | -- Analyze the sample test cases and try to understand the problem better. |
30 | | -- Check out the notes section of the problem statement. It may contain some useful information. |
31 | | -- Use pen and paper to draw stuff to better understand the problem. |
32 | | -- If you are still confused, try to read the problem statement again. |
33 | | - |
34 | | -### How to Solve a Problem? |
35 | | - |
36 | | -<details> |
37 | | - <summary><strong>1. Understand the problem statement</strong></summary> |
38 | | - <p>This is crucial. Make sure you understand what the problem is asking for, the constraints you have to work with, and the input and output formats. Misunderstanding any part of the problem can lead to a solution that doesn't work.</p> |
39 | | -</details> |
40 | | - |
41 | | -<details> |
42 | | - <summary><strong>2. Break It Down</strong></summary> |
43 | | - <p>Most problems are easier to solve when broken down into smaller, manageable parts. Identify the different components of the problem and try to understand how they relate to each other.</p> |
44 | | -</details> |
45 | | - |
46 | | -<details> |
47 | | - <summary><strong>3. Make a Plan/Algorithm</strong></summary> |
48 | | - <p>Once you've broken down the problem, you should have a better idea of how to solve it. Formulate a strategy for solving the problem. Use pen and paper to write down the steps you need to take to solve the problem. You should have a clear idea of your solution before you start writing the code for it.</p> |
49 | | -</details> |
50 | | - |
51 | | -<details> |
52 | | - <summary><strong>4. Write the Code</strong></summary> |
53 | | - <p>Once you have a solid plan, you can start coding. Write your code carefully, keeping it as clean and clear as possible. This will make it easier to debug and improve later.</p> |
54 | | -</details> |
55 | | - |
56 | | -<details> |
57 | | - <summary><strong>5. Test Your Solution</strong></summary> |
58 | | - <p>Once you've written your code, you should test it against the sample test cases provided in the problem statement. If your solution passes all the sample test cases, you can submit it. You can also try to come up with your own test cases to check your solution.</p> |
59 | | -</details> |
60 | | - |
61 | | -<details> |
62 | | - <summary><strong>6. Debug and Improve</strong></summary> |
63 | | - <p>If your solution doesn't pass all the sample test cases, you should debug it. Go through your code line by line and check if it's doing what you expect it to do. If you find any bugs, fix them and test your solution again.</p> |
64 | | - <code>Print and Check</code> |
65 | | -</details> |
66 | | - |
67 | | -<details> |
68 | | - <summary><strong>7. Optimize Your Code</strong></summary> |
69 | | - <p>Once your code is working correctly, see if there's any way to make it more efficient. Can you reduce its time complexity? Can you use less memory? Optimizing your code is good practice.</p> |
70 | | -</details> |
71 | | - |
72 | | -<details> |
73 | | - <summary><strong>8. Submit Your Solution</strong></summary> |
74 | | - <p>Once you're satisfied with your solution, you can submit it. Even if you're confident in your solution, be prepared for the possibility of it being rejected. If it is, use it as an opportunity to learn and improve.</p> |
75 | | -</details> |
76 | | - |
77 | | - # Always try to solve the problem using bruteforce. |
78 | | - # Then optimize it. |
79 | | - |
80 | | - while(fail){ |
81 | | - - If previous approach fail then try another approaches. |
82 | | - - Make algorithm first, code it later. |
83 | | - } |
84 | | - |
85 | | -### Verdicts |
86 | | - |
87 | | -Once you submit your code, you will get a verdict based on multiple criteria. The most common verdicts are:#### Basic Geometry |
88 | | - |
89 | | -<details> |
90 | | - <summary><strong>Wrong Answer (WA)</strong></summary> |
91 | | - <p>Your program gave an incorrect output for a specific test case. As a result, it wasn't executed on the remaining test set. Note that the test cases are hidden, so you won't be able to see the test case on which your program failed.</p> |
92 | | -</details> |
93 | | - |
94 | | -<details> |
95 | | - <summary><strong>Compilation Error (CE)</strong></summary> |
96 | | - <p>Your code failed to compile, likely due to a syntactic error. Solve the error by testing your code locally. Make sure you've selected the correct compiler upon submission.</p> |
97 | | -</details> |
98 | | - |
99 | | -<details> |
100 | | - <summary><strong>Runtime Error (RE)</strong></summary> |
101 | | - <p>A fault occurred during the execution of your program. This could be due to issues like accessing an out-of-bound array index, dividing by zero, and so on.</p> |
102 | | -</details> |
103 | | - |
104 | | -<details> |
105 | | - <summary><strong>Time Limit Exceeded (TLE)</strong></summary> |
106 | | - <p>Your program took more time to run than the specified limit. Note that, the execution time is the maximum time taken by your program to run on any test case. So, if your program is taking too much time on a specific test case, then it will get a TLE verdict.</p> |
107 | | -</details> |
108 | | - |
109 | | -<details> |
110 | | - <summary><strong>Memory Limit Exceeded (MLE)</strong></summary> |
111 | | - <p>Similar to TLE, your program used more memory than the allowed limit.</p> |
112 | | -</details> |
113 | | - |
114 | | -<details> |
115 | | - <summary><strong>Presentation Error (PE)</strong></summary> |
116 | | - <p>Your program ran successfully, and the output is correct, but the <em>output format</em> is incorrect. This is usually due to a missing space, newline, or an extra space or newline.</p> |
117 | | -</details> |
118 | | - |
119 | | -Note that your code first gets compiled and then gets executed. That's why you will get a CE verdict even before it gets executed. |
120 | | - |
121 | | -# |
122 | | - |
123 | | -### Useful Keyboard Shortcuts |
124 | | - |
125 | | -Shortcuts for Windows / Mac are given side by side. |
126 | | - |
127 | | -#### General |
128 | | - |
129 | | - 1. `Ctrl + S` / `Cmd + S`: Save - Saves the current file or document. |
130 | | - 2. `Ctrl + Shift + S` / `Cmd + Shift + S`: Save As - Saves the current file with a different name or location. |
131 | | - 3. `Ctrl + C` / `Cmd + C`: Copy - Copies the selected text or item. |
132 | | - 4. `Ctrl + V` / `Cmd + V`: Paste - Pastes the copied or cut text or item. |
133 | | - 5. `Ctrl + X` / `Cmd + X`: Cut - Cuts the selected text or item. |
134 | | - 6. `Ctrl + Z` / `Cmd + Z`: Undo - Reverses the last action. |
135 | | - 7. `Ctrl + Y` / `Cmd + Y`: Redo - Reverses the last undo action. |
136 | | - 8. `Ctrl + F` / `Cmd + F`: Find - Opens a search bar to find text within the current document or page. |
137 | | - 9. `Ctrl + A` / `Cmd + A`: Select All - Selects all text or items in the current document or window. |
138 | | - 10. `Alt + Tab` / `Cmd + Tab`: Switch Application - Switches between open applications or windows. |
139 | | - 11. `Ctrl + O` / `Cmd + O`: Open File - Opens a file for editing. |
140 | | - 12. `Ctrl + N` / `Cmd + N`: New File - Creates a new file. |
141 | | - |
142 | | -#### Sublime Text Specific |
143 | | - |
144 | | - 1. `Ctrl + P` / `Cmd + P`: Go to File - Allows you to search for a file in the current project. |
145 | | - 2. `Ctrl + D` / `Cmd + D`: Multiple Selections - Selects the next occurrence of the current word or selection and allows you to edit them all at once! |
146 | | - 3. `Ctrl + /` / `Cmd + /`: Toggle Comment - Comments out the selected code or text. |
147 | | - 4. `Ctrl + F5` / `Cmd + B`: Build/Run - Builds or runs the current file. |
148 | | - 5. `Ctrl + Shift + D` / `Cmd + Shift + D`: Duplicate - Duplicates the selected text or line. |
149 | | - 6. `Ctrl + K + B` / `Cmd + K + B`: Toggle Sidebar - Shows or hides the sidebar. |
150 | | - 7. `Ctrl + Shift + Up Arrow` / `Cmd + Shift + Up Arrow`: Move Line Up - Moves the current line or selection up by one line. |
151 | | - 8. `Ctrl + Shift + Down Arrow` / `Cmd + Shift + Down Arrow`: Move Line Down - Moves the current line or selection down by one line. |
152 | | - 9. `Ctrl + Shift + N` / `Cmd + Shift + N`: New file - Creates a new file. |
153 | | - |
154 | | -Note that you can change the shortcuts in sublime text by going to `Preferences > Key Bindings`. |
155 | | - |
156 | | -- [Self-deception: maybe why you're still grey after practicing every day](https://codeforces.com/blog/entry/98621) |
157 | | -- [The Forcing Fallacy](https://codeforces.com/blog/entry/106346) |
158 | | - |
159 | 1 | --- |
160 | | - |
161 | | -- Constant Optimization |
162 | | - |
163 | | - <pre> |
164 | | - - constant factors are the hidden constants in the time or space complexity of an algorithm. |
165 | | - |
166 | | - some tricks to reduce the hidden constants |
167 | | - - use '\n' instead of endl |
168 | | - - efficient i/o -> fastio |
169 | | - - efficient data structures -> use arrays/vectors instead of deque -> use something that has lower constant factors |
170 | | - - bit manipulation is faster than arithmetic operations |
171 | | - - modulo is slower than other arithmetic operations |
172 | | - - recursion is slower than iteration |
173 | | - - float/double are slower than integer |
174 | | - - const is faster than normal variable |
175 | | - - big data type is slower than small data type |
176 | | - - accessing big array is slower than small array |
177 | | - </pre> |
178 | | - |
179 | | -- Necessity and Sufficiency |
180 | | - |
181 | | - <pre> |
182 | | - - a necessary condition is a condition that must be present for a event to occur (ex. prime number always odd) |
183 | | - - a sufficient condition is a condition that, if present, guarantees that the event will occur (ex. all odd number can't be prime, it mustn't divide any number except(1,same number)) |
184 | | - </pre> |
185 | | - |
186 | | - https://codeforces.com/problemset/problem/1750/A |
187 | | - |
| 2 | +layout: category |
| 3 | +title: 00 cp math basics/ |
188 | 4 | --- |
189 | 5 |
|
190 | | -### Fast Input & Output |
191 | | - |
192 | | -https://usaco.guide/general/fast-io?lang=cpp |
193 | | - |
194 | | -- input/output is slow operation |
195 | | - |
196 | | -<code>ios::sync_with_stdio(false)</code> |
197 | | - |
198 | | -This disables the synchronization between the C and C++ standard streams. By default, all standard streams are synchronized, which in practice allows you to mix C- and C++-style I/O and get sensible and expected results. If you disable the synchronization, then C++ streams are allowed to have their own independent buffers, which makes mixing C- and C++-style I/O an adventure. |
199 | | - |
200 | | -<code>cin.tie(nullptr)</code> |
201 | | - |
202 | | -This unties cin from cout. Tied streams ensure that one stream is flushed automatically before each I/O operation on the other stream. |
203 | | - |
204 | | -By default cin is tied to cout to ensure a sensible user interaction. |
205 | | - |
206 | | -- we have to use '\n' instead of endl; |
207 | | - |
208 | | - endl -> '\n'+flush(buffer clear) |
209 | | - |
210 | | ---- |
211 | | - |
212 | | -#### Input with spaces |
213 | | - |
214 | | -- cin.getline(s,n); |
215 | | -- using getline() instead of get() |
216 | | - |
217 | | -```cpp |
218 | | -char c[100]; |
219 | | -int n; cin >> n; |
220 | | -//cin.get(); //without these we find n-1 getline().. |
221 | | -//because n '\n'..counted as first line. upto '\n' it count a line |
222 | | -//char ch = getchar();//alternative |
223 | | -cin.ignore(); |
224 | | -while (n--) { |
225 | | - cin.getline(c, 100); |
226 | | -} |
227 | | -``` |
228 | | - |
229 | | -### End Of File (EOF) |
230 | | - |
231 | | -Input untill end of file |
232 | | - |
233 | | -```cpp |
234 | | -while(cin>>x){ |
235 | | - ans+=x; |
236 | | -} |
237 | | -``` |
| 6 | +### Solutions |
| 7 | +- [1512A_Spy Detected!](1512A_Spy Detected!) |
| 8 | +- [cses1068_Weird Algorithm](cses1068_Weird Algorithm) |
| 9 | +- [1633C_Kill the Monster](1633C_Kill the Monster) |
| 10 | +- [leetcode_find-the-distance-value-between-two-arrays](leetcode_find-the-distance-value-between-two-arrays) |
| 11 | +- [758A_Holiday Of Equality](758A_Holiday Of Equality) |
| 12 | +- [cses1071_Number Spiral](cses1071_Number Spiral) |
| 13 | +- [219158W_Mathematical Expression](219158W_Mathematical Expression) |
| 14 | +- [219774O_Fibonacci](219774O_Fibonacci) |
| 15 | +- [1335C_Two Teams Composing](1335C_Two Teams Composing) |
| 16 | +- [abc258_a_When](abc258_a_When) |
| 17 | +- [214A_System of Equations](214A_System of Equations) |
| 18 | +- [1269A_Equation](1269A_Equation) |
| 19 | +- [abc263_a_Full House](abc263_a_Full House) |
| 20 | +- [number_of_unique_element_in_each_prefix](number_of_unique_element_in_each_prefix) |
| 21 | +- [lexicographical_compare](lexicographical_compare) |
| 22 | +- [after_query_print_unique](after_query_print_unique) |
| 23 | +- [sort_5d_points](sort_5d_points) |
| 24 | +- [sort_from_origin](sort_from_origin) |
| 25 | +- [binary_string_difference_pair](binary_string_difference_pair) |
| 26 | +- [remove_b_from_a](remove_b_from_a) |
| 27 | +- [balanced_bracket](balanced_bracket) |
| 28 | +- [kth_smallest_in_each_prefix](kth_smallest_in_each_prefix) |
| 29 | +- [sliding_window_sum](sliding_window_sum) |
| 30 | +- [occurrences](occurrences) |
| 31 | +- [word_frequency](word_frequency) |
| 32 | +- [1574B_Combinatorics Homework](1574B_Combinatorics Homework) |
| 33 | +- [2D_to_1D](2D_to_1D) |
| 34 | +- [subarray_sum_modn](subarray_sum_modn) |
| 35 | +- [subArray](subArray) |
| 36 | +- [num_of_pairSum_modN](num_of_pairSum_modN) |
| 37 | +- [subarray_xor_zero](subarray_xor_zero) |
| 38 | +- [subSequence_array](subSequence_array) |
| 39 | +- [subSet](subSet) |
| 40 | +- [subString](subString) |
| 41 | +- [271A_Beautiful Year](271A_Beautiful Year) |
| 42 | +- [1428C_ABBB](1428C_ABBB) |
| 43 | +- [219158N_Char](219158N_Char) |
| 44 | +- [320A_Magic Numbers](320A_Magic Numbers) |
| 45 | +- [subSequence](subSequence) |
| 46 | +- [1496A_Split it!](1496A_Split it!) |
| 47 | +- [lightoj_equal](lightoj_equal) |
| 48 | +- [cses1755_Palindrome Reorder](cses1755_Palindrome Reorder) |
| 49 | +- [219158K_Max and Min](219158K_Max and Min) |
| 50 | +- [219432C_Even, Odd, Positive and Negative](219432C_Even, Odd, Positive and Negative) |
| 51 | +- [219158L_The Brothers](219158L_The Brothers) |
| 52 | +- [329103G_Even Hate Odd](329103G_Even Hate Odd) |
| 53 | +- [219158Z_Hard Compare](219158Z_Hard Compare) |
| 54 | +- [219158I_Welcome for you with Conditions](219158I_Welcome for you with Conditions) |
| 55 | +- [219158U_Float or int](219158U_Float or int) |
| 56 | +- [1535A_Fair Playoff](1535A_Fair Playoff) |
| 57 | +- [219158V_Comparison](219158V_Comparison) |
| 58 | +- [343A_Rational Resistance](343A_Rational Resistance) |
| 59 | +- [hr_number-groups](hr_number-groups) |
| 60 | +- [1A_Theatre Square](1A_Theatre Square) |
| 61 | +- [219158F_Digits Summation](219158F_Digits Summation) |
| 62 | +- [326907D_Range Sum](326907D_Range Sum) |
| 63 | +- [cses1094_Increasing Array](cses1094_Increasing Array) |
| 64 | +- [cses1083_Missing Number](cses1083_Missing Number) |
| 65 | +- [735D_Taxes](735D_Taxes) |
| 66 | +- [1360D_Buying_Shovels](1360D_Buying_Shovels) |
| 67 | +- [576A_Vasya and Petyas Game](576A_Vasya and Petyas Game) |
| 68 | +- [hr_summing-the-n-series](hr_summing-the-n-series) |
| 69 | +- [219158G_Summation from 1 to N](219158G_Summation from 1 to N) |
| 70 | +- [219432Z_Three Numbers](219432Z_Three Numbers) |
| 71 | +- [219158T_Sort Numbers](219158T_Sort Numbers) |
| 72 | +- [1499B_Binary Removals](1499B_Binary Removals) |
0 commit comments