/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 12ms 532.0 KiB
#3 Accepted 12ms 340.0 KiB
#4 Accepted 9ms 372.0 KiB
#5 Accepted 16ms 612.0 KiB
#6 Accepted 1ms 532.0 KiB
#7 Accepted 1ms 380.0 KiB
#8 Accepted 1ms 484.0 KiB
#9 Accepted 40ms 536.0 KiB
#10 Accepted 40ms 532.0 KiB
#11 Accepted 1ms 564.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

bool sq(long long hysq)
{
    return(ceil(sqrt(hysq))==floor(sqrt(hysq)));
}

void sir(long long b)
{
    long long hi, hysq;
    long long max_peri = -1;
    long long n = floor((b*b)/2)+5;
    for(hi=n; hi>=1; hi--)
    {
        long long hysq = hi*hi + b*b;

        if (sq(hysq)) {
            long long peri = hi + b + sqrt(hysq);
            max_peri = max(max_peri, peri);
        }
    }
    if(max_peri != -1)
    {
        cout<<max_peri<<endl;
    }
    else{cout<<"-1"<<endl;}

}
int main()
{
    long long t;
    cin>>t;
    while(t--)
    {   
        long long b;
        cin>>b;
        sir(b);
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1027 Right triangle
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-12 10:33:20
Judged At
2024-11-11 03:40:57
Judged By
Score
100
Total Time
40ms
Peak Memory
612.0 KiB