|
|
вернуться в форумWhy TLE # 9?????? The code is very simple! Please check my code: #include <iostream> #include <cmath> using namespace std; double y(double x, double z){ double h =( 1 - 2*x + sqrt(4*x*x-4*x+1+8*z) )/2; if(h-floor(h) == 0) return h; else return -1; } int main(){ unsigned z; cin>>z; for(unsigned x=1; x<=z; x++) if(y(x, z)!=-1){ cout<<x<<" "<<y(x, z); break; } return 0; } Re: Why TLE # 9?????? The code is very simple! I think you have TLE because of for(unsigned x=1; x<=z; x++) Where Z can be about 10^9... Are you sure it will finish some day? Re: Why TLE # 9?????? The code is very simple! It works rather fast. When z == 1000000000 we have "26263 25600". And what are your variants to make this program faster? Re: Why TLE # 9?????? The code is very simple! 1) Bad (for your solution) test: 12224444 (run time is about 2 sec) 2) Hint: N >= P(P-1)/2 => P is not more than 50000 |
|
|