ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1003. Parity

1003- Why just 2 seconds?
Posted by Ksenya 29 Dec 2003 22:08
I think 2 seconds is bad Time Limit. Also I don't know how many input
tests contains each test.
So I tried everything: like binary search and hash-function. But
always TLE.
Do you think 2 seconds is enough time?
Re: 1003- Why just 2 seconds?
Posted by buggzy 28 Mar 2004 22:05
There is at least O(n*n) algorithm for 1003.
Re: 1003- Why just 2 seconds?
Posted by Vladimir Yakovlev (USU) 29 Mar 2004 02:34
I solved it in O(n*n) time and get AC in 0.125 sec. So, 2 seconds is enough timelimit for this problem.
Re: 1003- Why just 2 seconds?
Posted by buggzy 29 Mar 2004 10:53
My algo is:

Each point have attibutes "parity" and "connectivity compontent number". When processing each segment, we check if it
- form a new connectivity component - O(1)
- extends existing connectivity components - O(1)
- connects existing CCs - O(N) for glue operation
- form a cycle in the existing CC - O(1)

This stage is O(n*n). It's quite enought for AC, but I'm still interested in more efficient algorithm :) Any ideas? :)