CodeForces | designed problems that I solved in CodeForces contests | Learning library
kandi X-RAY | CodeForces Summary
kandi X-RAY | CodeForces Summary
Some nice-designed problems that I solved in CodeForces contests.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of CodeForces
CodeForces Key Features
CodeForces Examples and Code Snippets
Community Discussions
Trending Discussions on CodeForces
QUESTION
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time? This is the problem.
https://codeforces.com/contest/782/problem/A This is the problem statement.
...ANSWER
Answered 2021-Jun-14 at 17:10There are 2*n
numbers to read and process, but you processed only n
numbers. Process 2*n
numbers to fix.
QUESTION
What sites help me to increase my hacking skills, I'm a newbie, for coding there are hackerrank, hackerearth, codeforces, codechef etc, like those what are there to learn hacking?
...ANSWER
Answered 2021-Jun-11 at 09:01I would say CTF challenges are a good way to learn. https://tryhackme.com/ is a good place to start. Most of the rooms are aimed at beginners and it will give you a good understanding, of some of the programs you will use like nmap, burpsuite and wireshark. https://www.hackthebox.eu/ is a good place, when you are a bit more experienced.
I am also gonna share some GitHub links, you might find interesting:
QUESTION
While solving a codeforces problem, I had to make a vector of size=1. Also, I needed to iterate back from the second last element of the vector, so I used the following technique to use for loop.
...ANSWER
Answered 2021-Jun-05 at 08:18Here, you trying to access vec[-1]
, which leads to out of range subscript.
Try to run this and look for output:
QUESTION
The intentions is to store some pointers in a std::set, but order them by their corresponding value, not the value of pointer itself. and here is the code:
...ANSWER
Answered 2021-Jun-02 at 16:45As the error says:
QUESTION
The topic link:https://codeforces.com/contest/109/problem/D
For the question, I'm time limit exceeded on test41
I guess that the data structure used is not appropriate, but I have thought about it for a long time and I don't know where to adopt a good data structure, please give me some advice.
algorithm ideas:
This approach is somewhat similar to selection sort. First, find a lucky number, then swap the position with the first number, then start from the second, find the smallest number, and then swap it with the lucky number, so that the smallest number starting from the second is placed at the first position, the lucky number is now in another position, and its position is recorded. Then swap the lucky number with the second number, and then repeat the above process. Special attention should be paid to the fact that we need to record the position of the lucky number we selected after sorting because the process before and after the position is slightly different and needs to be compared(This is explained in the code comments).
...ANSWER
Answered 2021-May-29 at 05:54The nested loop used to find MINID
makes the runtime quadratic in n:
QUESTION
The topic link: https://codeforces.com/problemset/problem/600/D
For the question, I'm wrong answer on test28, which could look like this:
correct answer:119256.95877838134765625000
my answer: 120502.639190673828125
I guess it is caused by calculation accuracy, but I don't have evidence. Maybe algorithm itself is faulty, please point it out.
Algorithm ideas:
For any given two circles, in order to simplify the calculation, we can translate the origin of the coordinates to the center of one of the circles, and then rotate the other circle to the x-axis by rotating. For calculating the intersection area of the circles, before and after are equivalent, and finally a purple circle and a red circle are formed. In fact, the final intersection area is equal to the sum of the areas of the two sectors minus the area of the diamond in the middle(the figure below, Horizontal axis x, vertical axis y). However, before that, we must first calculate the intersection point of the two circles.
The coordinates of the center of the first circle at the beginning: .
The coordinates of the center of the second circle at the beginning: .
The coordinates of the center of the first circle after a series of transformations: .
The coordinates of the center of the second circle after a series of transformations: ,
.
The equations of two circles are combined:
are the radius of the first and second circles respectively,so:
we can use the sector area formula : ,
, .
In this place, there will be problems with the positive and negative values of the radian(the two figures below), but it can be proved that they can be absorbed in the final result.
The final result is the sum of the areas of the two arcs minus the area of the middle diamond.
mycode:
...ANSWER
Answered 2021-May-27 at 06:10Don't use too many intermediate floating variables to get to the final answer. Small inaccuracies when add up lead to huge inaccuracy which you can clearly see in the expected and real output in your question. What you can do is to minimize these intermediate floating variables. For example
QUESTION
This is the link to this algorithm topic: https://codeforces.com/problemset/problem/615/D
my code time limit exceeded on test40, I thought for a long time but no good way, is there a good optimization method, may be ?
mycode:
...ANSWER
Answered 2021-May-22 at 12:49An other formula for the product of the divisors of N
is N ** (D/ 2)
, where D is the number of divisors and may be found from your map count
by taking the product of entry->second + 1
for every entry.
This does raise the question of what to do when D
is odd, which it would be if N
is a perfect square. In that case it is easy to compute sqrt(N)
(the exponents would all be even, so you can halve them all and take the product of the primes to half of their original exponents), and then raise sqrt(N)
to the power of D
. Essentially this changes N ** (D / 2)
into (N ** (1 / 2)) ** D
.
For example if N = 2 * 3 * 2 = 12
(one of the examples), then D
will be (2 + 1) * (1 + 1) = 6
and the product of divisors will be 12 ** (6 / 2) = 1728
.
Computing N
(or its square root) should done modulo mod
. Computing D
should be done modulo mod - 1
(the totient of mod
, mod
is a prime so its totient is just one less). mod - 1
is even, so we could not have computed the modular multiplicative inverse of 2 to "divide" D
by 2 that way. When N
is a square then AFAIK we're really stuck with computing its square root (that's not so bad, but multiplying by a half would have been easier).
QUESTION
I wrote a program for this problem. But it's showing different result in compiler and online judge.
When I input
...ANSWER
Answered 2021-May-15 at 04:57arra[i-1]
with i=0
is out-of-range and using such out-of-range element invokes undefined behavior.
Fix the loop for(i=n-1; i>=0; i--){
not to cause out-of-range access.
It may be better to use the standard qsort()
function for sorting than writing your own sorting algorithm.
QUESTION
I am using an API call to get some data. And I am calling that method in the init state so that it fetches the data as soon as the widget is added into the tree.
I am using that data in a Text widget, but it shows an error that "The method '[]' was called on null".
Here is the code for your reference:
...ANSWER
Answered 2021-May-03 at 02:44not the best and efficient solution but if you just want to show some data like username or email you can do it like this:
QUESTION
I saw a program in codeforces where it says, "Now Petya wants to compare those two strings lexicographically."
I didn't understand it. What does lexicographically mean?
...ANSWER
Answered 2021-Apr-30 at 14:22I'm not sure if this is more of a stackoverflow question or not, but I could be wrong. . . Based on your question and its usage I would prefer a breakdown of the word "lexicographically".
The root appears to be "lexicon", which we can see by this reference the definition is:
"a book containing an alphabetical arrangement of the words in a language and their definitions"
OR
"the vocabulary of a language, an individual speaker or group of speakers, or a subject"
OR (more related to computers)
"the total stock of morphemes in a language"
In this pdf the author says,
"The lexicon of a computer language is its total inventory of words and symbols."
Next, we want to look at the word "lexicography", this is the next layer to our process of building the word up from the root. First, let us look at the general definition. According to Merriam-Webster in this reference we see that lexicography is defined as such:
"the editing or making of a dictionary"
OR
"the principles and practices of dictionary making"
In this reference regarding Computation Lexicography the author states, "Computational Lexicology is the use of computers in the study of the lexicon. It has been more narrowly described by others (Amsler, 1980) as the use of computers in the study of machine-readable dictionaries."
The next-to-last step is to look at the word without its description of the action occurring, that would be "lexicographic", as in lexicographic order. In this reference we see, "In mathematics, the lexicographic or lexicographical order (also known as lexical order, or dictionary order) is a generalization of the alphabetical order of the dictionaries to sequences of ordered symbols or, more generally, of elements of a totally ordered set."
Lastly, we can see that the word is an adverb since in the example sentence it is describing the action that is occurring - also we see the use of "-ly" at the end of the word.
It would appear that Petya would like to compare the two strings alphabetically and with regard to their potentially symbolic, or definitive, meaning within the dictionary of lexicons from which they exist.
A fun little analysis project that took me on.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CodeForces
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page