QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#647206 | #7704. Plus Minus Four Squares | enze114514 | AC ✓ | 1ms | 3772kb | C++20 | 1.7kb | 2024-10-17 12:40:16 | 2024-10-17 12:40:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
const ld pi = 3.14159265358979323846;
const ll INF = 1e18;
template<typename T>
T chmax(T a, T b) {
return a > b ? a : b;
}
template<typename T>
T chmin(T a, T b) {
return a > b ? b : a;
}
void solve() {
int n;
cin >> n;
int mx = sqrt(n);
int ans{};
for (int a = 0; a <= mx; a++) {
int a2 = a * a, aneg = (a < 0 ? -1 : 1);
for (int b = -abs(a); b <= abs(a); b++) {
int b2 = b * b, bneg = (b < 0 ? -1 : 1);
if (abs(a) == abs(b) && a != b) continue;
for (int c = -abs(b); c <= abs(b); c++) {
int c2 = c * c, cneg = (c < 0 ? -1 : 1);
if (abs(c) == abs(b) && b != c) continue;
int d2 = n - (a2 * aneg + b2 * bneg + c2 * cneg);
int dneg = (d2 < 0 ? -1 : 1);
int d = sqrt(abs(d2));
if (d * d != abs(d2)) continue;
if (d > abs(c)) continue;
if (abs(d2) == c2 && (d2 < 0 != c < 0)) continue;
int test = a2 * aneg + b2 * bneg + c2 * cneg + d * d * dneg;
if (test != n || b2 > a2 || c2 > b2 || d * d > c2 ||
(a2 == b2 && aneg != bneg) || (b2 == c2 && bneg != cneg) || (c2 == d * d && cneg != dneg)) {
cout << "bad" << '\n';
}
ans++;
}
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
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: 3668kb
input:
65
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
2023
output:
245
result:
ok single line: '245'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
5000
output:
951
result:
ok single line: '951'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
1024
output:
182
result:
ok single line: '182'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
2048
output:
355
result:
ok single line: '355'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
4096
output:
708
result:
ok single line: '708'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
2
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
4
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
3
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
1111
output:
131
result:
ok single line: '131'