Results of the New Year Habr-programming competition, analysis and discussion

    Honestly, I did not expect such a number of solutions: 265 solutions were sent in 24 hours, of which

    183 were left after the removal of the resubmission. Out of 183 solutions, 11 exceeded the allowed solution size, in 19 cases it was not possible to compile (more about these errors below). Then 47 gave incorrect answers on simple tests (1..1000000), 8 did not have time to calculate the answer per minute (the sample solution from the problem statement for 1 million worked 5 minutes 36 seconds).

    On complex tests - 5 solutions gave the wrong answer, and 12 - did not fit in one minute. 86 - successfully passed all the tests.

    If anyone lost, here is a topic about starting a competition with the conditions of the problem .


    About tests and testing

    Everything was tested with commonplace scripts, the most time-consuming operation is to save solutions from the mail with your hands (and repeated file names ... 42 pieces of main.cpp ....). This is probably one of those cases when writing a web application for making decisions is faster than scooping up tons of mail. Testing results - added up in MySQL, from where the results table was built.

    Simple tests:
    function do_test($input, $expected_output)
    {
    	global $task_id;
    	exec("echo '$input' | Solutions2/bin/$task_id &2>1", $output);
    	if(count($output)==0)return false;
    	return(strcmp($output[0], $expected_output)==0);
    }
    $result = do_test("10","17") && do_test("1","0") && do_test("1000","76127") && do_test("100000","454396537") && do_test("1000000","37550402023");
    


    Complex tests:
    Averaged runtime was estimated (i.e. runtime for 4 different input values ​​divided by 4). The 3 fastest solutions were tested with 100-fold repetition - to get a more accurate runtime (unlike a single run within 1%).
    $start_time = microtime (true);
    //for($i=0;$i<100;$i++)
    	$result = do_test("980000000","23783220704190493") && do_test("1051174931","27269025983026043") && do_test("891728152","19783994900202129") && do_test("761987760","14559966509022149");
    $end_time = microtime (true);
    


    Result table

    Colleagues, click on invites:
    No.HabranameDo I need an invite?ResultSystem id
    1@shadewareNot anymore0.035053772330284 sec.48
    2@mikhaelkhNot anymore0.039169362783432 sec41
    3@IcemoreNot anymore0.068273649811745 sec129
    4@ripatti
    Not anymore0.11206769943237 sec.8
    5@kbxxi
    Not anymore0.15401327610016 sec.156
    6@monoidNot anymore0.22840601205826 sec.69
    7@ Zver19920.23262423276901 sec.133
    8@Mrrl
    0.37099504470825 sec.178
    9@StakerYes0.66007524728775 sec.171
    10@SyDr
    Yes0.93328875303268 sec.78
    eleven@vbarinov
    Yes3.2648342847824 sec108
    12@vanla
    Yes3.3831697702408 sec.19
    thirteen@MaSaK
    Yes3.4151287674904 sec.20
    14@ dark1ight
    3.5476635098457 sec.36
    fifteen@udalovYes3.8905065059662 sec.116
    16@bklim
    4.3489827513695 sec.149
    17@cfighter
    4.4272682070732 sec.eleven
    18@VladVR
    4.7588297724724 sec.89
    19@borozdinKirill
    4.775633752346 sec.109
    20@ZhekSooN
    4.8941134810448 sec.122
    21@madkite4.9126330018044 sec.114
    22@akazakow
    5.208831012249 sec.45
    23@mingrief5.2523249983788 sec.179
    24@pasky
    5.9874464869499 sec.5
    25@ ewnd9
    6.024626493454 sec183
    26@gnhdnb
    6.0333037376404 sec.158
    27@through_horizon6.2488570213318 sec.21
    28@ kosmos89
    6.2885909676552 sec.126
    29th@Nickel6.36874127388 sec.42
    thirty@infsega
    6.4502172470093 sec.33
    31@shuternay6.4606020450592 sec.6
    32@smyatkin_maxim6.5664409995079 sec123
    33@azhi6.9450110197067 sec.145
    34@Valmount
    7.2953402400017 sec.147
    35@ Alick09
    7.4088390469551 sec.125
    36@alexeibs7.6391640305519 sec.177
    37@DoctorStein
    7.6435596942902 sec.128
    38@Kenny_HORROR
    7.8451775312424 sec.77
    39@ Ratio2
    7.8529967665672 sec.53
    40@No username specified8.0461687445641 sec.80
    41@mobi
    8.129643201828 sec.64
    42@Lonsdaleite
    8.2785065174103 sec.92
    43@tiirz8.3757525086403 sec.134
    44@Goryn8.3831282258034 sec.167
    45@Leronxp
    8.5381667613983 sec.93
    46@singstioYes8.5835777521133 sec.165
    47@ CTAKAH4uK
    8.7342492341995 sec.173
    48@XMypuK
    8.8221767544746 sec.95
    49@Edelweiss
    8.8413127660751 sec.61
    fifty@Jovfer
    9.6698319911957 seconds174
    51@crimaniak
    10.019654750824 sec.113
    52@luckman
    10.166677713394 seconds46
    53@ladilova
    10.607916533947 sec.59
    54@Gromilo
    11.256841778755 sec.86
    55@FreeCoder
    11.380919516087 sec.44
    56@awa
    11.482711791992 sec.102
    57@sprosin
    11.626729488373 sec.76
    58@BelerafonL
    11.740502238274 sec.fifteen
    59@polar_winter
    11.798308491707 seconds47
    60@luckychess
    11.956114530563 sec.143
    61@darinflar11.991075217724 sec.105
    62@kreep
    12.082272768021 sec.170
    63@iqmaker12.346569001675 sec.34
    64@ dima1122112212.357870519161 sec.54
    65@ kos6612.412921786308 sec.68
    66@alex_r
    12.501110970974 sec.31
    67@dannk12.711302280426 sec.138
    68@andreybotanic
    12.847037494183 sec.40
    69@realsugar14.033301234245 sec.10
    70@kromych14.101772785187 sec.25
    71@iamnp
    14.298875749111 sec.32
    72@skripkakos
    14.305522501469 sec.96
    73@OnScript
    14.555817246437 sec.142
    74@aserty15.127694249153 sec.175
    75@ ivanbl4
    15.24883300066 sec.148
    76@kinbote16.56739872694 sec.130
    77@ryokuyou
    16.7338377232332 sec.106
    77.5@MarvinPA21.251857995987 sec.186
    78@quarck21.369844019413 sec.157
    79@sultanko
    21.440900743008 seconds172
    80@ Yura1111
    22.057671248913 sec.thirty
    81@Troyal
    22.184078454971 sec.99
    82@Izobara
    23.361551761627 sec.16
    83@PutPixel
    35.820213794708 sec.180
    84@CheshaNeko53.085104465485 sec.120
    85@fromnull53.490429997444 sec.65
    86@ronsenval
    Wrong answer on complex tests14
    87@undiabler
    Wrong answer on complex tests26
    88@MrDindows
    Wrong answer on complex tests52
    89@kladovWrong answer on complex tests66
    90@ Andrew146
    Wrong answer on complex tests127
    91@vaux
    Exceeded time limit for difficult tests22
    92@marsencpp
    Exceeded time limit for difficult tests27
    93@phrkExceeded time limit for difficult tests43
    94@burtsevExceeded time limit for difficult tests55
    95@yooll
    Exceeded time limit for difficult tests58
    96@DarkContact
    Exceeded time limit for difficult tests70
    97@drongosar
    Exceeded time limit for difficult tests87
    98@alexvab
    Exceeded time limit for difficult tests90
    99@MrKonshyn
    Exceeded time limit for difficult tests91
    100@appplemacExceeded time limit for difficult tests112
    101@ msn92
    Exceeded time limit for difficult tests136
    102@ikalnitsky
    Exceeded time limit for difficult tests152
    103@ 0Chekhov0Invalid answer on simple tests.1
    104@ savik1
    Invalid answer on simple tests.2
    105@ zenden2k
    Invalid answer on simple tests.12
    106@alexaolInvalid answer on simple tests.17
    107@AvitellaInvalid answer on simple tests.18
    108@ yrik04
    Invalid answer on simple tests.24
    109@topz
    Invalid answer on simple tests.35
    110@drozdVadym
    Invalid answer on simple tests.37
    111@ anton280
    Invalid answer on simple tests.39
    112@ ehead01
    Invalid answer on simple tests.49
    113@ 8086
    Invalid answer on simple tests.fifty
    114@DIMKAAAAA
    Invalid answer on simple tests.57
    115@ mike_4d
    Invalid answer on simple tests.60
    116@alinemanInvalid answer on simple tests.74
    117@ pavor84Invalid answer on simple tests.75
    118@denzp
    Invalid answer on simple tests.79
    119@RamTararam
    Invalid answer on simple tests.81
    120@DezzK
    Invalid answer on simple tests.82
    121@frozendogInvalid answer on simple tests.83
    122@ sasha237
    Invalid answer on simple tests.98
    123@ aX1v
    Invalid answer on simple tests.103
    124@rutigl
    Invalid answer on simple tests.104
    125@JoricInvalid answer on simple tests.107
    126@LibertyPaul
    Invalid answer on simple tests.110
    127@volokitinss
    Invalid answer on simple tests.111
    128@Formicidae
    Invalid answer on simple tests.115
    129@fao
    Invalid answer on simple tests.117
    130@vkm
    Invalid answer on simple tests.124
    131@kleninzInvalid answer on simple tests.131
    132@knstqqInvalid answer on simple tests.135
    133@ryokuyou
    Invalid answer on simple tests.139
    134@morphingInvalid answer on simple tests.140
    135@VadddddInvalid answer on simple tests.144
    136@ancalledInvalid answer on simple tests.150
    137@fasterthanlightInvalid answer on simple tests.154
    138@sinc
    Invalid answer on simple tests.155
    139@SatayevInvalid answer on simple tests.159
    140@eversyt
    Invalid answer on simple tests.162
    141@zyss
    Invalid answer on simple tests.163
    142@ smile616Invalid answer on simple tests.166
    143@Moress
    Invalid answer on simple tests.169
    144@ zzzeeerrr0
    Invalid answer on simple tests.176
    145@kilotaras
    Invalid answer on simple tests.182
    146@I_AM_FAKE
    Exceeded time limits on simple tests7
    147@Aksiom
    Exceeded time limits on simple tests28
    148@WarAngel_alk
    Exceeded time limits on simple tests63
    149@skovpenExceeded time limits on simple tests132
    150@safinaskarExceeded time limits on simple tests160
    151@No username specifiedExceeded time limits on simple tests168
    152@jit_md
    Exceeded time limits on simple tests181
    153@mrigiTrying to work with a missing network146
    154@Tweekaz
    Compilation error3
    155@No username specifiedCompilation error4
    156@Thunderbird
    Compilation error9
    157@shock_one
    Compilation errorthirteen
    158@shyCompilation error23
    159@DgutCompilation error38
    160@ShouldNotSeeMe
    Compilation error56
    161@therussianphysicist
    Compilation error62
    162@aamuvirkku
    Compilation error84
    163@IntegralUnderground
    Compilation error85
    164@ 0leksandr
    Compilation error88
    165@ipoder
    Compilation error94
    166@IharBury
    Compilation error97
    167@xtern
    Compilation error100
    168@ KycokCo6aku
    Compilation error101
    169@gridemCompilation error118
    170@ minc2319
    Compilation error141
    171@okneigresCompilation error151
    172@antidotcb
    Compilation error164
    173@merkiusFile size exceeded71
    174@iTwin
    File size exceeded29th
    175@bstructureFile size exceeded153
    176@fsv
    File size exceeded51
    177@ 411
    File size exceeded72
    178@plehaFile size exceeded67
    179@staricam
    File size exceeded73
    180@chipaFile size exceeded119
    181@dosefoseFile size exceeded121
    182@SergeySib
    File size exceeded161
    183@PtaxFile size exceeded137


    Out of competition

    Decisions sent after deadline:
    No.HabranameDo I need an invite?ResultSystem id
    1@bstructure1.5542407631874 sec.192
    2@corsairnv
    12.768928468227 sec.194
    3@theirbaldness15.648555219173 sec.191
    4@ pavor84Invalid answer on simple tests.189
    5@Jamim
    Invalid answer on simple tests.193
    6@ 1dashCompilation error188


    About bugs

    They wrote for MS VC : __int64 instead of long long or __int64_t, math.h is not connected, using the missing stdafx.h.
    They wrote for Windows : Math.h <> math.h
    Bleeding-edge C ++ 11 features : Unfortunately, the correct code does not always compile. Clang has problems with C ++ 11 multithreading (the compiler cannot compile the standard library, the bug is known - I tried rolling the patch - but it didn’t help). If this is not tested before sending to the target compiler, then there is no way to detect the problem.
    Syntax errors : Banal care - I suspect sending an unsaved file.
    64-bit non-portable code : Attempts to implicitly cast a pointer to an int, and vice versa.
    memset: undeclared identifier 'memset'; did you mean 'wmemset'? It was an online test on the llvm website. The most popular mistake.
    C # : One case.
    Incorrect comment format with username : Solutions are still tested, so now they’re tormented somewhere :-).
    Segmentation fault : Half of the incorrect answers in the short tests are segfaults and crashes.

    You can see your compilation results here (see System ID).
    A complete archive of source code solutions .

    Solutions

    Initially, I wanted to talk about decision algorithms - but now I see that I have no idea how the first 2 places work, so it's better for us to wait for the authors :-) Nevertheless, it is worth noting that the use of threads is not a necessary condition for victory.

    Shadeware Winner
    @shadeware Nothing bugs you, it compiles.
    //@shadeware
    #include 
    #include 
    #include 
    unsigned i,n,Q,j,L;long long u[66],A;int main(){for(;i<448;i++)u[i/7+2]=u[i/7+2]*96+"+.Uy[e^4MAqc>,3Vq8a}n3-teC`p2r/)Fl[2Z)|>Ke2O~7FZ%$1+[%c\"<0dAd/tP1->\"0M!1;JwZ6!1*%j_y00V6$w!u10I dHR1PXF]r20!?Xhxw1?nbdEr0e-/ZE_0s:6:z.0[}+qG51f0\'\"aEs60OP;ZHs0zsjvXg0:~BPSu/aWY+&F1_aM,>24<<24;A=u[(n>>24)+1]+2*!L*!!~-n;std::vectorS(Q/2+1),B(n-L+2);B[1]=!L;for(i=3;i<=Q;i+=2)if(!S[i/2]){for(j=3*i;j<=Q;j+=2*i)S[j/2]=1;for(j=L?(L+i-1)/i*i:2*i;j<=n;j+=i)B[j-L]=1;}for(i=1;i+L<=n;i+=2)B[i]?0:A+=i+L;printf("%llu\n",A);} 
    Mikhaelkh, 2nd place
    @mikhaelkh The compiler cursed at a text string - but everything compiled.
    //@mikhaelkh
    #include 
    #include 
    unsigned char s[]=" 3ћfСЫБ b”Ђ)Cр —іЈ€Я $9шэD » $ѕ|Іш† %ЃЉЃмF &_яВГЕЕ 'Y¶FьВµ (nsџИp± )ќлznQ2 *иSР—ж) ,oшtе\\v -пW0BC† /«Ю#)ґ 1‚ьј”8P 3sю[Y6i 5.qЛ.“ 7¤zMЃшj 9г—‹XyЇ <_‰­XжЅ >ТOh«€Y AЃМ“«n DKr]µrЩ G.?“нU J*Ј»‚­Џ M@˜Eп†Ь PpYґпHј S№pvdјя W>дGpІш ZєQЦаЋ~ ^qяmty= bC†,щnт f.d“¤ ¤ j1Ж [|Ј nN№BўЮ: r…ЄG­рр vФiчwЁ{ {_Лз}Lh б*sЁЭ# „ћoї‹УE ‰to]¶е~ Ћd*4:иХ “kѕK8ћш ˜Њ~ќ˜QЄ ќЕЛ7д6« Ј;Ёл0ўь Ё§Iвc§б ObЗюЏP імЏxь>† №Е›»ЯPo ї·NцбЬ† ЕБ1ґgп& ЛгlъІcѓ ТAdЎ“[$ Ш–Й:ілЧ Я%юі±Ю1 е«_7бќЌ мlчnєСџ уF”ЭDРЭ ъ8ћуcћЖ $$CМжМMЕ $+gDbцPр $2ЎЧтУ‡E $9цАП†Ы ";
    enum{S=1<<14,N=1<<23};
    long long a[65],res;
    std::bitset u;
    std::bitset v;
    int n,r,x,i,j;
    int main() {
    	scanf("%d",&n);
    	for (i=1;i<65;++i)
    		for (++j;s[j]>32;++j)
    			a[i]=221*a[i]+s[j]-35;
    	*a=2,res=a[j=n/2/N],x=j*2*N,v[0]=!j;
    	for (i=3;i1?res:0);
    }
    Icemore, 3rd place, fastest multi-threaded solution
    @Icemore
    
    //@Icemore
    #include
    #include
    #include
    #include
    #define lng long long
    const int T=4,Q=33000,S=100000;
    bool np[Q],b[T][S];
    int p[Q],c,B,s,e;
    lng A[T],R,P[]={0,1906816620981654LL,7357074544482779LL,16217881619242062LL,28422918403819825LL};
    void* f(void*_){
    	long id=(long)_;
    	int C=(e/S-B+1)/T,q,M,i,j,k;
    	M=(id==T-1)?(e/S+1):(id+1)*C+B;
    	for(k=id*C+B;k1?j:2)*p[i]-q;
    			for(;j>n;
    	i=(n-1)/(1<<28);s=i*(1<<28)+2;e=(i+1)*(1<<28);
    	if(n-s-10?R:-R);
    } 
    
    ripatti 4th place
    @ripatti
    //@ripatti
    //идея - блочное решето с предпросчетом ответов для нескольких первых блоков
    #include 
    #include 
    #define S 150000
    bool F[40000],B[S];
    int P[10000],p=0;
    long long pre[]={0,79835127420606,307011790722811,675490692294675,
    1182357709860117,1825666731904492,2603717273255596,3515373254256955,
    4559774703609068,5736228298250417,7043215380181465,8481171232603598,
    10049045128993920,11745741297705187,13571569117886223,15525668198679060,
    17608378509778587,19817357312226874,22154562782502270,24618987306923167,
    27209541722648039};
    int main(){
    	int a,b,c,n,Z=(1<<15),Q=S*350;
    	std::cin >> n;
    	long long ans=pre[n/Q];
    	for(a=2;a*a
    kbxxi, 5-е место
    @kbxxi
    //@kbxxi
    #include 
    long long A[]={0,72619548630277,279209790387276,614333144695291,1075207199997334,1660170771905893,2367646772295462,
    3196703482711201,4146437503168147,5215984059716389,6404774487532576,7711724083073573,9137303389808024,
    10680189372387880,12340337443955708,14116726304047228,16010026481858292,18019518580817005,20143329357815162,
    22383876593236984,24739512092254535,27209541722648039};
    char S[50000100];
    int p[50100],C,i,j,B=50000000,l,r;
    long long R=0;   
    int main(){    
    	std::cin >> r;   
        for (i=2;i<=100000;i++)
        if (!S[i]){
            p[C++]=i;        
            for (j=2*i;j<=100000;j+=i)
                S[j]=1;
        } else S[i]=0;    
    	l=r/B*B+1;
    	for (i=1;p[i]*p[i]<=r;i++){
            int v=p[i],P=l/v*v;        
            if (P1) R+=2;
        std::cout<

    Singstio, самое короткое решение проходящее все тесты
    @singstio 304 байта, никакого «сжатия»
    //@singstio
    #include
    #include
    #include
    using namespace std;
    int main()
    {
      __int64_t n,sum=0,i,j,sn;
      cin>>n;
      sn=int(sqrt(n))+1;
      vector s(n+1,true);
      for(i=2;i<=sn;i++)
        if(s[i]){
          for(j=i*i;j<=n;j+=i)s[j]=false;}
      for(i=2;i<=n;i++)if(s[i])sum+=i;
      cout<


    Мораль

    • Сначала правильный алгоритм, потом многопоточность.
    • Перенос C++ программ на другую ОС, разрядность, компилятор — сложный и тернистый путь, тестировать на целевой платформе нужно обязательно. Вдвойне это касается bleeding-edge фич.


    О моих ошибках

    Вам кажется что у вас все работает, а в таблице — что-то неправильное?
    Рекомендую взять отправленное вами решение _из архива с решениями_, и скомпилировать на clang 3.2 64bit — и если заработает — тогда писать мне. Уже человек 10 написали, что у них все работает, а проблема всегда была или в другом компиляторе или во внимательности.

    Только зарегистрированные пользователи могут участвовать в опросе. Войдите, пожалуйста.

    Стоит ли организовать следующее хабра-соревнование через 3-6 месяцев, только с онлайн-приемом решений и проверкой на компилируемость не отходя от кассы?

    • 7.2%Нет уж, и так весь новый год испортил… К тому же, всегда есть USACO, TopCoder…130
    • 94.2%Пожалуй да!1681

    Also popular now: