Блог пользователя accidentallygivenfuck

Автор accidentallygivenfuck, 11 лет назад, По-английски

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.

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
11 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Try to use scanf() instead of cin.

  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    (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. :(

  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      11 лет назад, # ^ |
      Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

      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.

      • »
        »
        »
        »
        11 лет назад, # ^ |
          Проголосовать: нравится +1 Проголосовать: не нравится

        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?

»
11 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

My AC solution just uses scanf.

»
11 лет назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

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 :)