Comments

You may follow SecondThread on his youtube channel. Just make sure to use fast io in java rest everything will be fine.

Yes in my current template I use PrintWriter only.

Yes I noticed it after a while. Thanks but can you please elaborate on what is the problem with BufferedWriter?

No one is asking you to use java knucklehead Ninja :p

On akash_kumar123 → Red and Green Balls, 6 years ago
0

Yes you are right, should have though about it. Good one mate!

If all the numbers are 1 then both can win depending upon the value of n. And also why are you xoring p-1? You should xor p instead.

Is it giving wrong answer or syntax error? You should remove the first line : package a; as it causes syntax error when file is not present in that directory.

My username is not even in the list. #unworthy :p

On __goku__ → Help needed in DP + 2D BIT, 6 years ago
+1

Thanks!! Will look into it.

On __goku__ → Help needed in DP + 2D BIT, 6 years ago
0

No One?

Yes they can divide it in a way like division 3 are based on IOI style and div2/1 competitions are based on ICPC style. Codechef Cook-Offs are held in ICPC style where as Lunchtime are held in IOI style.

Do we still have a 6 minute window between downloading test case then submitting our program?

Says a "Probably" fake id.

On akash_kumar123 → Red and Green Balls, 6 years ago
0

This is my program. It got accepted. ~~~~~

import java.io.*;
import java.util.*;
class code {
  public static void main(String[] args) throws Exception {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int ar[]=new int[n];
    for(int x=0;x<n;x++)
    {
        String s=sc.next();
        int p=-1;
        for(int y=0;y<n;y++)
        {
            if(s.charAt(y)=='R')
            {
                p=y;
            }
        }
        ar[x]=p;
    }
    int ans=0;
    for(int x=0;x<n;x++)
    {
        for(int y=0;y<n-1;y++)
        {
            if(ar[y]>ar[y+1])
            {
                ans++;
                int t=ar[y];
                ar[y]=ar[y+1];
                ar[y+1]=t;
            }
        }
    }
    boolean found=true;
    for(int x=0;x<n;x++)
    {
        if(ar[x]>x)        
        {
            found=false;
            break;
        }
    }
    System.out.println(found?ans:-1);
  }
}

~~~~~

On akash_kumar123 → Red and Green Balls, 6 years ago
0

Last index of occurrence of 'R' in each row. For example, for input such as:

R
GR
GRR
RGRG
GRGGG

we will store values as {0,1,2,2,1} now we will perform bubble sort on this array to count number of swaps. The idea of bubble sort comes from "swap adjacent rows".

On akash_kumar123 → Red and Green Balls, 6 years ago
0

Just store the last index in every row in an array and perform bubble sort on the array and count number of swaps. If after sorting value of index is greater than index then output -1 otherwise number of swaps.

In such tight time limit you may use ArrayList instead of array because Collections.sort() is faster than Arrays.sort() or if you want to stick with array then use Arrays.parallelSort()

https://medium.com/@ssrivastava990/a-java-template-for-competitive-coding-b810fbda77c9

Here you can see. In some cases BufferedReader is slower and in even more extreme cases PrintWriter is slow. We have to use BufferedWriter in those cases.

You are wrong here. ArrayList is actually faster than int[] when it is implemented properly. Specially Collections.sort() is much faster than Arrays.sort(). And in my second implementation I have used TreeMap in which we have to implement Comparator for generic type.

Yeah I have mentioned about TreeMap in the post as well. I made a function because sometimes we need a basic function only. And its not about C++ to Java, most of the time editorials are in C++ so some java users get confused sometimes about how a predefined function works.

+10

Yes we all do :(

On __goku__ → Favorite programming meme!, 6 years ago
0

Great... and thanks!

On ritikagupta8734 → Div3 Contest 997, 6 years ago
0

Yes because recursion makes the program slow.

On ritikagupta8734 → Div3 Contest 997, 6 years ago
0

Try implementing dfs using iteration.

On ritikagupta8734 → Div3 Contest 997, 6 years ago
0

Try this.

There is a limit to number of recursive calls in languages like python and java. We can manually change it.

Can you be a little more specific with your question.

lol do you mean karan the great? :p

No idea.

I don't think you can do anything now. Take care in next contest!

Keep your code private from next time or it will better if you use offline ide.

Maybe someone copied you code then. Did you write your code on online ide like ideone?

Yup that maybe the reason why ArrayList worked then.

Thanks, till now I believed that sort function worked upon merge sort but I was wrong. Now the random ordering make sense.

Can you please tell why did that work?

Auto comment: topic has been updated by __goku__ (previous revision, new revision, compare).

Auto comment: topic has been updated by __goku__ (previous revision, new revision, compare).

Yup. And then 2 codeforces round + lunchtime this week!!

Hey thanks, I have used StringTokenizer before but it was slow at times. I generally use BufferedReader and BufferedWriter only but at one instance they didn't won thats why I had to use this. And thanks for the advice of PrintWriter I will definitely look into it.