Tameshk's blog

By Tameshk, 5 years ago, In English

I want to invite you to share your template code which you're using for Codeforces contests using Carbon(free and open-sourse) project. Mine (First but not Best!):

Hope you guys take care in this time of corona-related hardship!

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

| Write comment?
»
5 years ago, # |
  Vote: I like it +10 Vote: I do not like it

here is an ugly looking Template. ;)

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

Not a macro guy so mine's prob shorter than most. The stuff at the top is just debugging template.

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

    Not shorter than this. ;) Btw carbon looks very nice Tameshk, and I love the name.

    carbon76bfeb0cf2dcaa00.png

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

Thankx for letting us know about Carbon. It's AMAZING ;)

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

Unsurprisingly, the length of the template has (from the examples so far) been inversely correlated with CF rating :^)

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

    Not true for this guy : Egor. Look at the code lengh XD

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

      I have no template at all (or, strictly speaking, here is my submission template:

      %Code%
      
      int main() {
      #ifdef LOCAL
              signal(SIGABRT, &signalHandler);
      #endif
          std::ios::sync_with_stdio(false);
          std::cin.tie(0);
      #ifdef LOCAL_RELEASE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
          auto time = clock();
      #endif
      	%ClassName% solver;
      	%Input%
      	%Output%
      	%SolverCall%
      	fflush(stdout);
      #ifdef LOCAL_RELEASE
      	cerr << clock() - time << endl;
      #endif
      	return 0;
      }
      

      ). I do use inliner though

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

        Can you please share your library on GitHub or something ? Egor

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

          Here you go

          I'd appreciate any suggestions

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

            Sure. Thank you!

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

            Hey Egor! Thanks for sharing your library with us. I have a doubt. This link does not include code inliner.(Or Is it?)
            If not, Can you please give a link to it? Thanks in advance.

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

              Google "JHelper"

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

        I'll count this as a win for my predictive model :)

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

          Waiting for your analysis! This is going to be interesting

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

        Do you use patched JHelper? Noticed you have removed the in/out params but didn't notice any new code in your fork

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

          Yep, I think I just forgot to push

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

    Don't worry I get it.

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

    your statement spectacularly fails for Savior-of-Cross and his beauty

    (yes I know that Savior-of-Cross doesn't use this in contest)

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

      You really can't consider that a template. It's an algorithm library. For example, you can't compile that as is (variable names are reused, etc.). I use KACTL (https://github.com/kth-competitive-programming/kactl), which also has a ton of lines of code total, but doesn't have a very long template.

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

    Hitting on 1000 lines and I'm not a newbie (yet). Behold the outliers :)

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

[Here is a simple one.](carbon-1)

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

Here's mine :) Different sections are imported when needed (not by default).

P.S. Your project is really awesome ^_^

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

    Thanks for comment. It's not mine, but it's really awesome ^_^

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

Here's the JAVA code template I use:

carbon74c05b1e0890611d.png)

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

Well just those common macros nothing fancy(as expected from a noob xD (carbon70d89b563183424e.png)

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

    was curious about how you wrote cubefreak777 ?? like is there a script or something or you did it manually?

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

I don't have a proper template :) Probably, because I'm too lazy. For people with big templates: please, consider hiding them in spoilers, it would make the thread much more readable.

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

 Can someone tell me how to use that clock to check execution time,its not working.

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

    Maybe you're not compiling with the correct preprocessor directive? Your code snippet seems to require LOCAL_RELEASE to be defined.

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

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

    You can call both power1 and power2 power; the difference in header will overload the function signature and the version called will just depend on whether you pass in the mod argument. Also, it probably won't matter because ll overflow is rare, but you may want to rewrite the lcm argument as (x/gcd(x,y))*y to prevent x*y from overflowing.

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

here is mine, it's so simple btw carbon looks very nice, great work Tameshk

Spoiler
»
5 years ago, # |
  Vote: I like it +11 Vote: I do not like it
Spoiler
»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

    Hi. I see you are using c++17 on cf. I'd like to tell you about one funny thing. Your template has lcm function which is defined for long longs, but c++17 has it's own function with the same name, so it replaces yours with the std one. Why does it matter? Std function's return type is the same as argument type, so if you run

    cout << lcm(1000000000, 1000000000 - 1);
    

    You will see 1808348672( overflow ), because args are of type int. It's very tricky, isn't it? Here's how you can fix it:

    1. add #define lcm(x, y) lcm((ll)(x), (ll)(y)) instead of implementing your own lcm function

    2. add #define lcm randomlongstringwhichyouwillneveruseasanameorsomethinglikethat after including libraries, this way your function will be used

    p. s. talking about lcm I suggest that shahil_005 throws that weird-ass lcm function out of his template there are so many things wrong with it

    UPD: soumitri2001 you have fucked up lcm function as well(but for a different reason. Change (long) (a*b/gcd(a,b)) to (long) ((long)a*b/gcd(a,b)). The a*b part gives you overflow

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

      Thank you very much! I didn't notice that.

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

      I would just do

      #define gcd(a, b) ggcd(a, b)
      

      where the function ggcd has the gcd function.

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

I don't know how to use macro

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

Here's mine:

carbon-1

Usually, I start from scratch, or copy-paste from my last code
I don't have any macros

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

    how do you save it?I pressed the "Image" button but nothing happens:(

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

Whats the point in posting screenshots of sourcecode?

»
5 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

1000 lines of code just make it stucked... UPD:Just like this code

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

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

    how do you save it?I pressed the "Image" button but nothing happens:(

»
5 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

This is mine, I saw Geothermal use it in his Div. 3 unofficial editorial and thought it was good and that I wouldn't have to change it for a long period of time, and so far it's served me really well. Though I made a few edits of my own.  Pastebin link because I just can't get carbon to upload the template

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

Here's mine template, ugly but fun. ;D

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it
My query template
My graph template
My Hello-World template
My normal template
»
5 years ago, # |
  Vote: I like it +13 Vote: I do not like it

You can avoid to use macro CONFIG:

const bool ready = [](){
    std::ios_base::sync_with_stdio(false); std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(12);
    return true;
}();

This lambda will be called before main. Example

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

    Oh, Pretty neat.

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

    Are you sure that "std::cout" will be initialized before "ready"?

    Seems to be UB.

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

    Thanks for sharing this elegant lambda expression.

    The followng is a slight update that uses auto as the return type of the expression.

    Update

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

My template

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

C++:

Rust:

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

Ok so I was preparing to post but I really didn't want to drown everybody's codes with my monster, gotta share the spotlight. See any of my submissions 78664902 to understand :p

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

    Nobody asked for your whole library. He just asked for your template. ;)

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

      This is my template. I put it before every code even if it's int n; cin>>n; cout<<n<<endl; :D

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

Creating images instead of pasting code with CF formatting. Heavier page to load, and nobody can't copy-paste something useful from here, nice.

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

    You don't learn from copy-paste! You should make your own template without taking exactly the same template from random red guys!

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

      People can anyway go to submissions of that red coder, and open any code.

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

        Yes errichto, I copied yours. Thank you for that brilliant suggestion.

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

Short, efficient, unique.

I use snippet shortcuts to insert algorithms and implementations when needed.

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

I don't use it during contests, because I don't have time to complete it yet, but I published mine on my blog : Input/Output.

I also have a tool that includes functions that I need at compile-time on my github : C-Tool

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

Here's my submission template :)

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

Short and simple, loaded and ready for multiple test-cases and focus only on the solve function.

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

Too much templates !!! I will have long long time to learn all of this. Thank you everyone <3

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

My UltiSnips snippet for vim

»
5 years ago, # |
  Vote: I like it -19 Vote: I do not like it

It failed to accommodate the whole code, so a huge part of this picture is just black.

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

Why does every body using dark theme? :) carbon.png

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

it's mine :)

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

I want this theme for my compiler...anyone knows either online or offline compiler which contain this theme .

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

    I guess you can install themes on your editor since those themes are not created by the author.

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

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

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

My template is

here

Standard I think. Not using

Header

I feel like it is too slow when running on test cases...

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

Here you g----->o
carbon-1

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

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

Small and simple

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

The main thing is #define int long long. WA from overflow too many times

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

    Why do u have both #define int long long and typedef long long ll.

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

Debugger that you might like, since it can be used without writing a single line of code in your final submission file.
(See sample_program in the link given above.)

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

I try to keep it as simple as possible, and not exaggerated.

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

carbon.png