Safe Robots wrong answer (SAFEROBO)

Can someone please help me why my question is returning the wrong answer on submitting the answer. while testing with sample input it is working as expected.

Thanks in advance.

/* package codechef; // don’t place package name! */

import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef {
	public static void main(String[] args) throws java.lang.Exception {

		Scanner scanner = new Scanner(System.in);
		int inputLength = 0;
		if (scanner.hasNext()) {
			inputLength = scanner.nextInt();
		}

		while (inputLength-- > 0) {
			int sa = 0;
			int sb = 0;
			int emptyCells = 0;
			if (scanner.hasNext()) {
				if (scanner.hasNext()) {
					emptyCells = scanner.next().length() - 2;
				}
				if (scanner.hasNext()) {
					sa = scanner.nextInt();
				}
				if (scanner.hasNext()) {
					sb = scanner.nextInt();
				}

				int saInc = 1;
				int sbInc = emptyCells;
				boolean unsafe = false;
				for (int i = 0; i < emptyCells; i++) {
					saInc += sa;
					sbInc -= sb;
					if (saInc == sbInc) {
						System.out.println("unsafe");
						unsafe = true;
					}
				}

				if (!unsafe) {
					System.out.println("safe");

				}
			}
		}

	}
}

Please either format your code or link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Edit:

Some obvious errors:

Your program’s output has to match the expected output exactly - so

  • Don’t print out the unexpected output "inputLength " + inputLength
  • The words you should be printing out are safe and unsafe (the output checker is case-sensitive).

Hi,
Thanks for helping me.
I have edited the code, still getting the wrong answer.

I am new to codechef, how to figure out the error without seeing the exception log.
Appreciating your suggestions.

I think you’ve misread the Problem :slight_smile:

Consider the testcase:

1
.......A...B....
1 Like

You know honestly I wonder how you have so much time to patiently help so many people, you’re amazing man. How do you manage to do it?
Cases where stuff fails ,
“format your code” should be your catchphrase :joy:
Logic explanation
Well documented codes.
Pseudo-admin xD
Great stuff :slight_smile:

2 Likes

Thanks for the kind words - I don’t really have anything better to do at the moment XD

I should probably get off my @$$ and get a job in the New Year, at which point my contributions will probably drop off a lot :slight_smile:

4 Likes

It shouldn’t be hard for you to get a job man.
You have insane coding skills + ( I stalked you on LinkedIn (ouch) , goddamn makes me feel like a kid,you have insane experience)
After all the work you’ve done, what motivates you to keep pushing forward ?
And the first thing you felt while seeking a job?

4 Likes

Stop, you’re making me blush XD

Yeah, the job market is very hot here in the UK - I’ve never been even the slightest bit worried about finding a job :slight_smile:

I just love programming - I don’t think I’ll ever tire of it :slight_smile:

4 Likes

Thank you so much for your guidance, appreciating your help.

2 Likes

@ssjgz Hat’s off for the effort and hard work you do to improve the community and guide others. :hearts:

@vijju123 Give him goodies. :stuck_out_tongue:

2 Likes

this worked!!!