accidentallygivenfuck's blog

By accidentallygivenfuck, 10 years ago, In English

Hi all,
I've been trying to solve this problem at TOJ.
I am recieving TLE for following simple code (I just scan input):

#include <iostream>
#include <algorithm>
using namespace std;

int m, n, res;
int b[500];
int r[500];

int main()
{
	while (true) {
		cin >> m;
		cin >> n;
		
		if (m == 0 && n == 0)
			break;
		
		for (int i = 0; i < m; i++)
			cin >> b[i];
		
		for (int i = 0; i < n; i++)
			cin >> r[i];
	}
	
	return 0;
}

If any of you is familiar with (have been solving problems for long time) TOJ, please tell me what is wrong.

»
10 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Try to use scanf() instead of cin.

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    (As I thought) No, it didn't help. Actually if I print something, then verdict is Output Limit Exceeded. I think there is a problem in testdata. :(

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    But if there is problem in testdata, then how 66 people got AC?! :(

    • »
      »
      »
      10 years ago, # ^ |
      Rev. 3   Vote: I like it +1 Vote: I do not like it

      Are you sure you have to input from console?

      Well FAQ says stdio but who knows?:D (also notice "Multiple test files" on the problem's page)

      BTW, 10 million numbers are too much. Also try to input using following technique:

      cin.read(big_buffer, size);

      It helps sometimes.

      • »
        »
        »
        »
        10 years ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        Multiple test files = multiple test cases in one input. Many online judges put that note somewhere. If the output was to a file, the filename would be specified.

        Where are you getting 10 million numbers from?

»
10 years ago, # |
  Vote: I like it +1 Vote: I do not like it

My AC solution just uses scanf.

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you please send your code to me? I just want to experiment on it.

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      Here is my code. I did something strange to check if gcd of 2 numbers is greater than 1 and I don't remember why (I solved this problem more than year ago).

      • »
        »
        »
        »
        10 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Thanks for your code. Reason you check if gcd is greater than 1 is, you can pair cards only if gcd > 1.

        • »
          »
          »
          »
          »
          10 years ago, # ^ |
            Vote: I like it +1 Vote: I do not like it

          I know that, I just did it in a strange way.

»
10 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Thanks to everbody, especially Fcdkbear.
I spent a day (yesterday) to find out why I was recieving TLE for such simple code. Here is what had happened:

  • I clicked to "Connect" to connect to internet and it connects in 2-3 seconds.
  • Then immediately I clicked "Submit" in problem page.
  • As I was not connected to internet the moment I clicked to "Submit", Firefox opened a cached page http://acm.tju.edu.cn/toj/submit.html where problem field didnt contain correct problem id. (not 3783 but 2823).
  • And all day I used that submit page which contained wrong problem id to submit my codes.
  • It turned out that I was submitting my code to wrong problem.

Yeah, such things happen in life, and you can just live this moments :)