r/programmingcontests • • Jan 04 '23

Plagiarism Checker for hosting coding contests

2 Upvotes

So i am a part of the organizing team for a coding contest in my college. We are planning to use hackerrank for hosting the contest. This is an online contest which can be given by the participants from their homes.
So in this, we are going to need any software,application etc that will help us find out whether the solution sent has been copied from a website or something. So if anybody has any idea on how to deal with this issue, kindly let me know


r/programmingcontests • • Dec 13 '22

Number of strings of length N consisting of ICPC letters.

2 Upvotes

Here's a nice question from recent Olympiads. Can anyone help with the solution?

Thanks.


r/programmingcontests • • Sep 28 '22

Top down DP approach for distinct subsequence problem

2 Upvotes

I was trying out distinct subsequence problem:

Given two strings s and t, return the number of distinct subsequences of s which equals t. For example, if s = "rabbbit" and t = "rabbit", then the answer is 3 as there are 3 ways you can generate "rabbit" from s.

I came up with following dynamic programming solution with 2D array for memoization:

def numDistinct(self, s: str, t: str) -> int:
    
    s_len = len(s)
    t_len = len(t)
    
    dp = [[0 for _ in range(s_len + 1)] for _ in range(t_len + 1)] 
    
    for j in range(s_len+1): dp[0][j] = 1 
    
    for i in range(1, t_len+1):
        for j in range(1, s_len+1):
            if t[i-1] == s[j-1]:
                dp[i][j] = dp[i-1][j-1] + dp[i][j-1]
            else:
                dp[i][j] = dp[i][j-1]
    
    return dp[t_len][s_len]

This follows bottom up approach. That is we start building target string from empty string to full target string "checking if string traversed so far is derivable". So we start index 1 onwards. I was guessing if there can be top down approach for the same. That is starting from indexes t_len+1 and s_len+1 down to 0 while "checking if remaining target string can be derived". I am not able to guess what will be the recurrence relation for such top down approach.

PS:

I am able to build below recursive solution which goes from indexes t_len+1 and s_len+1 down to 0. But it is really a bottom up approach disguising as top down. The fact that the problem is symmetric makes easy to start from either ends of indexes and come up with solution which is bottom up. That is why I asked the question for iterative solution, which possibly makes difference between top down and bottom up approach more clear.

from functools import cache

class Solution:
    
    def numDistinct(self, s: str, t: str) -> int:
    
        @cache        
        def aux(i, j):

            if j == -1: return 1
            if i == -1: return 0 
            
            if s[i] == t[j]:
                return aux(i-1,j-1) + aux(i-1, j)
            else:
                return aux(i-1, j)
            
        return aux(len(s)-1, len(t)-1)

r/programmingcontests • • Sep 27 '22

Understanding base cases for distinct subsequence dynamic programming problem

2 Upvotes

I was trying out distinct subsequence problem:

Given two strings s and t, return the number of distinct subsequences of s which equals t. For example, if s = "rabbbit" and t = "rabbit", then the answer is 3 as there are 3 ways you can generate "rabbit" from s.

I tried following bottom up DP approach:

// bottom up - working
def numDistinct(self, s: str, t: str) -> int:
    
    @cache # (i,j): number of distinct subsequences in s[i:] that equal t[j:]
    def aux(i, j):            
        if j == len(t): return 1 
        if i == len(s): return 0 
        
        if s[i] == t[j]:
            return aux(i+1, j+1) + aux(i+1, j)
        else:
            return aux(i+1, j)
        
    return aux(0,0)

This gets accepted. I also tried follow top down DP solution:

// top down - not working
def numDistinct(self, s: str, t: str) -> int:

    @cache        
    def aux(i, j):
        
        if i == -1: return 0
        if j == -1: return 1
        
        if s[i] == t[j]:
            return aux(i-1,j-1) + aux(i-1, j)
        else:
            return aux(i-1, j)
        
    return aux(len(s)-1, len(t)-1)

It fails. For strings s = rabbbit and t = rabbit, it gives output = 0, when the output should be 3 (we can form bb in 3 ways from bbb).

I dry run top down approach and realized that I need extra check while returning value from first if:

Top down solution dry run image link

In above image, each node label is s<sub>i</sub>t<sub>j</sub>. Each edge label is ij. I realized:

  • for leaf (-1,-1), I should return 1 as it represents both s and t getting exhausted together.

  • for leaf (-1,0), I should return 0 as it represents s getting exhausted before t

So I changed the return value of first if a bit:

// top down - working
def numDistinct(self, s: str, t: str) -> int:

    @cache        
    def aux(i, j):
        
        if i == -1: return 1 if j == -1 else 0 # if s exhausts before t, return 0, else 1
        if j == -1: return 1
        
        if s[i] == t[j]:
            return aux(i-1,j-1) + aux(i-1, j)
        else:
            return aux(i-1, j)
        
    return aux(len(s)-1, len(t)-1)

And this solution gets accepted. Now I was guessing why such check (1 if j == -1 else 0) was not necessary in bottom up DP solution. I tried dry for bottom-up approach too:

Bottom up approach dry run image

And looking at leaves of above image, I feel here too I need similar check in first if. But then how bottom up approach is working without similar check in the first if's return value? What I am missing here?

In other words, how bottom up approach is working with if i==len(s): return 0 and does not need if i==len(s): return (1 if j==len(s) else 0)?


r/programmingcontests • • Feb 04 '22

Product of efforts of on/off leetcode after several years

2 Upvotes

Is competitive programming just... not for me?

I've had dividends doing this in solving many programs in my own time, but things that seem hard still feel daunting to me.

Maybe I just have to grit through it for a couple of years and it will get better? I never really tried doing like say a hard problem every day or anything. And I notice now that medium problems are significantly easier now than they were 4 years ago. But hard problems generally feel unsolvable for me still, even if I know what techniques I'll likely have to use.


r/programmingcontests • • Dec 19 '21

Programming challenges for randomization or approximation

2 Upvotes

Hello, I am looking for programming challenges related to randomization or approximation. Any practical coding-oriented problems are fine, Even if not exactly alike contests format.

After reading on randomized algorithms and math, I wish to get my hands dirty with coding.


r/programmingcontests • • Oct 26 '21

Starting with competitive programming

2 Upvotes

Hey, I'm trying to start a competitive programing club in my Uni and we're looking for resources to learn as we're all new to it, what books, pages or courses would you recommend for us to start with?

Thanks a lot, I hope we can be part of this wonderful community!


r/programmingcontests • • Oct 12 '21

Mental exercises to improve competitive programming skills?

2 Upvotes

I am a dev at a large tech company. I am trying to improve my cognition relating to my programming skills. This could include working memory, executive function etc. The problem is trying to find a way to improve these in a transferable way to programming. I was looking into Dual NBack, thinking it could help in keeping tack of complex pointer movements, though I am unconvinced it is transferable. What mental exercises , apps or programs can do daily that would help me improve?


r/programmingcontests • • Oct 11 '21

The Biggest Festival for Programmers is Back!

2 Upvotes

r/programmingcontests • • Aug 18 '21

Need help with a homework from my teacher.

2 Upvotes

This is the problem:

Given a MxN (M,N<=300) farm. To hydrate the farm, we have to replace dirt cells with water. A dirt cell is hydrated if there's at least one water cell share a same side with it.

We have to hydrate the entire farm. What is the maximum number of dirt cells remain?

Thanks.


r/programmingcontests • • Aug 04 '21

Should competitive programmers learn about Algorithms before training for competitive programming or the reverse?

2 Upvotes

Books like these don't seem to be detailed enough


r/programmingcontests • • Feb 28 '21

What Online Competitive Programming Platform Is The Best?

2 Upvotes

Here is the thing, I am looking for a competitive replacement to playing Apex Legends. I love competition and I love competition that I can participate in daily. I want to switch from Apex Legends to coding because I want a competitive outlet that will actually help me in the long run to be able to solve real world problems and prepare me for my career. (Unfortunately the skills from Apex are not as transferable as I would like them to be) However, I heard that some coding competitions are focused on obscure algorithms that may or may not help much in preparing for a career in software development or other related fields.

So does anyone know of an online competitive programming platform that offers daily real world challenges?


r/programmingcontests • • Feb 17 '21

Binary Search

2 Upvotes

Hey,

I made a tutorial about Binary Search check it out here: https://medium.com/@arisfotakis0/binary-search-beaaa4f4a7b4


r/programmingcontests • • Dec 15 '20

Any website like CTFtime but for competitive programming?

2 Upvotes

Basically what the title says.

I'm looking for a website that has upcoming contests, ongoing contests, etc.., maybe has a ranking system and such like ctf time


r/programmingcontests • • Oct 22 '20

I just wanted to ask you whether it makes a huge difference in using a slower langiuage like python in codejam/kickstart type competitions?? You sent about a minute ago Are the runtimes adjusted so that the slower languages also pass the test cases if the code has efficiency or do python programmer

2 Upvotes

I just wanted to ask you whether it makes a huge difference in using a slower langiuage like python in codejam/kickstart type competitions??You sent about a minute ago.Are the runtimes adjusted so that the slower languages also pass the test cases if the code has efficiency or do python programmers have a handicap here??


r/programmingcontests • • Sep 27 '20

Looking for someone to practice Competitive Programming with

2 Upvotes

Hey Guys!

So I am fairly new to CP but my interest has been growing exponentially in it. And I am now ready to go full force with it!

I am looking for a person who is interested in doing virtual contests (at least once a day) and create something like a study group. I live in the Middle East, so it would be preferable if he/she was living nearby. It doesn't matter the timezone as long as we manage to coordinate the time difference.

So excited!


r/programmingcontests • • Sep 19 '20

TCO Round 1A 500

Thumbnail
youtu.be
2 Upvotes

r/programmingcontests • • Aug 15 '20

Can anyone solve this problem!!

Post image
2 Upvotes

r/programmingcontests • • Jun 20 '20

Announcing 2nd edition fo 10 Days Challenge

Thumbnail
self.codepuzzle
2 Upvotes

r/programmingcontests • • Jun 20 '20

Hey everyone there is 10 days of easy challenge on codepuzzle.app to win 12 months of Laracast. Please check this out to get the details.

2 Upvotes

https://www.reddit.com/r/codepuzzle/comments/hcjao6/announcing_2nd_edition_fo_10_days_challenge/
We can win 99$ worth 12 months of laracasts subscription and learn full stack development and other interesting things. I found that we only have to play 5 puzzles in PHP everyday which is an easy task for 10 days.


r/programmingcontests • • May 25 '20

Hello. I would like to know the difference between these two programs.

2 Upvotes

The following programs aim to find the solution for this problem : https://atcoder.jp/contests/abc065/tasks/arc076_a

My program is not showing correct answers for test cases. So I wanted to know where I'm going wrong.

This is the program I wrote :

#include<iostream>

int modfact(int n, int p)

{

if (n >= p)

return 0;

int result = 1;

for (int i = 1; i <= n; i++)

result = (result * i) % p;

return result;

}

//--main function

int main(){

int n,m;

cin>>n>>m;

if(n==m){

	cout<<(modfact(n,1000000007)\*modfact(m,1000000007)\*2)%1000000007;

}

else if(n-m==1 || m-n==1){

	cout<<(modfact(n,1000000007)\*modfact(m,1000000007))%1000000007;

}

else cout<<0;



return 0;

}

This is a successful submission :

https://atcoder.jp/contests/abc065/submissions/6377519

I want to know what am I doing wrong. Specifically , my program doesn't work for Sample Input 4.


r/programmingcontests • • May 16 '20

Stem competitions and Internships?

2 Upvotes

Hi, I was wondering if anybody knows any good STEM and Technology competitions, as I am trying to improve my resume. Any suggestions would be extremely helpful! I am mostly looking for competitions that do with solutions in technology, and maybe some business aspects. If anyone knows any good STEM internships, scholarships or Coding summer camps that would be helpful as well. Thanks!


r/programmingcontests • • Sep 29 '19

VirtualCF- A codeforces parser for virtual contests and upsolving contests

2 Upvotes

I wrote a Codeforces parser called VirtualCF .

A Codeforces parser for a specific contest identified by Id. It can be used for uninterrupted and smooth participation in a virtual contest, upsolving a practice contest or even a live contest.

Have you ever thought of practicing a particular round - say Div3 and felt lazy about creating a proper directory structure for the contest, having proper files with the names of the problems?

Have you ever thought of getting a visual representation of the Accepted ratio of the problems in a CF contest before you virtually participate in it or even normally practice it?

If you have, then my python script is at your disposal. It will save you a huge amount of unnecessary time wasted.

Quora ans: https://qr.ae/TWsbvm

Youtube video: https://youtu.be/9UNwuovxQm4


r/programmingcontests • • Aug 05 '19

IP2Location Programming Contest 2019

Thumbnail
contest.ip2location.com
2 Upvotes