Submission #3014988


Source Code Expand

class BIT
    def initialize(n)
        @n = n+1
        @dat = Array.new(@n+1, 0)
    end

    def sum(i)
        s = 0
        while i >= 0 do
            s += @dat[i]
            i = (i & (i + 1)) - 1
        end
        s
    end

    def add(i, x)
        while i <= @n do
            @dat[i] += x
            i |= i + 1
        end
    end
end

def inversion(arr)
    bit = BIT.new(arr.length)
    ret = 0
    arr.length.times do |i|
        ret += i - bit.sum(arr[i])
        bit.add(arr[i], 1)
    end
    ret
end

N = gets.to_i
abc = N.times.map{gets.split.map(&:to_i)}
abc.sort_by!{|arr| arr[0].to_f/arr[1]}
half = (N*(N-1)/2+1)/2

ub = 10.0**9
lb = -10.0**9
while ub-lb > 0.1**10
    mid = (ub+lb)/2
    order = N.times.sort_by{|i| (-abc[i][0]*mid+abc[i][2]).to_f/abc[i][1]}
    inv = inversion(order)
    if inv < half
        lb = mid
    else
        ub = mid
    end
end
x = ub

abc.sort_by!{|arr| arr[1].to_f/arr[0]}

ub = 10.0**9
lb = -10.0**9
while ub-lb > 0.1**10
    mid = (ub+lb)/2
    order = N.times.sort_by{|i| (-abc[i][1]*mid+abc[i][2]).to_f/abc[i][0]}
    inv = inversion(order)
    if inv < half
        lb = mid
    else
        ub = mid
    end
end
y = ub

puts [x, y].join(' ')

Submission Info

Submission Time
Task E - CARtesian Coodinate
User betrue12
Language Ruby (2.3.3)
Score 0
Code Size 1275 Byte
Status TLE
Exec Time 5262 ms
Memory 43744 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 3
AC × 6
TLE × 29
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt TLE 5260 ms 24544 KB
02.txt TLE 5261 ms 27404 KB
03.txt TLE 5262 ms 37348 KB
04.txt TLE 5260 ms 24024 KB
05.txt TLE 5257 ms 32152 KB
06.txt TLE 5261 ms 31120 KB
07.txt TLE 5261 ms 33604 KB
08.txt TLE 5261 ms 37084 KB
09.txt TLE 5260 ms 25344 KB
10.txt TLE 5262 ms 36844 KB
11.txt TLE 5260 ms 24920 KB
12.txt TLE 5260 ms 23648 KB
13.txt TLE 5262 ms 33692 KB
14.txt TLE 5261 ms 23572 KB
15.txt TLE 5260 ms 33132 KB
16.txt TLE 5260 ms 25056 KB
17.txt TLE 5261 ms 23660 KB
18.txt TLE 5261 ms 39328 KB
19.txt TLE 5260 ms 28112 KB
20.txt TLE 5261 ms 28868 KB
21.txt TLE 5262 ms 41828 KB
22.txt TLE 5261 ms 43744 KB
23.txt TLE 5260 ms 30720 KB
24.txt TLE 5261 ms 23488 KB
25.txt TLE 5261 ms 27096 KB
26.txt TLE 5260 ms 24900 KB
27.txt TLE 5259 ms 2044 KB
28.txt TLE 5259 ms 2044 KB
29.txt TLE 5259 ms 2044 KB
30.txt AC 8 ms 1788 KB
31.txt AC 8 ms 1788 KB
32.txt AC 8 ms 1788 KB
s1.txt AC 8 ms 1788 KB
s2.txt AC 8 ms 1788 KB
s3.txt AC 9 ms 1916 KB