11571 - Simple Equations - Extreme!!

All about problems in Volume 115. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

zeyadetman
New poster
Posts: 1
Joined: Sat Sep 17, 2016 7:29 am

Re: 11571 - Simple Equations - Extreme!!

Post by zeyadetman » Sat Sep 17, 2016 7:52 am

here's my code

Code: Select all

#include<bits/stdc++.h>
using namespace std;
typedef long double ll;
int main(){
    //freopen("FighterAttack.txt", "r", stdin);
    //freopen("FighterShow.txt", "w", stdout);
    ll A,B,C,n;
    cin>>n;
    while(n--)
    {
        ll minx=6000000000000,miny=600000000000,minz=0;
        bool flag=false;
        cin>>A>>B>>C;
        for(ll x=0; x<=100000 ; x++)if(x*x<=C && ceil(B/x)==floor(B/x)){
            for(ll y=0; y<=1000000; y++)if(x!=y && x*x+y*y<=C && ceil(B/y)==floor(B/y)){
                ll z = A-(x+y);
                if(x+y+z==A && x*y*z==B && x*x+y*y+z*z==C && x!=y && x!=z && y!=z){
                    if(x<minx){minx=x; miny=y; minz=z; flag=true;}
                    else if(x==minx){ if(y<miny){minx=x; miny=y; minz=z;} }
                }
            }
        }
        if(flag)
            cout<<minx<<" "<<miny<<" "<<minz<<endl;
        else
            cout<<"No solution.\n";
    }
    return 0;
}
Why i get TimeLimit Error?

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11571 - Simple Equations - Extreme!!

Post by lighted » Fri Mar 10, 2017 4:00 pm

I fixed bug in my code, so it passes all 249 cases in brianfry713's input. Accepted in 0.0 s. :D

Brute force method certainly will give time limit exceeded. Read this thread to optimize your code.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 115 (11500-11599)”

Who is online

Users browsing this forum: No registered users and 1 guest