Hi,
I was trying to solve the sumtrian problem in the SPOJ problem set
( https://www.spoj.pl/problems/SUMTRIAN/ ) and this is the solution I
submitted: http://pastebin.ca/1035867
The result was, "Your solution from 2008-06-01 15:13:06 to problem
SUMTRIAN, written in Python,
has exceeded the allowed time limit."
I suspect that the first portion of my solution which looks at the
input, figures out the number of triangles and forms a list that
contains lists containing each row of the triangle, is wrong. I am not
too sure how to optimize it. I would appreciate help.
Thanks,
Shriphani Palakodety 2 2866
On Jun 1, 10:25*am, Shriphani <shripha...@gma il.comwrote:
Hi,
I was trying to solve the sumtrian problem in the SPOJ problem set
(https://www.spoj.pl/problems/SUMTRIAN/) and this is the solution I
submitted:http://pastebin.ca/1035867
The result was, "Your solution from 2008-06-01 15:13:06 to problem
SUMTRIAN, written in Python,
has exceeded the allowed time limit."
I suspect that the first portion of my solution which looks at the
input, figures out the number of triangles and forms a list that
contains lists containing each row of the triangle, is wrong. I am not
too sure how to optimize it. I would appreciate help.
Thanks,
Shriphani Palakodety
First, you have to write a correct algorithm. Notice that your code
doesn't correctly calculates the given sample input. Later, think
about optimization.
On Sun, Jun 1, 2008 at 7:25 AM, Shriphani <sh********@gma il.comwrote:
I was trying to solve the sumtrian problem in the SPOJ problem set
( https://www.spoj.pl/problems/SUMTRIAN/ ) and this is the solution I
submitted: http://pastebin.ca/1035867
The result was, "Your solution from 2008-06-01 15:13:06 to problem
SUMTRIAN, written in Python,
has exceeded the allowed time limit."
I suspect that the first portion of my solution which looks at the
input, figures out the number of triangles and forms a list that
contains lists containing each row of the triangle, is wrong. I am not
too sure how to optimize it. I would appreciate help.
Since you asked, I went and tried the problem myself and managed to
get a solution accepted with a bit of work. Here are my suggestions
with regard to your code:
* You absolutely need to use psyco for this problem. The accepted
solutions have memory usage of 36M+, which on SPOJ is a sure sign that
psyco was used, and they're already just a hair under the time limit.
* Instead of guessing "it's probably the input step", why don't you
profile your code so that you *know* where the bottlenecks are?
* Use xrange instead of range in for loops, and certainly don't use
while loops for iteration.
* max is quite slow for comparing only two things. It's faster to
compare the two things yourself. Since this line may be executed
millions of times, the difference could be quite significant. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter Salzman |
last post by:
Hi all,
Newish PHP programmer here. I wrote a form select class to help reduce code
clutter, but I don't think the effort was worth it. I was hoping to post my
attempt and get some ideas from more advanced users on how to implement a
select form using less lines of code.
First the select form class which implements a select widget. I'll post only
the relevent parts:
|
by: qwweeeit |
last post by:
Hi all,
when I was young I programmed in an interpreted language that allowed
to modify itself.
Also Python can (writing and running a module, in-line):
fNew =open("newModule.py",'w')
lNew=
fNew.writelines(lNew)
fNew.close()
|
by: gorda |
last post by:
Hello,
I am playing around with operator overloading and inheritence,
specifically overloading the + operator in the base class and its
derived class.
The structure is simple: the base class has two int memebers "dataA",
"dataB". The derived class has an additional int member "dataC". I am
simply trying to overload the + operator so that 'adding' two objects
will sum up the corresponding int members.
|
by: suri |
last post by:
Hello
I downloaded glibc and tried looking for the code that implements the
sine function
i couldnt find the file.
i went to the math directory and found math.h.. i guess that needs to be
included for the sine function. but which .c file implements the
sine/cosine and other trig fns
thanks
|
by: ErnieJ |
last post by:
I a have a .net application which displays the results of
a database query on a form in graphical format (i.e.
charts and maps). This application is launched from
another legacy Windows application with the query
determined by a number of parameters. This calling
application is not a .net app and does not support the
type of display I am able to achieve with vb.net.
Currently, anytime a user in the intitial application
wishes to see a...
| |
by: vlsidesign |
last post by:
I am a newbie and going through "The C programming language" by
Kernighan & Richie on my own time (I'm not a programmer but I want to
learn because it can save me time in my normal job, and it is kind of
fun). As I go through the book, I seek to do all the exercises because
they are very useful, and good, but it seems like I am just stumbling
through somewhat. In particular, I don't really know how to think about
"catching errors", or how...
|
by: Hendrik van Rooyen |
last post by:
Hi,
I would like to do the following as one atomic operation:
1) Append an item to a list
2) Set a Boolean indicator
It would be almost like getting and holding the GIL,
to prevent a thread swap out between the two operations.
- sort of the inverted function than for which the GIL
|
by: Gilles Ganault |
last post by:
Hello,
I'm no LAMP expert, and a friend of mine is running a site which is a
bit overloaded. Before upgrading, he'd like to make sure there's no
easy way to improve efficiency.
A couple of things:
- MySQL : as much as possible, he keeps query results in RAM, but
apparently, each is session-specific, which means that results can't
be shared with other users.
|
by: Shriphani |
last post by:
Hi,
I was trying to solve the sumtrian problem in the SPOJ problem set
( https://www.spoj.pl/problems/SUMTRIAN/ ) and this is the solution I
submitted: http://pastebin.ca/1035867
The result was, "Your solution from 2008-06-01 15:13:06 to problem
SUMTRIAN, written in Python,
has exceeded the allowed time limit."
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |