Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:53:38+00:00 2026-06-13T06:53:38+00:00

What are tips and tricks so that my code can be executed in the

  • 0

What are tips and tricks so that my code can be executed in the given time limit? Maybe some logical changes or anything.

When I submit my solution in CodeChef it shows time limit exceeded, but I think it is fast enough simple code. How could it be executed within the time limit, i.e. 3 seconds?

Code

long int iv, aia[1000][1000];
long int imax = 0;
long int score(int ia, int ib);

int main() {

    int ii, ij;
    long int iut, ivt, ie;

    memset(aia, 0, 1000000);

    scanf("%d %d", &iv, &ie);

    if((iv <= 1000) && (iv >= 2)) {

        if((ie >= (iv-1)) && (ie <= ( (iv*(iv-1)) / 2) )) {

            for(ii = 0; ii<ie; ii++) {

                scanf("%d%d", &iut, &ivt);

                if((iut >= 0) && (ivt <= (iv -1))) {

                    scanf("%d", &aia[iut][ivt]);

                    if(aia[iut][ivt] < 0) {

                        return 1;
                    }

                    aia[ivt][iut] = aia[iut][ivt];
                }
                else {

                    return 1;
                }
            }

            for(ii = 0; ii<iv; ii++) {

                for(ij = 0; ij<iv; ij++) {

                   printf("%d ", score(ii, ij));
                   imax = 0;
                }

                printf("\n");
            }
        }
    }
    return 0;
}


long int score(int ia, int ib) {

    int ii;
    int long imaxt = 0;

    if(ia == ib) {

        return 0;
    }

    if(aia[ia][ib] != 0) {

        imax = aia[ia][ib];
    }

    for(ii = 0; ii<iv; ii++) {

        if((ii != ib) && (ii != ia)) {

            if(aia[ia][ii] != 0) {

                if(aia[ii][ib] != 0) {

                    imaxt = (aia[ia][ii] < aia[ii][ib]) ? aia[ia][ii] : aia[ii][ib];

                    if(imaxt > imax) {

                        imax = imaxt;
                    }
                }
            }
        }
    }
    return imax;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:53:40+00:00Added an answer on June 13, 2026 at 6:53 am

    My advice to you is to run your code through a profiler. I personally prefer Valgrind.

    Then when you find the bottleneck, you could have a go at it or post it here instead of the long listing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any tips tricks , techniques, configurations to improve rendering time of sifr3-r436
Coming from PHP with some Java Struts 2.0 experience any tips/tricks on learning GWT?
I am using this code from css tips and tricks to cover a background
What are some tips one can keep in mind to speed up jSoup? I
In Vim and ctags tips and tricks , there are some mappings like: map
Possible Duplicates: Is there a site that emails out daily C# tips and tricks?
I am wondering if there are any tips or tricks to converting perl into
Please give me some tips for this case. I have an iPhone APP which
I'm currently working on some .Net based software (.Net Framework 3.5 SP1) that integrates
I have created an ios application that can talk to the database and get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.