做了codility网站上一题:CountBoundedSlices

在写上一随笔之前,在Codility网站上还做了一个道题(非Demo题):CountBoundedSlices,得了60分(害臊呀)。今天又重新做了一下这个算法,性能提高了不少,但由于此题不是Demo题,不能重新在Codility网站测试了。

可以从http://codility.com/cert/view/certAWY5VP-D46CA7989XU4XEZT/details看到题目的详细信息。

这里把题目copy出来:

An integer K and a non-empty zero-indexed array A consisting of N integers are given.

A pair of integers (P, Q), such that 0 ≤ P ≤ Q < N, is called aslice of array A.

bounded_slice is a slice in which the difference between the maximum and minimum values in the slice is less than or equal to K. More precisely it is a slice, such that max(A[P], A[P + 1], ..., A[Q]) ? min(A[P], A[P + 1], ..., A[Q]) ≤ K.

The goal is to calculate the number of bounded_slices.

以下新做的算法及第一次做的算法贴在下面:

做了codility网站上一题:CountBoundedSlices
def solution(K, A):
    # http://codility.com/cert/view/certAWY5VP-D46CA7989XU4XEZT/details
    _ret_numer = 0
    _count = len(A)
    for _inx in range(_count):
        _max_int = None
        _min_int = None
        for _inx2 in range(_inx,_count):
            if _max_int is None:
                _max_int = A[_inx2]
            else:
                if _max_int < A[_inx2]:
                    _max_int = A[_inx2]
            if _min_int is None:
                _min_int = A[_inx2]
            else:
                if _min_int > A[_inx2]:
                    _min_int = A[_inx2]
                    
            if _max_int - _min_int <= K:
                _ret_numer += 1
            else:
                break
    return _ret_numer

def solution2(K, A):

    def sum_special(number, times):
        return sum(range(number, number-times, -1))
    _ret_numer = 0
    _current_inx = 0 # current index
    _loop_inx = _current_inx # loop index for array.
    _minvalue_inx = _current_inx # index of min value for a loop break.
    _maxvalue_inx = _current_inx # index of max value for a loop break.
    _count = len(A) # array length
    while _loop_inx < _count:
        
        # compare two values, get max
        if A[_maxvalue_inx] < A[_loop_inx]:
            _maxvalue_inx = _loop_inx
        # compare two values, get min 
        if A[_minvalue_inx] > A[_loop_inx]:
            _minvalue_inx = _loop_inx
        
        # break if meeting condition.
        if A[_maxvalue_inx] - A[_minvalue_inx] > K:
            _first_inx = None
            _second_inx = None
            if _minvalue_inx <= _maxvalue_inx:
                _first_inx, _second_inx = _minvalue_inx, _maxvalue_inx  
            else:
                _first_inx, _second_inx = _maxvalue_inx, _minvalue_inx
                
            _ret_numer += sum_special(_second_inx-_current_inx, _first_inx-_current_inx+1)
            
            _current_inx = _first_inx + 1 # move next to first_inx
            _loop_inx = _current_inx
            _minvalue_inx = _current_inx # index of min value for a loop break.
            _maxvalue_inx = _current_inx # index of max value for a loop break
        else:
            _loop_inx += 1 # increment one
    if _current_inx != _loop_inx:
        _ret_numer += sum_special(_loop_inx-_current_inx, _loop_inx-_current_inx)

    return _ret_numer
做了codility网站上一题:CountBoundedSlices

关于新做的算法,虽然性能提高了很多,但我还是不是很满意,因为_loop_inx在每次满足K条件计算后还要重新回溯到_current_inx位置,按理说应该通过记录更多数据达到不需要回退,试了几次发现复杂度陡升。

 

列了测试case:

做了codility网站上一题:CountBoundedSlices
def test(K, A):
    print K, len(A), A[:10]
    import time
    _start = time.time()
    _value = solution(K, A)
    _end    = time.time()
    print "solution result: time=%f, value=%d" % (_end-_start, _value)
    _start = time.time()
    _value2 = solution2(K, A)
    _end    = time.time()
    print "solution2 result: time=%f, value=%d" % (_end-_start, _value2)
    return _value == _value2
    
def sample_test():
    import random
    N = random.randint(1,100000)
    A = [random.randint(-1000000000,1000000000) for _ in xrange(N)]
    K = random.randint(0,1000000000)
    return test(K, A)
    
def simulate_test(times=100):
    _error_occur = False
    print "simulate start..."
    for _ in range(times):
        if not sample_test():
            _error_occur = True
            break
    if _error_occur:
        print "occur error, please check it"
    print "simulate complete"
做了codility网站上一题:CountBoundedSlices

以下是随机做100次,两次算法测试结果对比。可以看到两此算法得到time差距挺大的,如果codility网站测试,应该能够高于60分吧。

做了codility网站上一题:CountBoundedSlices
>>> simulate_test(times=100)
simulate start...
712518820 21893 [233628416, -652563058, 551353390, -217560133, -154138713, 563467537, 808230529, -205481433, 561911746, -750371596]
solution result: time=2.067000, value=46806
solution2 result: time=0.028000, value=46806
871940175 46368 [937986329, -952927755, -932362380, -469631039, -306238711, 696474641, -783179175, -931362077, -937403887, -681449512]
solution result: time=9.547000, value=118063
solution2 result: time=0.060000, value=118063
477409879 75579 [-995189110, 153461080, 383822333, -755867874, -499883883, -432680163, 96191219, 580653424, 423158838, -182965136]
solution result: time=25.332000, value=123214
solution2 result: time=0.104000, value=123214
488625751 1591 [558870329, 608903479, 550502154, 81531055, 707009330, 376372020, -276696701, -161031308, -8064320, 88712047]
solution result: time=0.013000, value=2571
solution2 result: time=0.002000, value=2571
436684262 20033 [-83885888, 463772906, 24144710, -480048118, 217531317, -104917140, 67141243, 714708231, -593590958, -980170193]
solution result: time=1.731000, value=31133
solution2 result: time=0.030000, value=31133
155090300 81187 [-482815444, 400503737, 33426826, 421085581, -175168617, -849832660, 780212059, 694032115, -636059844, -746589641]
solution result: time=29.778000, value=94954
solution2 result: time=0.124000, value=94954
465594288 40508 [521794630, -723650954, -690791173, -765608385, -393134645, 740067734, 516698048, -992683360, -335416969, -827405186]
solution result: time=7.330000, value=65321
solution2 result: time=0.055000, value=65321
907687848 11438 [895044686, 806244941, -690502444, 706872903, -15439789, -491691160, -33510875, -850504728, 627498209, 178781503]
solution result: time=0.580000, value=30599
solution2 result: time=0.014000, value=30599
917658188 1416 [-82302265, -328719536, 84686291, 226567716, -198056874, -651427652, -518158222, 459874316, -996196104, 762641325]
solution result: time=0.011000, value=3821
solution2 result: time=0.002000, value=3821
22150008 15811 [-359774811, -601356389, -349038488, -393355819, 200142427, -247051785, 79855294, 762147974, 349270442, -543063059]
solution result: time=1.124000, value=16154
solution2 result: time=0.026000, value=16154
806546890 39666 [225604285, 699280534, 574919735, -222005860, -756343609, 364653794, -642289525, -132214696, -531522216, 668841925]
solution result: time=7.352000, value=93516
solution2 result: time=0.053000, value=93516
446767256 61167 [-797312962, 859493626, -481645569, -885060421, 378198746, -630555365, -714358149, -224569996, 366913479, 572567757]
solution result: time=17.873000, value=96243
solution2 result: time=0.084000, value=96243
908894749 14304 [126236598, -325056547, -567716458, 756952836, 963930898, -761802348, 579888315, -191851495, -888831957, 223176046]
solution result: time=0.894000, value=37720
solution2 result: time=0.017000, value=37720
445662903 43594 [-77115444, -146497457, -201219950, 298322886, 699626045, -721141178, 620626818, -656768352, 779191843, -496056951]
solution result: time=9.026000, value=68633
solution2 result: time=0.064000, value=68633
896193106 87799 [225127782, -499401589, 576280745, -193205926, -378379146, 201195499, 240271554, 1990460, 524040734, 276918545]
solution result: time=37.246000, value=229708
solution2 result: time=0.106000, value=229708
898616436 3450 [-263848570, 466852557, 87733905, -345331987, 194432951, -122943788, 407961797, 253794919, 869433356, 175595518]
solution result: time=0.057000, value=9435
solution2 result: time=0.005000, value=9435
346182055 75038 [451820085, 404626026, -312042611, -316557991, 563084929, 371309936, -245776405, -127691048, -243875924, -494809654]
solution result: time=27.318000, value=106255
solution2 result: time=0.116000, value=106255
534249547 79539 [-891387059, 567285015, -664026466, -101133107, 510858959, -446038753, 566859262, -566626952, 365507295, 476351425]
solution result: time=29.328000, value=136652
solution2 result: time=0.108000, value=136652
504143400 31603 [972028042, 283415620, 607959186, -642899634, -686734313, 810373520, -695705028, -836014133, 168291764, 756721934]
solution result: time=4.457000, value=52865
solution2 result: time=0.044000, value=52865
384581802 77375 [124172689, -989437467, 213271375, 767367034, -635598230, 573627766, -17536139, 529795086, -403202636, 145615315]
solution result: time=27.306000, value=114084
solution2 result: time=0.112000, value=114084
818348046 9450 [867092810, -949286543, 710835399, -753470788, -461126327, -232093661, -971742891, 367646003, 269914630, -404115168]
solution result: time=0.406000, value=22305
solution2 result: time=0.012000, value=22305
173852970 60865 [-620839314, -542468951, -756181557, 561495967, 377686974, 577437042, -377448675, 886945237, 89270904, -610962060]
solution result: time=16.640000, value=72461
solution2 result: time=0.094000, value=72461
499297656 13388 [-658918296, 573321638, -881032247, 133944805, 107632459, 404755776, -349641260, 499223348, 616340316, 209652460]
solution result: time=0.816000, value=22225
solution2 result: time=0.019000, value=22225
405777536 4712 [991132018, -555754397, 815968493, 341471300, 349248457, -366471082, -502991469, -904956372, -410473995, 154448524]
solution result: time=0.104000, value=7171
solution2 result: time=0.007000, value=7171
645972146 48874 [207036460, 777964439, -869769768, 632827966, 492357468, -897393398, 144409238, 790113060, 527670908, -371291798]
solution result: time=10.739000, value=95091
solution2 result: time=0.064000, value=95091
808578966 98628 [634313108, -942656305, -643190985, -416688166, -983545086, 912481211, 163493211, 74856124, 711407211, -266978307]
solution result: time=43.970000, value=232592
solution2 result: time=0.121000, value=232592
355325933 76586 [662937721, -145146531, -398164748, 673949927, 308331782, 325586368, 23113293, 986270073, -816944356, -730811600]
solution result: time=26.614000, value=110348
solution2 result: time=0.114000, value=110348
761216523 93577 [-837332680, 771328205, -719811887, 791884900, -13712154, 283433368, 918649998, -655057859, -788172865, 455689690]
solution result: time=40.215000, value=207636
solution2 result: time=0.116000, value=207636
783573895 55337 [245850466, 177512999, 972610314, -537276190, 510326842, 943461244, 814218276, 775038330, 258371520, 381553002]
solution result: time=13.974000, value=127198
solution2 result: time=0.075000, value=127198
832961419 8705 [527690176, -142454319, -833394683, -23090434, 983716699, 949421655, 66180144, -63036290, 527943121, -167037530]
solution result: time=0.337000, value=21191
solution2 result: time=0.010000, value=21191
327033249 19748 [-422213445, -39921808, -587681736, 557326963, 708249854, 879393396, -408082146, 122508216, 651860574, 407392392]
solution result: time=1.821000, value=27434
solution2 result: time=0.029000, value=27434
585634165 70062 [425757413, 803383603, 161247508, -916557044, 595616918, 768806511, 237103747, 236377526, 12194813, -866313211]
solution result: time=23.379000, value=128177
solution2 result: time=0.098000, value=128177
563474140 94150 [-703235352, 35870455, 335996845, -595442340, 421192010, 648244845, 840504662, 302486161, 616434154, 400639679]
solution result: time=46.241000, value=168336
solution2 result: time=0.137000, value=168336
82122439 62173 [489853684, 563492429, 789310745, 472733566, -743742866, -399996889, 104565340, -687414875, -504564072, 737758124]
solution result: time=19.033000, value=67597
solution2 result: time=0.096000, value=67597
109729378 7307 [633154092, -57032773, 558099426, 4039547, -8965147, 149102167, -886781021, -30871882, 513890435, 652674395]
solution result: time=0.246000, value=8152
solution2 result: time=0.011000, value=8152
822838845 71765 [167311255, -474601042, -127570038, 385860789, 580427297, 463957253, 493028118, 254566413, 730987268, 872890654]
solution result: time=25.029000, value=172331
solution2 result: time=0.093000, value=172331
337754458 70673 [-462598416, 962379077, 170887493, -732389260, -684586478, -136816765, -170107401, 951118787, -834481478, 79708570]
solution result: time=24.828000, value=98952
solution2 result: time=0.113000, value=98952
153483349 82204 [-404359860, 376658497, -435203359, -726096623, 691866378, -685408854, -636659789, -756316181, -277011379, 564607832]
solution result: time=33.016000, value=95720
solution2 result: time=0.121000, value=95720
762844266 14208 [83806463, 132385188, 102461415, 968336292, 188351300, -428967587, -61086466, 201214276, -871725323, 86747156]
solution result: time=0.939000, value=31248
solution2 result: time=0.018000, value=31248
897408826 72107 [35258331, 315858099, -223428272, 533245539, -610000767, 662929147, 651812106, -909524082, 243889270, -901410127]
solution result: time=24.851000, value=190545
solution2 result: time=0.088000, value=190545
743698423 29084 [419956009, -553181412, 678881476, 409448464, 140269216, 740233466, 100032755, 439377696, -57410744, 152443857]
solution result: time=4.077000, value=64165
solution2 result: time=0.038000, value=64165
326295028 16648 [-798168361, 457779581, 908568446, -473471277, -221084137, 270011445, 736569831, -669910270, -176674556, 143606485]
solution result: time=1.293000, value=23065
solution2 result: time=0.025000, value=23065
436796613 80483 [727731281, -964077429, -917817354, 251377572, 859200396, -893534473, 289487629, -260281044, 837685396, 645482629]
solution result: time=30.663000, value=125454
solution2 result: time=0.113000, value=125454
93425419 15686 [562256985, 8031239, 586441668, 414353339, -645037703, -896644019, -764560767, -69489267, 390240171, -50267606]
solution result: time=1.144000, value=17191
solution2 result: time=0.024000, value=17191
674636947 21055 [550084099, -802488786, 609915011, -586347975, 526196054, -45129218, -733855544, 588035730, -4877919, 301136186]
solution result: time=2.057000, value=42626
solution2 result: time=0.030000, value=42626
834244298 56637 [342849532, 247426826, -408774084, -271290404, -844270714, -540658336, -924957693, 215269084, 68698466, 20471291]
solution result: time=15.251000, value=139012
solution2 result: time=0.076000, value=139012
36645599 16550 [921658471, 896437246, 505287263, 940913814, 691022604, -99749202, -314310287, -357254151, 422328865, -529373634]
solution result: time=1.286000, value=17159
solution2 result: time=0.026000, value=17159
627767452 7071 [-281962597, -343073587, -159309745, 483694105, 316782190, -720949731, 457460273, 738448118, -526524719, -925886631]
solution result: time=0.239000, value=13441
solution2 result: time=0.009000, value=13441
68618630 3501 [-629773285, 911119600, 279067796, -120085978, -788279714, -426147905, 709014529, -880362509, 163920372, 15117878]
solution result: time=0.073000, value=3754
solution2 result: time=0.009000, value=3754
438229966 85292 [564210654, -666516923, -821492950, -592644856, 21851293, 320812012, -371769959, 343554559, 239479135, -614081644]
solution result: time=34.535000, value=133209
solution2 result: time=0.140000, value=133209
60590254 44959 [802293468, -868006856, 717045106, 431953073, 232681248, -715567245, 161989388, 396482999, -360885655, -452082510]
solution result: time=9.660000, value=47734
solution2 result: time=0.076000, value=47734
367136486 49884 [-569156615, 913618240, -986936913, -940493527, 891341874, 693443649, 884924425, -856141178, 69173897, -919026395]
solution result: time=11.874000, value=72178
solution2 result: time=0.073000, value=72178
795304404 50530 [860065037, -235481529, -253357520, 92286946, 852038144, -81322281, 679320675, 84736643, -956217945, -987449813]
solution result: time=11.689000, value=116212
solution2 result: time=0.063000, value=116212
673542513 67615 [107244507, -451962005, -275019984, 135368790, 419474092, -742250690, 509036286, 111926590, -575869367, 749708273]
solution result: time=20.965000, value=136532
solution2 result: time=0.088000, value=136532
490294164 27654 [-541928294, -831893921, 382579626, -502987376, -210162522, 135048583, -116677670, -706590577, -478384698, 389698878]
solution result: time=3.483000, value=45851
solution2 result: time=0.040000, value=45851
401372908 53232 [-481058407, 298484033, 408625876, 972746889, -560687223, 974105405, -302224935, 631935384, 822204678, 476219625]
solution result: time=12.949000, value=80131
solution2 result: time=0.077000, value=80131
284735741 51881 [-345807207, -129261965, -352380669, 277914830, 291780286, 152315428, -184992070, 483307946, -446674379, 948115430]
solution result: time=12.332000, value=69129
solution2 result: time=0.077000, value=69129
432883620 62480 [469503850, -539457993, -842789654, -479584582, 908984876, -696502180, -840353152, 737456491, 757536480, -439888052]
solution result: time=17.879000, value=96916
solution2 result: time=0.087000, value=96916
164951982 89712 [779076511, -232870291, -861584260, -52539474, -673546529, -96336485, -96756249, 17707699, 98505217, -205525504]
solution result: time=37.262000, value=106016
solution2 result: time=0.137000, value=106016
513937832 84274 [-21513836, 376554427, -979373372, -962866844, -457971106, -385902011, 882198155, -525170096, -294492860, -352508630]
solution result: time=34.129000, value=142527
solution2 result: time=0.129000, value=142527
307963635 81777 [932178349, -527949859, -383956924, -753712604, 47089792, 690444342, 739063913, 224219373, 833574786, 971852315]
solution result: time=31.118000, value=111762
solution2 result: time=0.130000, value=111762
687779571 89275 [-99308024, 658491819, -158599952, -620935925, 287375981, 838267355, -267627981, -800768276, 625181447, 19883648]
solution result: time=37.183000, value=183069
solution2 result: time=0.117000, value=183069
567904914 57606 [-367813911, 30467460, 206847465, 549982402, 676142457, -453426240, -595993045, -226172178, 627387247, -98718053]
solution result: time=15.267000, value=103433
solution2 result: time=0.080000, value=103433
885498887 60348 [-236020933, 897973963, 414990262, -964761972, -511189467, 510334903, -224632643, -544273654, 985753509, -518391836]
solution result: time=16.971000, value=155805
solution2 result: time=0.076000, value=155805
306869931 74661 [52566962, -895074195, 85838469, 320261208, 514872304, -132903773, -857615502, 913599850, 577739522, 809302199]
solution result: time=26.181000, value=101925
solution2 result: time=0.109000, value=101925
706017933 46716 [-745426972, 848603628, 367270640, -898077673, -390350212, -100690446, 552440572, -679353996, 531789682, 823690023]
solution result: time=10.175000, value=97541
solution2 result: time=0.063000, value=97541
76368316 10886 [336720056, -401264322, 248795749, -675148155, -644742633, 879944699, 721898840, -867241645, 120674545, 157629997]
solution result: time=0.538000, value=11768
solution2 result: time=0.019000, value=11768
565613733 777 [-832403031, -176427770, -72783530, 144206612, 983277374, -243287817, -742891511, 769010333, -486452685, -965926265]
solution result: time=0.004000, value=1432
solution2 result: time=0.001000, value=1432
945499726 54204 [-639579678, -871127485, 13689092, -940307461, -998050768, -583136026, -250263835, -417168204, 127400342, -51666596]
solution result: time=13.853000, value=151685
solution2 result: time=0.064000, value=151685
366490687 64295 [205472643, 272383426, -486778183, -352718311, -155910350, -532183343, 516408425, 176985634, -359136259, 233442230]
solution result: time=19.379000, value=93073
solution2 result: time=0.108000, value=93073
607566355 54971 [-147401034, 100408291, -810848885, -283856910, 776597630, -14412059, -146081217, 663015950, -676590257, 401717944]
solution result: time=14.006000, value=102800
solution2 result: time=0.077000, value=102800
668912154 85391 [-711565158, 89781829, 412630639, 298803272, 870618256, 745432015, -98799704, 455429205, 601662861, 410070373]
solution result: time=33.683000, value=170674
solution2 result: time=0.119000, value=170674
325924899 55339 [-781696608, -983625149, 295500471, -598500843, -760562265, -575637913, 395290021, -667801107, -987009801, -952131754]
solution result: time=13.952000, value=76643
solution2 result: time=0.086000, value=76643
417778592 41235 [186341621, 793314762, -830791559, -293964235, -774798115, -923977018, 530958305, 743045627, -236090125, 851335697]
solution result: time=7.784000, value=62849
solution2 result: time=0.060000, value=62849
788836469 92294 [612571957, -529846396, 382792829, -347063239, -819868003, -955459129, -501243242, 108154002, 643317398, 914278946]
solution result: time=39.554000, value=211255
solution2 result: time=0.118000, value=211255
253002276 44420 [-897956408, 36184986, -824113972, 158108441, 889656728, 460087215, 136420294, -363306627, -880842097, 357731237]
solution result: time=8.962000, value=57079
solution2 result: time=0.063000, value=57079
914165630 54374 [-185503060, 908375424, 275649890, 382189070, 172667828, 856208089, 774502628, 119146496, 421495025, 203488123]
solution result: time=13.551000, value=146096
solution2 result: time=0.066000, value=146096
21737637 99176 [-120433256, 441495573, -37833683, -881435713, -355284422, -941415306, 466161969, -886533289, -301736056, 319122897]
solution result: time=46.575000, value=101350
solution2 result: time=0.193000, value=101350
59237201 60607 [-22604364, -547347368, 230976321, -930566630, -138375317, 89190005, 894076441, 861622359, 56062419, 718756072]
solution result: time=17.800000, value=64358
solution2 result: time=0.096000, value=64358
313820620 41634 [-830276433, -313449630, -752838812, -352533087, -70448071, 148813376, -109598972, -54334552, -265743989, 700494774]
solution result: time=8.196000, value=57140
solution2 result: time=0.059000, value=57140
268899831 17360 [-769862500, 828578431, 729980420, 722194236, 905125229, -880073067, 740880445, -830060822, -701026507, -189098200]
solution result: time=1.367000, value=22747
solution2 result: time=0.026000, value=22747
873844778 86118 [-168038690, 787818538, -955058250, -589350044, 713046079, -135724740, 526103169, -968453999, 146522228, -574307525]
solution result: time=34.445000, value=219273
solution2 result: time=0.104000, value=219273
247456977 37455 [398946317, 844767076, -419690071, -293894754, 454569331, -841343340, -71545219, -475497116, -218330377, 788309070]
solution result: time=6.394000, value=47944
solution2 result: time=0.057000, value=47944
366276656 11076 [-639657470, -663479305, -23412656, 389127348, -35261073, 822337416, -839869960, -32586410, 166151404, -202344527]
solution result: time=0.540000, value=16036
solution2 result: time=0.015000, value=16036
98344334 59608 [-153718922, 907077871, 805579415, -986285156, 202735870, 36143819, -679126295, 500299409, -456585661, -239291274]
solution result: time=16.369000, value=65639
solution2 result: time=0.093000, value=65639
454065229 14042 [45654615, -767223760, -843575437, 858849644, -814935201, -698315792, 824921855, -27028995, 57622423, -773166959]
solution result: time=0.908000, value=22505
solution2 result: time=0.019000, value=22505
144643656 21910 [-916069030, 52621660, 913991678, -204315752, 927638507, 123676464, -131477571, 939546603, 103398246, 91692230]
solution result: time=2.199000, value=25363
solution2 result: time=0.033000, value=25363
302772568 63965 [-865830511, -705765644, -262481382, -937003277, 812537996, -577131660, 167678520, -825193487, -532105016, -282891760]
solution result: time=19.046000, value=86465
solution2 result: time=0.093000, value=86465
485348428 31194 [725778102, 126558201, -943218277, -916452272, -794398562, 313250590, -468465532, 977822564, -978348406, 207242665]
solution result: time=4.440000, value=50998
solution2 result: time=0.042000, value=50998
69990594 33258 [-674867551, 96790805, 701545146, 507761249, 729645449, 417771596, -689191016, 274669548, -464755611, -863320975]
solution result: time=5.149000, value=35682
solution2 result: time=0.057000, value=35682
647538910 67275 [234328942, 165831107, 623832269, -579656554, -332041479, -54077014, 913975093, 764193587, -977224481, 291126481]
solution result: time=20.987000, value=132667
solution2 result: time=0.089000, value=132667
245237871 11449 [-872455246, 446700095, -129257411, 674586820, 789426999, 254554164, 85750590, 346556033, -276483472, -604041637]
solution result: time=0.585000, value=14649
solution2 result: time=0.017000, value=14649
250062830 80110 [567355179, -497004383, 666849254, 391953266, -643318683, -792153748, 873456179, 620818838, -699988970, 438383904]
solution result: time=30.561000, value=103350
solution2 result: time=0.128000, value=103350
981053388 96594 [916365057, 509755683, -298793914, 288075801, -579458677, 919047309, 177099894, -308469811, -793778189, -508042013]
solution result: time=44.342000, value=281470
solution2 result: time=0.119000, value=281470
936441261 87269 [-638756520, -983955050, -104831404, 7016873, -39868300, 794179610, 294311022, 218113648, 685723949, 437935217]
solution result: time=36.514000, value=242361
solution2 result: time=0.108000, value=242361
330028795 83465 [-125060762, 998877847, -975099323, -738518915, 68696423, 129443535, 128254804, 268819007, 908132685, -172527093]
solution result: time=33.019000, value=116644
solution2 result: time=0.123000, value=116644
48001717 53765 [457979641, 831973625, 394583952, 172906081, -596707313, 371812920, 140952647, 663295630, 696419827, -592665770]
solution result: time=13.259000, value=56323
solution2 result: time=0.091000, value=56323
563035850 83791 [490881185, -954368711, -161419749, -100160681, 71824406, 76572626, 675867896, -786468534, 3387857, -761023083]
solution result: time=33.030000, value=149626
solution2 result: time=0.116000, value=149626
377811495 85955 [-592637058, -236610635, 812214587, -365915745, 570588899, -543774880, -595380576, -13139683, 345144807, 358538207]
solution result: time=34.337000, value=125621
solution2 result: time=0.129000, value=125621
872204043 8801 [-195059373, 198246517, -85838306, -551894734, 381031985, -197986394, -575769771, 710559136, 417415353, -563478458]
solution result: time=0.360000, value=22284
solution2 result: time=0.010000, value=22284
simulate complete
>>>
做了codility网站上一题:CountBoundedSlices

做了codility网站上一题:CountBoundedSlices

上一篇:写给 Node.js 学徒的 7 个建议(转)


下一篇:.NET下 JSON 的一些常用操作