QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#876191 | #7704. Plus Minus Four Squares | Teapot# | AC ✓ | 92ms | 3712kb | C++20 | 2.8kb | 2025-01-30 18:12:14 | 2025-01-30 18:12:14 |
Judging History
answer
/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double ld;
typedef __int128_t ill;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll n;
cin >> n;
ll a=0,b=0,c=0,d=0;
ll res = 0;
vector<ll> r(4);
while(a*a <= n)
{
b = 0;
while(b <= a)
{
c = 0;
while(c <= b)
{
d = 0;
while(d <= c)
{
FOR(i,0,16)
{
FOR(j,0,4)
if((i & (1 << j)) > 0)
r[j] = 1;
else
r[j] = -1;
if(a == b && (r[0] != r[1]))
continue;
if(c == b && (r[2] != r[1]))
continue;
if(c == d && (r[3] != r[2]))
continue;
if(a == 0 & r[0] == -1)
continue;
if(b == 0 & r[1] == -1)
continue;
if(c == 0 & r[2] == -1)
continue;
if(d == 0 & r[3] == -1)
continue;
if(r[0] == -1)
continue;
ll cur = r[0] * a*a + r[1] * b*b + r[2] * c*c + r[3] * d*d;
if(cur == n){
//cerr << r[0] << ' ' << a*a <<' ' << r[1] << ' ' << b*b << ' ' << r[2] << ' ' << c*c <<' '<< r[3] << ' ' << d*d << endl;
res++;
}
}
d++;
}
c++;
}
b++;
}
a++;
}
cout << res;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
input:
64
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
65
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 15ms
memory: 3584kb
input:
2023
output:
245
result:
ok single line: '245'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 92ms
memory: 3712kb
input:
5000
output:
951
result:
ok single line: '951'
Test #6:
score: 0
Accepted
time: 4ms
memory: 3456kb
input:
1024
output:
182
result:
ok single line: '182'
Test #7:
score: 0
Accepted
time: 17ms
memory: 3712kb
input:
2048
output:
355
result:
ok single line: '355'
Test #8:
score: 0
Accepted
time: 66ms
memory: 3584kb
input:
4096
output:
708
result:
ok single line: '708'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
2
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 6ms
memory: 3584kb
input:
1111
output:
131
result:
ok single line: '131'