QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#714584#7704. Plus Minus Four Squaresrand123WA 1ms3800kbC++142.7kb2024-11-06 00:39:562024-11-06 00:39:57

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 00:39:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3800kb
  • [2024-11-06 00:39:56]
  • 提交

answer

#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define yes "YES"
#define no "NO"
#define ll long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define MOD2 998244353
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(int cas){
    ll n;
    cin>>n;
    ll res = 0;
    for (int i = 0; i<=(int)sqrt(n); i++){
        for (int sub = 0; sub < i; sub++){
            for (int add = 0; add < sub; add++){
                ll curr = i*i - sub*sub + add*add;
                if (curr < n){
                    ll diff = abs(n - curr);
                    ll sq = sqrtl(diff);
                    if (sq*sq==diff && sq <= add) res++;
                }
                else{
                    ll diff = abs(n - curr);
                    ll sq = sqrtl(diff);
                    if (sq*sq==diff && sq < add) res++;
                }
            }
            for (int sub2 = 0; sub2 <= sub; sub2++){
                ll curr = i*i - sub2*sub2 - sub*sub;
                if (curr < n){
                    ll diff = abs(n - curr);
                    ll sq = sqrtl(diff);
                    if (sq*sq==diff && sq < sub2) res++;
                }
                else{
                    ll diff = abs(n - curr);
                    ll sq = sqrtl(diff);
                    if (sq*sq==diff && sq <= sub2) res++;
                }
            }
        }
        for (int add = 0; add <= i; add++){
            for (int add2 = 0; add2 <= add; add2++){
                ll curr = i*i + add*add + add2*add2;
                if (curr < n){
                    ll diff = abs(n - curr);
                    ll sq = sqrtl(diff);
                    if (sq*sq==diff && sq <= add2) res++;
                }
                else{
                    ll diff = abs(n - curr);
                    ll sq = sqrtl(diff);
                    if (sq*sq==diff && sq < add2) res++;
                }
            }
            for (int sub2 = 0; sub2 < add; sub2++){
                ll curr = i*i - sub2*sub2 + add*add;
                if (curr < n){
                    ll diff = abs(n - curr);
                    ll sq = sqrtl(diff);
                    if (sq*sq==diff && sq < sub2) res++;
                }
                else{
                    ll diff = abs(n - curr);
                    ll sq = sqrtl(diff);
                    if (sq*sq==diff && sq <= sub2) res++;
                }
            }
        }
    }
    cout<<res<<'\n';
}
int main(){
    int t=1;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //cin>>t;
    for (int i = 1; i<=t; i++){
        solve(i);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

input:

64

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

65

output:

10

result:

ok single line: '10'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3792kb

input:

2023

output:

245

result:

ok single line: '245'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3800kb

input:

0

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'