SPOJ | Some selected solutions
kandi X-RAY | SPOJ Summary
kandi X-RAY | SPOJ Summary
To see problem, put Make sure it’s all caps, and don’t include the .java extension. Some files may actually have nothing of interest (i.e. it’s just a template file). This just means I forgot to implement the problem…. to see what problems are actually solved. Some may not be included (that probably means I implemented in C++, or I can’t locate the file).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- not convex hull
- Calculates the number of nodes in the network
- Calculates the convex hull .
- returns the number of matches
- converts a char array to a string
- Command line entry point .
- Calculates the root of a string .
- Returns the best state for the given points .
- Find the number of words in the matrix .
- Assigns splits to the number of splits .
SPOJ Key Features
SPOJ Examples and Code Snippets
Community Discussions
Trending Discussions on SPOJ
QUESTION
I am trying to solve the SPOJ problem DIVFACT where we need to find the factorial of a number. Though I used the correct formulae and at the same time I also checked the special case of 0 and 1,still I am getting wrong answer and it's really difficult for me to figure out what's wrong with my code. Can someone please help me figure out the problem? For reference I am providing the link to the problem:- Link of the problem
...ANSWER
Answered 2021-Jun-10 at 21:59The problem states that the answer should be in MOD 10^9+7
but you have mistakenly defined MOD
as 10^8+7
.
QUESTION
Using pandas/python, I want to calculate the longest increasing subsequence of tuples for each DTE
group, but efficiently with 13M rows. Right now, using apply/iteration, takes about 10 hours.
Here's roughly my problem:
DTE Strike Bid Ask 1 100 10 11 1 200 16 17 1 300 17 18 1 400 11 12 1 500 12 13 1 600 13 14 2 100 10 30 2 200 15 20 2 300 16 21 ...ANSWER
Answered 2021-May-27 at 13:27What is the complexity of your algorithm of finding the longest increasing subsequence?
This article provides an algorithm with the complexity of O(n log n).
Upd: doesn't work.
You don't even need to modify the code, because in python comparison works for tuples: assert (1, 2) < (3, 4)
QUESTION
I am solving task on spoj platform - count number of digits in factorial. I found Kamenetsky Formula and implemented it:
...ANSWER
Answered 2021-May-19 at 07:00I think the time limit is exceeding because of the slow I/O. This is mainly because of System.out.println's underlying PrintStream. Find more details in this post why-is-system-out-println-so-slow. You can refer to the below Fast I/O template which will help solve this problem.
Reference - Fast I/O in java
QUESTION
I tried a problem from SPOJ called The next palindrome. The problem statement is given as
A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.
Here is my code
...ANSWER
Answered 2021-May-16 at 06:21The error is caused because your input "n" makes both arguments same in the range function in this line "for j in range(int(n) + 1, 1000000 + 1)". It looks like this range(1000001, 1000001) which return nothing. Use input of "n" smaller than 1000000. It will work.
It return empty list when I use this code.
QUESTION
I'm trying to submit this code on spoj https://www.spoj.com/problems/PALIN which is asking to find next smallest palindrome of a given number n, but as this code works, it is slow therefor it exceeds the time limit (2-9 seconds). is there another way to solve this exercise in a faster way?
The first line contains integer t, the number of test cases. Integers K are given in the next t lines.
code:
...ANSWER
Answered 2021-Mar-08 at 07:29The most obvious thing to do is to stop copying and reversing the string. Instead, compare the first character to the last character, then the second to the second-to-last, and so on.
Also, why are you using strings at all? Strings are complex and expensive. The operations you are performing can be done entirely on numbers.
Lastly, consider numbers like "473X". None of those can ever be palindromes. You don't have to test all ten of them. If you're going to look at four-digit numbers starting with "47", there's only one that's a palindrome -- so why are you checking all hundred of them?
Before writing code to solve a problem like this, think through the algorithm you're going to use and make sure you don't have any obvious wasted effort.
QUESTION
The following code gets TLE (time limit exceeded) if the standard output is not flushed.
...ANSWER
Answered 2021-Mar-01 at 16:10The problem specification tells you what to do:
Attention: the program should clear the output buffer after printing each line.
It can be done using fflush(stdout) command or by setting the proper type of buffering at the beginning of the execution - setlinebuf(stdout).
The problem title indicates why:
(Interactive)
The judging software is operating the program interactively. After giving the program an input, it waits for output before providing more input. When your program does not flush the buffered output, the judging software keeps waiting until its time limit is exceeded.
Commonly, output streams to terminals are line-buffered, in which case printing a new-line character causes them to be flushed. However, this judging software is likely using a pipe that is fully buffered, so output will not be flushed until the buffer is full or you explicitly request a flush (or, at the start of the program, you change the buffering mode to unbuffered or line-buffered).
When you flush the output, the judging software will see it, and then it will continue and provide more input.
As an alternative to flushing the output after each printf
, you can set the stream to line buffering mode by executing setvbuf(stdout, NULL, _IOLBF, 0);
at the beginning of the program (before doing any other operation on the stream).
QUESTION
I have done an exercise on SPOJ to practice advanced algorithms.
The Problem Statement is as follows:
Harish went to a supermarket to buy exactly ‘k’ kilograms apples for his ‘n’ friends. The supermarket was really weird. The pricing of items was very different. He went to the Apples section and enquired about the prices. The salesman gave him a card in which he found that the prices of apples were not per kg. The apples were packed into covers, each containing ‘x’ kg of apples, x > 0 and ‘x’ is an integer. An ‘x’ kg packet would be valued at ‘y’ rupees. So, the placard contained a table with an entry ‘y’ denoting the price of an ‘x’ kg packet. If ‘y’ is -1 it means that the corresponding packet is not available. Now as apples are available only in packets, he decides to buy at most ‘n’ packets for his ‘n’ friends i.e he will not buy more than n packets of apples. Harish likes his friends a lot and so he does not want to disappoint his friends. So now, he will tell you how many friends he has and you have to tell him the minimum amount of money he has to spend for his friends.
This is the code I used to solve the problem:
...ANSWER
Answered 2020-Dec-16 at 15:23Since this is a SPOJ question, and you're not given the test data, what you should do is to randomize the tests until you get a failure. That way, you may be able to get a sample case that fails. This is called fuzzing, and is a technique that can be used in your question.
The following will work for the cases that cause segmentation faults, and in some cases, to verify if a given output matches the expected output. In other words, instead of trying to figure out the test data, let the computer generate the tests for you.
The way you do this is to look at the constraints that the question gives you, and generate random data that fits the constraints. Since they are all integers, you can do this by using the header, and using a
uniform_int_distribution
.
Here is a sample of fuzzing the data using the following constraints for N
, K
, and the data for prices:
QUESTION
I know this type of question has been asked before but I can't find a solution to this, I know its a invalid memory reference error or array out of bounds, but I can't seem to find the cause of the error in my code. I just tried this problem on SPOJ, it was the 'Transform the Expression' https://www.spoj.com/problems/ONP/ my all test cases are right!
here is my code:
...ANSWER
Answered 2020-Nov-13 at 07:08#include
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin>>t;
while(t--){
string str;
std::stack f ;
cin>>str;
string ans="";
for(int i=0;i0){ // Change 2
ans+=f.top();
f.pop();
}
break;
default:
ans+=str[i];
break;
}
}
if(f.size()>0){
while(f.size()>0){
ans+=f.top();
f.pop();
}
}
cout<<
QUESTION
Quick question. This is the code that I wrote to finish a problem in SPOJ. The output is correct but it gives me wrong answer. Whats wrong with my code? This is the link to the question: https://www.spoj.com/problems/SUMUP/
...ANSWER
Answered 2020-Oct-07 at 10:30In the lines:
QUESTION
I am trying to make a GUI(using tkinter) for checking the code using test cases. Just like you see in Competitive Programming Websites like Hackerrank , SPOJ , CodeForces etc.
Now I have somehow managed to print in the terminal for what test cases the code failed and for what the code passed.
But the catch is , I want to do the same in tkinter messageboxes.
My code runs in loop , so it checks each and every test cases and then prints out the result immediately rather than storing all the result in a list and checking them in the end.
So I want my Messagebox to also do the same i.e update everytime a test cases has been evaluated and show whether the test case was passed or not?
Is it possible to implement?
...ANSWER
Answered 2020-Oct-03 at 07:48If you mean the messagebox module that comes with tkinter, then no. But you can easily make your own message boxes with the Toplevel
widget, and those can do anything you want.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SPOJ
You can use SPOJ like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the SPOJ component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
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