You are not logged in. Please login at to post your questions!


[closed] Help me in TWONUM

Hey Guys,I am getting TLE on a very basic and simple problem(feel bad for that)...I've tried the same logic of the code cramped into the main method hopin it would run faster but it took even more. The Problem TWONUMS. The original constraints are 1 sec and 50k bytes and the testcases are upto 100.

And somehow my code executes at 0.11 millisec at its best, and considering the codechef stress test(that is it will run the maximum number of testcases)..if i could reduce the execution time to 0.1 it would work. And i couldnt figure what i can possibly reduce with the code. Please do comment on my Coding prefrences or in anyway i could improve. Any critics are highly encouraged.

import java.util.Scanner;

class Operations extends Game { //int num_alice,num_bob,turns; int result;

void getData()
    int num_alice = sc_ops.nextInt();
    int num_bob = sc_ops.nextInt();
    int turns = sc_ops.nextInt();

void gameplay(int num_alice,int num_bob,int turns)
    for(int i=1;i<=turns;i++)

void result(int num_alice,int num_bob)
    result=(num_alice>num_bob)? (num_alice/num_bob):(num_bob/num_alice);


class Game { static Scanner sc_ops= new Scanner(; public static void main(String[] args) {
Operations obj = new Operations(); int cases = sc_ops.nextInt();





asked 17 Jul '17, 14:58

stabcode_77's gravatar image

accept rate: 12%

closed 18 Jul '17, 00:12

vijju123's gravatar image

5★vijju123 ♦♦

also i have tried most trivial changes as well..still it runs at 0.11 millisec at best!

(17 Jul '17, 15:01) stabcode_771★

Looking at your profile, it appears that you've found out how to solve this problem. So this thread can be closed now.

(17 Jul '17, 23:30) c_utkarsh5★

Ya, actually vijju helped me ...which basically meant to change my code's time from O(n) to O(1)...and the same thing helped me in another problem. Lesson Learnt! :) thanks vijju

(20 Jul '17, 22:11) stabcode_771★

The question has been closed for the following reason "Other" by vijju123 18 Jul '17, 00:12

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 17 Jul '17, 14:58

question was seen: 257 times

last updated: 20 Jul '17, 22:11