Kattis | Solutions to Open Kattis Problems | Learning library
kandi X-RAY | Kattis Summary
kandi X-RAY | Kattis Summary
Solutions to Open Kattis Problems
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 Kattis
Kattis Key Features
Kattis Examples and Code Snippets
Community Discussions
Trending Discussions on Kattis
QUESTION
I am new to programming and I want to learn as much as I can. I am working on problem Ptice on Kattis (Link to problem).
The problem in my programming journey now is that I create code I think works but when I pass it through Kattis it rejects my solutions halfway etc. Code below passes 3 out of 19 test cases. (on 4th case it hits a runtime error)
Would be superkind if someone could take a look why my logic isn't working / breaks. I would love to know what I do wrong so I can improve my programming. :)
...ANSWER
Answered 2021-May-09 at 19:26Your answer sequences for the three people are each 12 characters long.
If the input string is 12 characters or less, that's fine.
But if the input string is 13 or more characters long (it can be up to 100 characters, as stated in the competition text), the line
QUESTION
I have been tasked to solve a question concerning the creation of a triple-ended queue with efficient random access, as outlined in this: https://open.kattis.com/problems/teque. I created a program based around using 2 very large arrays, one containing the front half of all stored integers so far and the other the back half, with both being of the same size or the front half containing at most 1 more element than the back half after every insertion operation. This should allow all insertion and retrieval operations to be of O(1) time complexity, but the code just keeps exceeding the given time limit. Can anyone tell me what is wrong with my code? Here it is:
...ANSWER
Answered 2021-Feb-22 at 16:07You could try to minimze IO-Operations: Collect your programm output. Instead of writing System.out.println better create a new StringBuilder to collect everything. In the end write all at once.
QUESTION
So I'm doing some coding problem and in order to solve it I'm trying to create a list of all the possible answers and then I will see if that answer exists when asked to. However I am running into a problem with the function precedence of "o1", "o2", and "o3" - even though they represent expressions like *, div, +, - they all have the same precedence so when an option like 4 + 4 + 4 * 4 arises, the program answers with 48 instead of the correct answer, which is 24.
What I'm trying to ask is, are there any ways I can change the precedence of the functions "o1", "o2", and "o3", or make them reflect the operator's precedence?
The Code:
...ANSWER
Answered 2021-Feb-01 at 10:19You can change the precedence of infix functions with fixity declarations:
QUESTION
I'm trying to use parts of this Python script (taken from here) in a Rust program I'm writing. How can I construct a reqwest request with the same content?
...ANSWER
Answered 2020-Sep-14 at 15:00You are not using it, but with requests
you'd use a session object to handle cookie persistence. You already found the equivalent in reqwest
; a ClientBuilder
has a cookie store method which enables the same functionality. Use the builder configured with this to create both requests, and any cookies on one response then are passed on to the next request (following the normal rules for cookie domains, paths and flags).
Next, the requests.post()
method combines fields passed to files
and data
into a single multipart form request body. This does not post JSON data, don't use the RequestBuilder.json()
method here. Just add those fields to the multipart request as a text field, using the Form.text()
method.
Your login function is also not sending JSON; a dictionary passed to data
is handled as form fields instead.
So this should work:
QUESTION
Hope you can help me in this problem :
So the problem is Almost Perfect in Kattis.
https://open.kattis.com/problems/almostperfect
This is my code. the first test is passed but the second no it gives me am message (Time Limit Exceeded)
...ANSWER
Answered 2020-Dec-22 at 01:00The issue is that the code is simply too slow. Luckily, there's a simple optimization that can save you.
Note that if d
is a divisor of n
, then n / d
is also a divisor. Furthermore, if d
is lesser than sqrt(n)
, then n / d
is greater than sqrt(n)
(and vice-versa).
What this effectively means is we only need to check numbers up to sqrt(n)
instead of checking all the way to n
. And for every divisor d
we find, we also make sure to add n / d
to the divisor sum, except when d
is 1
or exactly sqrt(n)
.
Here's what that might look like in your code:
QUESTION
I recently tried to do the online programming challenge Texture Analysis on open.kattis.com; however, despite my answers for the sample cases being correct in my personal tests, I keep getting the second sample case wrong, the status of the submission says: "wrong answer". What am I doing wrong with my code?
Here is a link to the kattis problem: https://open.kattis.com/problems/textureanalysis
...ANSWER
Answered 2020-Dec-17 at 20:56Fixed commented example:
QUESTION
Im currently trying to implement a version of the sieve of eratosthenes for a Kattis problem, however, I am running into some memory constraints that my implementation wont pass.
Here is a link to the problem statement. In short the problem wants me to first return the amount of primes less or equal to n and then solve for a certain number of queries if a number i is a prime or not. There is a constraint of 50 MB memory usage as well as only using the standard libraries of python (no numpy etc). The memory constraint is where I am stuck.
Here is my code so far:
...ANSWER
Answered 2020-Jul-14 at 16:40I think you can try by using a list of booleans to mark whether its index is prime or not:
QUESTION
I'm trying hard to learn Haskell here Advent of Code would be a good place to test the language, but I'm dying here.
The problem:My solution (in my head):Find the two entries that sum to 2020; what do you get if you multiply them together?
So I'm thinking I'm super smart here:
If I sort it first, I can just move inwards from the two endpoints until I find the two that sum to 2020:
i.e.
Given: [1, 5000, 2, 4000, 3, 3000, 1009, 1010]
I'll sort it [1, 2, 3, 1009, 1010, 3000, 4000, 5000]
Then check 1
against the end until it's less than 2020
(reaching 1010
)
Then check 1010
against the start until it's more than 2020
(reaching the goal of 1009
)
I read this tutorial on input/output
and copied this code:
...ANSWER
Answered 2020-Dec-01 at 17:17I can't see where your code goes wrong, but I can suggest a few improvements to improve clarity (and speed).
First, you are using a single list argument where the content has a rather peculiar form: either it's [maximum, rest in ascending order ...]
or [minimum, rest in descending order ...]
. This makes the code a bit hard to read, and I would suggest to split the maximum/minimum into a separate argument.
Second, you should always start coding a function by writing the intended type. If you don't, and make a mistake, GHC will often infer a type which you did not expect. This will cause type errors much later on in the code, making them hard to fix, or produce error messages which are harder to understand.
Third, you are reversing the list too many times. Reversing is an O(n) operation, so we should try to avoid using it frequently. Fortunately, we can just reverse once in the whole program.
QUESTION
I am currently doing some tests at Kattis to practice my node.js skills but I'm stuck with this one.
Below is my code..
...ANSWER
Answered 2020-Nov-16 at 03:59By definition, you get ONE line at a time with this interface. The line
event in the readline interface just gives you one line at a time. So, it will never give you two lines you can compare.
If you just want to see compare successive lines in the file with whatever logic you want, you can keep the previous line in a higher scoped variable and compare the next line to that when the next line
event occurs.
QUESTION
I'm solving this problem on Kattis called Heart Rate.
Link to the problem: https://open.kattis.com/problems/heartrate
ISSUE: Getting an input with 2 different data types and manipulating them as such.
Here is my solution so far, but it only returns final answers in int data types when I think they're supposed to be floats.
...ANSWER
Answered 2020-Sep-19 at 05:26Here you are mapping int type to all the values of list i.e b and p. Apply different type casting to them. You can do something like this,
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Kattis
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