MikeMirzayanov's blog

By MikeMirzayanov, history, 4 years ago, translation, In English,

I am glad to inform you that C++14 has been added to the list of supported languages ​​on Codeforces. The choice fell on the compiler MinGW-w64, version of GCC 6.2.0 (will be updated on new releases). If you have Windows, you can easlily install it using PBOX with one command pbox install mingw-w64.

Besides trendy features of C++14 (not sure there's a lot to the contests), there are some advantages:

  • this compiler is faster than mingw-tdm 5.1.0 on cin/cout — for example, reverse a sequence of 106 integers from 1 to 106 runs 1.5 seconds instead of 2.5 (0.3 vs. 1 if you use std :: ios :: sync_with_stdio (false))
  • works correctly to print a double with the both specifiers %f and %lf (you should read using %lf)
  • works correctly to read-write long double with the specifier %Lf
  • works correctly to read-write long long both with %lld and %I64d

It seems that lately we remove support of MinGW C++/C++11 (especially since it is difficult to upgrade them to GCC 6 due to backward compatibility issues). Of course, after a while C++14 will appear on Polygon.

 
 
 
 
  • Vote: I like it
  • +1159
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +28 Vote: I do not like it

Are there any nifty features like those from c++11?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +47 Vote: I do not like it

    Mostly for jury it will be good idea to use apostrophe to separate thousands (say, in validators) like:

    int n = inf.readInt(1, 1'000'000'000, "n");
    
    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      1e9 is in C++ for already long time :). It is by far the best way of inputting large bounds in my opinion.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it +56 Vote: I do not like it

        as long as it doesn't fail silently

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it -8 Vote: I do not like it

          Yeah, I was aware of that and I silently expressed that by subtle choice of words =). That's why I said "bounds" not "numbers" :D. One should be aware of that however that's very rare usage whereas inputting something like 1e5 + 5 needs to be done in literally almost every problems.

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it +62 Vote: I do not like it

            Don't write comment if you know it may mislead someone.

            "My comment may be interpreted in such a way that it's correct" isn't a strong argument.

            • »
              »
              »
              »
              »
              »
              »
              4 years ago, # ^ |
                Vote: I like it +34 Vote: I do not like it

              Yeah, I guess it could have been misleading. Sorry for that. I had mentioning it in my mind, but I was in a bit of hurry and was writing from mobile, so that's because I chose replacing "numbers" with "bounds" =p.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
          Rev. 3   Vote: I like it -27 Vote: I do not like it

          ...

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          With just a little more typing, maybe do int64_t x = (int64_t) 1e18 + 1;?

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it 0 Vote: I do not like it

            Is it guaranteed to work?

          • »
            »
            »
            »
            »
            »
            4 years ago, # ^ |
              Vote: I like it +3 Vote: I do not like it

            it works only accidentally.

            • »
              »
              »
              »
              »
              »
              »
              4 years ago, # ^ |
                Vote: I like it -10 Vote: I do not like it

              What exactly here is an 'accident'? Fact that (int64_t)1e18 == 1000000000000000000?

              • »
                »
                »
                »
                »
                »
                »
                »
                4 years ago, # ^ |
                Rev. 3   Vote: I like it +8 Vote: I do not like it

                more like fact that 2 | 10 (I mean base used in computers is divisible by base used by people, not particular numbers), so 10^n is divisible by several powers of 2

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Maybe this could be a solution? You may pre-define as many as you want in your default code so you won't have to type it every time.

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it +16 Vote: I do not like it

      Please could you update the source code highlighter to support this feature, because the current one thinks that those apostrophes are character literals and the formatting becomes ugly.

      #include<iostream>
      using namespace std;
      
      int test = 1'000'000'000;
      
      int main() {
      
      }
      
  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Now you can write auto in lambdas, make recursive dfs in lambda without unnecessary overhead, etc

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +16 Vote: I do not like it

    you now can do things like this

    #include<iostream>
    #include<stdio.h>
    using namespace std;
    
    bool zero = 0;
    char one = '1';
    short two = 2;
    int three = 3;
    long long four = 4;
    
    int cnt;
    void z(auto a, auto b, auto c, auto d, auto e, auto f, auto g, auto h){
    	if(h!=zero){
    		cout<<a<<b<<c<<d<<e<<f<<g<<h<<endl;
    		++cnt;
    		return ;
    	}
    	z(one,a,b,c,d,e,f,g);
    	z(two,a,b,c,d,e,f,g);
    	z(three,a,b,c,d,e,f,g);
    	z(four,a,b,c,d,e,f,g);
    }
    
    int main(){	
    	z(zero,zero,zero,zero,zero,zero,zero,zero);
    	cout<<cnt<<endl;
    	return 0;
    }
    
»
4 years ago, # |
  Vote: I like it +85 Vote: I do not like it

works correctly to read-write long long both with %lld and %I64d

works correctly to read-write long long both with %lld and %I64d

works correctly to read-write long long both with %lld and %I64d

works correctly to read-write long long both with %lld and %I64d

Finally!

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +184 Vote: I do not like it

    Actually, %lld/%I64d already worked correctly about 3-4 years.

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 2   Vote: I like it +22 Vote: I do not like it

      So the warning about %lld when submitting should be removed then?

      EDIT: I just found out that there is a don't show again tickbox to prevent the warning from showing up again.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I've been on CF about 3-4 years :D

      I thought the warning still existed because it didn't work yet...

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +91 Vote: I do not like it

    more like

    Finally!

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +41 Vote: I do not like it

»
4 years ago, # |
Rev. 2   Vote: I like it -67 Vote: I do not like it

will xcode be supported at any time in the future /?

UPD : i meant the C++ language that xcode uses ... it's a bit strange from MSVS2010 and C++11 .... i wish that some day xcode will be a language to submit like MSVS

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +24 Vote: I do not like it

    xcode is not a language.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    i think you mean the clang++ compiler since thats what Xcode uses

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +7 Vote: I do not like it

    Testing is done on Windows and clang doesn't fully support Windows yet.

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      What are you talking about? It surely does.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        If it did, Chromium would use clang on Windows by default and would never look back. Google is working on this issue, so hopefully we don't need to wait long.

        • »
          »
          »
          »
          »
          4 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          MSVC has a better optimizer, so the release builds are built with it. Clang is widely used internally though.

»
4 years ago, # |
Rev. 2   Vote: I like it -8 Vote: I do not like it

Hoora!! so what is g++14?!

What's the different between g++11 & g++14?

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it +22 Vote: I do not like it

    One of the most interesting features in aspect of competitive programming is: auto f(auto i, auto j) { return i < j; }. Now both return type and parameter types are automatically resolved while compiling — it might save some bytes.

»
4 years ago, # |
  Vote: I like it +17 Vote: I do not like it

I'm sorry if this is out of topic, but when did CF completely remove Java 7 ? I recently realized that during contest #366, I submitted A and B using Java 7, and C onwards, Java 8 was the only Java version available..Was Java 7 removed right during the contest ?

»
4 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Wow!!! great news.

»
4 years ago, # |
Rev. 5   Vote: I like it +91 Vote: I do not like it

A word of warning: looks like scanf is much slower on C++14 than it was on C++11. Here are three submissions using almost the same code on a problem:

So if you're using C++14, looks like it may be best to avoid scanf/printf now.

Edit: As pointed out below, a possible workaround is adding "#include <stdio.h>" before all other headers to the code, but this may break other things in the standard library (I don't know exactly what): 20295608

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +17 Vote: I do not like it

    That sounds like a huge disadvantage of a new version, it means that it's not possible to simply replace current compilers for C++98 and C++11 with a new one as it would fail lots of already working solutions. Can anybody using Windows investigate the reason of such slowdown?

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +16 Vote: I do not like it

      Probably the same reason why it's more accurate; while old compiler used to call the functions in the MSVCRT (Microsoft C Runtime Library), mingw-w64 took the approach of reimplementing the standard library.

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +11 Vote: I do not like it

    I've tried other problem and got these results:

    • »
      »
      »
      4 years ago, # ^ |
      Rev. 3   Vote: I like it +30 Vote: I do not like it

      The reason I chose that specific problem was because the actual computations were extremely simple, so not much could change other than scanf/cin performance.

      Your benchmark is spending the most time in priority_queue operations, so that's what you're really measuring (and it looks like C++14 priority_queue is much faster than C++11 priority_queue).

      As you can see, reading the input of that problem with scanf takes 150ms on C++14 (20294340) and only 50ms on C++11 (20294356)

  • »
    »
    4 years ago, # ^ |
    Rev. 4   Vote: I like it +40 Vote: I do not like it

    20294551 c++14 scanf stdio.h 265ms

    20294631 c++14 scanf cstdio tle

    Is there any reason why this would happen?

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it +24 Vote: I do not like it

      Funny stuff!

      As I can see in the mingw-w64 headers, including <cstdio> includes <bits/c++config.h> which includes <bits/os_defines.h> which contains the following code:

      // Make sure that POSIX printf/scanf functions are activated.  As
      // libstdc++ depends on POSIX-definitions of those functions, we define
      // it unconditionally.
      #undef __USE_MINGW_ANSI_STDIO
      #define __USE_MINGW_ANSI_STDIO 1
      

      If this file doesn't get included, it uses MSVCRT implementations of scanf/printf, just like the C++11 compiler.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I believe if it's not included, some incompatibilities between between already built libstdc++ and existing code may arise and break something.

      • »
        »
        »
        »
        4 years ago, # ^ |
          Vote: I like it -10 Vote: I do not like it

        Sorry for bothering you but do you have any idea whether this problem still exists if I include <bits/stdc++.h> instead :)) Thanks so much

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +24 Vote: I do not like it

    Some good news for stdio haters :)

»
4 years ago, # |
  Vote: I like it -22 Vote: I do not like it

"for example, reverse a sequence of 10^6 integers runs 1.5 seconds instead of 2.5"
"(0.3 vs. 1 if you use std :: ios :: sync_with_stdio (false))" Cool!


Some stories: (just for fun)
so maybe same codes gives TLE when submitted with old compiler and AC with this compiler.
so some TLE java users will think about using cpp as a solution ^^
so some cpp users will update #defines
so we will detect disadvantages of this version soon.
so some problem setters will thinking about (time limit per test: 0.6 seconds) 0_o
so some users at the end of code remove %I64d and write %lld as a (job secret) :D
you are smiling now :).
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

So after half a year...**C++17** will be supported?

»
4 years ago, # |
  Vote: I like it +34 Vote: I do not like it

__int128 is still not supported... Linux g++ supports it and thus it is available in most of online judges including ICPC WF judge.

  • »
    »
    4 years ago, # ^ |
    Rev. 3   Vote: I like it +18 Vote: I do not like it

    mingw-w64 also supports it, but in the 64-bit version (I think Linux g++ only supports it in 64-bits as well, no?). Mike probably installed 32-bit version, which doesn't have __int128.

    I wish we had __int128 here too :c

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    It's because testing server has 32-bit OS, I think. :(

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone help? Where can I get a C++14 for free? Does anyone has a hyperlink leads to the download page?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

pbox install mingw-w64: FATAL [2016-08-31 16:20:50,263] Unexpected error: Can't find mingw-w64$6.2.0.pbox.7z for 'mingw-w64$6.2.0'. Are you sure the package exists? java.lang.RuntimeException: Can't find mingw-w64$6.2.0.pbox.7z for 'mingw-w64$6.2.0'. Are you sure the package exists? at me.pbox.command.InstallCommand.run(InstallCommand.java:44) at me.pbox.command.DefaultCommand.run(DefaultCommand.java:21) at me.pbox.Main.main(Main.java:104)

»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

20301838: MS C++, scanf, 1559 ms

20301823 : GNU C++11, scanf, 1731 ms

20301815 : GNU C++14, scanf, TLE (time limit 3 seconds)

<cstdio> included

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Those who are using Windows 10 and anniversary update, they will get linux beta version in developer mode. I am not sure about earlier version of windows 10 but this one I have tried. I think this will remove the necessity of CYGWIN or other tools for windows.

How to enable it — Steps to follow — 1) go to settings 2) update and security 3) for developers, click on developer mode

After that- 1) open control panel 2) go to program and features(if you can't find it go to uninstall program) 3) you will see turn features on or off(you can directly search it in cortona or search bar), click on it 4) you will see "window subsystem for linux beta", include the folder and its sub folders and now you have workable linux.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Thank you Mike for your work making this feature possible :)

»
4 years ago, # |
  Vote: I like it -13 Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

I'm wondering if this is the first blog, which has +1000 upvotes ?

»
4 years ago, # |
  Vote: I like it +19 Vote: I do not like it

When C++ 14 will appear on Polygon?