Possible reasons for time Limit exceeded

Source: Internet
Author: User

    • Today in doing POJ above a topic "MXN Puzzle", problem id:2893, test all passed, is prompted to time out, find the original source code comparison found on the Internet the same logic ... And then finally finally found the problem, in this article why does I get a time Limit exceeded? In the article mentions in C + +, do not use Cin/cout-use scanf and printf Inst EAD. Replace all cin,cout after accepted!
#include <iostream> #include <string.h>using namespace std; #define N 1000007int a[n];int B[n];long Long inv;/  /void merge (int first, int mid, int last) {int I, J, k;memcpy (b + First, A + first, (Last-first + 1) *sizeof (int)); k = i = First, J = mid + 1;while (I <= mid | | J <= last) {if ' (J > Last | | (i <= mid&&b[j] >= b[i])) {a[k++] = B[i++];inv + = (J-(Mid + 1));} else{a[k++] = B[j++];//inv + = ((mid + 1)-i) & 1;}}} void Msort (int first,int last) {if (first>=last) return;int mid = (first + last)/2;msort (first, mid); Msort (mid + 1, Las t); Merge (First, Mid, last);}  int main () {int m, n, S, J, Iter, V, y = 0;while (scanf ("%d%d", &m,&n) ==2) {if (!m | |!n) break;s = m * N;for (iter = j = 0; J < S; J + +) {scanf ("%d", &v); v? (a[iter++] = v): (y = m-1-j/n);} INV = 0;msort (0, iter-1);//cout << INV << endl;//If the number of columns is odd, the upper and lower left and right movements of the numbers do not affect the total number of final reverse pairs if (N & 1) {y = 0;} printf (((y% 2 = = Inv% 2)? "yes\n": "no\n");} System ("Pause");}


Possible reasons for time Limit exceeded

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.