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

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

Re: 11571 - Simple Equations - Extreme!!

Post by zeyadetman »

here's my code

Code: Select all

using namespace std;
typedef long double ll;
int main(){
    //freopen("FighterAttack.txt", "r", stdin);
    //freopen("FighterShow.txt", "w", stdout);
    ll A,B,C,n;
        ll minx=6000000000000,miny=600000000000,minz=0;
        bool flag=false;
        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;} }
            cout<<minx<<" "<<miny<<" "<<minz<<endl;
            cout<<"No solution.\n";
    return 0;
Why i get TimeLimit Error?
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 11571 - Simple Equations - Extreme!!

Post 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.
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)”