How to test your solution in Competitive Programming, on Linux?

preview_player
Показать описание


I'm known as Errichto. I compete in and organize programming competitions. I'm a finalist of ACM-ICPC, Topcoder Open, Facebook Hacker Cup and Google Code Jam. I got a second place in Google Code Jam 2018. Watch me if you want to practice Competitive Programming, algorithms or you want to learn for a coding interview. I share my thought process, explain everything, and mention similar problems that I know or techniques/algorithms that could be used too. Learn from me and grow your rating on Codeforces!
Рекомендации по теме
Комментарии
Автор

dude, keep doing this, this is original content.

nullnull
Автор

Thank you for this! It helped me a lot with solving some problems in a recent Codechef contest.

abhijeetkrishnan
Автор

One of th best tutorials for programmers .... Thanks Errichto

Nampjg
Автор

I am also using Linux, Ubuntu 18.04.
loved your channel and getting lot of motivation from your channel.

indiansoftwareengineer
Автор

With this video, I not only learn about up solving but also Linux commands :P

prateeksinghal
Автор

Most Helpful Video of Youtube Ever Seen

harivilas
Автор

very useful for codechef were testcases arent shown which becomes difficult while upsolving

shameekagarwal
Автор

Nice video, thanks!

How would you test a solution with multiple correct answers?
For example, let's consider the following problem: "Given a number N (N > 2), print a positive number less than N". Obviously there are multiple correct answers, but the brute force solution might return something different than the other solution. In this case just diff-ing the output is not sufficient. :)

Maybe in such cases an additional checker program should be provided. However, it might sometimes seem that writing an efficient solution + brute force solution + checker could be very time consuming.

hutofrock
Автор

Thanks, I wanted to know it and, its pretty awesome the way it works.

shubhamk
Автор

Great video. I like this approach to testing. The script is simple so you can easily write it during a contest. I prefer using an extension for VS Code to test my solution on my laptop. I guess it's up to you what you choose.

In 0:29, there is a small mistake in eng subs. Instead of "you CANT submit a solution" should be "you CAN submit a solution". That would be stupid if you couldn't submit a solution on contest :)

Xenox_dev
Автор

How to debug the problems ? after finding a breaking test case in case of a backtracking solution which is harder to debug using breakpoints?

Pauljanson
Автор

Awesome! Are you still considering DP contest from AtCoder in some next stream?

getintodevices
Автор

Please make a video on testing interactive problems' solutions efficiently.

nafiurrahmankhadem
Автор

Sir how to generate random test cases if the given input is a tree

satyajeetkumar
Автор

How to test on large input files? For example 20000 KB size of input file

piotrbublik
Автор

Outside a script I think it's more convenient to use "git diff", not "diff"

Golovanov
Автор

Does this mean that we need to have a brute force solution for the question in order to check it? What happens when the solutions are not easy and we can't find the bute force solution?

vishnuvs
Автор

How to do the same things in WIndows??

lovleshbhatt
Автор

Thank you very much, I will watch it.

adityasher
Автор

i was trying this. The only change I made was not to generate unique numbers. So i removed do..while loop. Problem is for a given seed
value, I am always generating same sequence. The code is :

#include<bits/stdc++.h>
using namespace std;


int rand(int a, int b)
{
return (a + rand() % (b-a+1));
}

int main(int argc, char* argv[])
{
//srand(time(0));
srand(atoi(argv[1]));
int n=rand(2, 10);
printf("%d\n", n);
for(int i=1;i<=n;i++)
{
int x;
x=rand(1, 10);
printf("%d ", x);
}
puts("");
}

and for seed 1, that is, ./gen 1 this is the output i always get
3
7 8 6
i want the numbers generated to be repetitive and not unique. Any solution to that ?

edit: Even running the same code as in video is giving me same sequence of integers every time for a given seed

Edit 2: i just learnt that rand() generates a pseudo random sequence. So thats the reason the values are fixed for a particular sequence.

So i just change my question. Is there any way to fix this issue. I have used srand(time(NULL)) but its time interval is 1 second. So the seed is fixed for one second. In one second if i have to generate multiple sequence there seed is same so the sequence is same. Can we generate a truly random sequence in c++ ?

theeasypeasysquad