Swistakk's blog

By Swistakk, history, 3 months ago, In English,

Hi, I wanted to present to you guide on how you should set up TopCoder Arena in order to make competing in TC much more pleasant experience. Or at least guide how to do the same thing as I did which seem very comfortable to me compared to this big pain of competing in bare default Arena. In case you want to grab easy upvotes please leave here some joke about how I am jealous about Radewoosh getting insane boost in his contribution by writing his blogs, but the real reason is that I screwed my setup recently and needed to go through this painful and magical setup once again and it seems this information is very nontrivial and not available publicly in a known place (which I believe is one of reasons TopCoder is losing its popularity, but I hope thanks to this post I can give slight boost to it by settling up Arena problems once and for all for many people), so I wanted to share it with others. I want to express my sincere thanks to tomasz.kociumaka for guiding me by hand in this process (twice), because I would never be able to do this on my own. By the way, I use Linux, obviously. Probably many steps are also similar on Windows or Mac, but I'll leave any hypothetically needed changes up to you.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Plugins I use are CodeProcessor, FileEdit, moj and pq. Overall functionality they offer me is:

1) When I open a problem statement they create a new file corresponding to this task in a designated location.

2) This file contains template code I used, created class for me with already correctly declared method I need to fill in and namespace with samples which are then executed in main.

3) After I end coding I am able to compile my program locally (with my own debugging flags), run it and get automated feedback about its speed and correctness. This is done by moj plugin.

4) I have a simple way of adding my own sample testcases.

5) When I'm ready to submit I need to hit "Compile" button in arena and then "Submit".

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So let's go to the point of how we should go about setting this up:

1) Go to this page https://www.dropbox.com/s/375tyunr3y0bb0k/TCplugins.zip?dl=0, download this zip and extract it in your fapfolder. I will denote path to this extracted folder as /path/TCplugins

2) Go to Arena, log in and go to Options->Editor->Add and fill this accordingly:

Name: CodeProcessor
EntryPoint: codeprocessor.EntryPoint
ClassPath: Add 4 paths here, to CodeProcessor.jar, FileEdit.jar, moj.jar and pq.jar (I've done this by multichoice with held Ctrl). After this it should look like /path/TCplugins/pq.jar:/path/TCplugins/moj.jar:/path/TCplugins/FileEdit.jar:/path/TCplugins/CodeProcessor.jar

save this and tick boxes next to newly added line (and maybe uncheck others if you have any ticks elsewhere)

3) Click on this newly added line and click "Configure". New big window will pop up. Fill Editor EntryPoint as fileedit.EntryPoint . Next to "CodeProcessor Scripts (...)" hit "Add" and add two entries "moj.moj" and "pq.MyPostProcessor".

4) Hit "Configure" next to Editor EntryPoint and specify path where your codes will be appearing (do not use "~" in your path, it doesn't work, you probably want to use something like /home/anon/something). Uncheck this very stupid option "Backup existing file then overwrite". Go to "Code template" and if you use C++ then modify your template to something like this (filling out parts within underscores): https://www.dropbox.com/s/63unh4paj1k4o1k/TopCoderTemplate.txt?dl=0 (I wanted to paste it here, but my attempts to correctly display dollar sign were futile, if you know a good way to do this, please message me). If you happen to use hack like "#define int long long" then also put "#undef int" before line with method declaration and "#define int long long" after it.

5) Restart you Arena and you are ready to go! Go to some practice room and do Div2 250 to familiarize with workflow with all these newly added plugins.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

A few technical notes I would like to point out:

1) If I'm not mistaken on TopCoder your program is executed many times — once per every testcase. However locally your program is executed one time and it does many calls to specified method. It may seem like there is no difference, but there is a significant one — state of your global variables. You may leave your global variables in some random state and it will not affect execution of your program on testing servers, but it can affect behaviour of your program locally and you may get local WAs even though your program would be considered correct by TC. However I very rarely use global variables in TopCoder because only reason I can think of right now for using them is that when declared globally instead of putting them as attributes of my class, they are zeroed by default (which disappears if you want to be able to test your program locally, because you need to clean them anyway).

2) If you did some defines it may affect your remote compilation on server. Your code is somehow included in testing framework and this code TC adds to your code in order to grade your solution uses some variable names etc. too. It is unlikely that something like "#define SZ(x) (x).size()" will affect compilation on server, but "#define int long long" will very likely do so. That's why if you use some common expressions in defines, you better undef them (like "#undef int") at the end of your code, because otherwise you will get compilation errors when submitting even though your program compiles locally and it will be very confusing.

3) Apparently, informations about this setup are stored in ~/contestapplet.conf file. You can save a copy of it in some safe place (so that you can restore it whenever you do some mess or change your laptop) and be aware to not move this file around (that's how I screwed up my setup recently, because I cleaned my home directory of some weirdly looking files).

4) When testing locally, what is performed in order to check correctness of your code is to do some simple diff (it takes appropriate care when there are doubles in output, so don't worry about them). Be aware that problems with multiple allowed outputs exist and in such cases local testing tool will say that you FAILED, so in such cases you will need to validate your output by yourself (or use "Batch test"). But that is the same as in every other platform (unless we are provided some checker, but we are never provided, so yeah). Be aware that in such cases you should use option "Batch test" in arena which checks correctness of your output (but look at field "Correct example", not "Success")

5) Sometimes expected output is an empty vector. Code attached for testing on samples doesn't compile when expected output is an empty vector (in cpp), so you need to manually adjust that. For example by changing expected answer to {-1} and checking correctness by verifying that all your failed sample cases look like:
Received: { }
Expected: {-1}

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

»
3 months ago, # |
Rev. 3   Vote: I like it +56 Vote: I do not like it

In case you want to grab easy upvotes please leave here some joke about how I am jealous about Radewoosh getting insane boost in his contribution by writing his blogs [...]

[insert joke about how Swistakk is jealous about Radewoosh getting insane boost in his contribution by writing his blogs]

  • »
    »
    3 months ago, # ^ |
      Vote: I like it -11 Vote: I do not like it

    LMAO. [insert joke about how aryaman.arora2020 is trying to troll lgms because he wants to seek attention.]

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

      I feel like LanceTheDragonTrainer writes comments with sense recently, and he still gets downvotes just as a tradition xd

      Regarding the blog: That's a lot of work, what suggests that TC platform is bad :( I wonder what are the rules of TCO. Do they allow participants to bring their own laptops? Or to have half an hour before the competition to configure everything?

      Maybe it's possible to compare doubles with an allowed error by default in your configuration? They appear quite often in TC, so a change like that would be useful. That being said, I'm not going to use your tools because IMO it doesn't hurt that much to type in arena and then copy to my IDE if the code doesn't work and is complicated.

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

        They allow participants to bring their own laptops.

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

        Plugins take care of comparing doubles, what they don't handle is "any valid solution will be accepted" problems, in which case you will have to use the Arena checker (the one that says "success, correct answer: false", which has obviously never confused anyone :P)

»
3 months ago, # |
  Vote: I like it +47 Vote: I do not like it

I can confirm that your item 1) is correct.

And regarding 2), if people use ugly hacks like "#define int long long", they fully deserve it if it sometimes comes back to bite them :)

  • »
    »
    3 months ago, # ^ |
      Vote: I like it -12 Vote: I do not like it

    What is wrong with #define int long long and #define abs llabs sir?

    I used them all the time and never got WA even once. What prob does it have?

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

      I used #define int long long and got TLE/MLE once :(. The problem disappeared when I used long long only when I need to use it.

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

      "#define abs llabs" sounds really silly. abs in std already works for ll.

      • »
        »
        »
        »
        3 months ago, # ^ |
        Rev. 3   Vote: I like it 0 Vote: I do not like it

        what about using fabs? ;p

        Answering to Necrozma: You use more memory and sometimes more time. When you must use ints (e.g. you know a program doesn't fit in the memory), you are not used to catching places where LL is needed. The same when you want to write in a different language or you want to write a production code in a company. And it's trickier to solve problems where you should implement a function with some given format.

»
3 months ago, # |
  Vote: I like it +33 Vote: I do not like it

Regarding item 1), I have the following code instead of the DEFAULTMAIN in my template:

#include <unistd.h>
int main(int argc,char *argv[])
{
	int x = argc == 1 ? 0 : atoi(argv[1]);
	int R = moj_harness :: run_test_case(x);
	if(argc == 2) return 0;
	int total = argc < 4 ? 0 : atoi(argv[3]), correct = argc < 5 ? 0 : atoi(argv[4]);
	if(R == -1)
	{
		if(total == 0) printf("No test cases run.\n");
		else if(total == correct) printf("All %d tests passed!\n", total);
		else printf("Some cases FAILED (passed %d of %d).\n", correct, total);
		return 0;
	}
	x++;
	total++;
	correct += R;
	char txt[30], tot[30], corr[30];
	sprintf(txt, "%d", x);
	sprintf(tot, "%d", total);
	sprintf(corr, "%d", correct);
	execlp(argv[0], argv[0], txt, txt, tot, corr, NULL);
}

What it does is run every testcase as a separate process, with the test number passed as command line argument. You can also run a single case via e.g. ./yourexecutable 3 to run 3rd case.

I believe the credits go mainly to marek.cygan as I found the process spawning scheme on his webpage and added some modifications (IIRC the display of summary is mine).

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

    It doesn't come as a surprise to me that this code may be authored by marek.cygan :P. If you look at their team library it's full of ugly global variables etc xD.

»
3 months ago, # |
  Vote: I like it +53 Vote: I do not like it

Or, if you program in Java, just use CHelper and it will do everything out of the box

»
2 months ago, # |
  Vote: I like it +3 Vote: I do not like it

I am new on Topcoder, and I can't even login in arena applet. There is a message that saying "A connection to the server could not be established". What am I missing?