Page 3 of 3

Re: 11571 - Simple Equations - Extreme!!

Posted: Sat Sep 17, 2016 7:52 am
by zeyadetman
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?

Re: 11571 - Simple Equations - Extreme!!

Posted: Fri Mar 10, 2017 4:00 pm
by lighted
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.