QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#321655 | #7704. Plus Minus Four Squares | ishmeal# | AC ✓ | 16ms | 3684kb | C++23 | 445b | 2024-02-05 04:10:59 | 2024-02-05 04:11:00 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
int n;
int ans;
void dfs(int sum, int i, int last) {
if (i == 4) {
ans += sum == n;
return;
}
if (!last) return dfs(sum, i+1, 0);
int s = -last+1, e = last;
if (last < 0) s = last, e = -last-1;
while (s <= e) {
dfs(sum + s*abs(s), i+1, s);
s++;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for (int i = 0; i*i <= n; i++) dfs(i*i, 1, i);
cout << ans << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3600kb
input:
64
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
65
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3564kb
input:
2023
output:
245
result:
ok single line: '245'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 16ms
memory: 3568kb
input:
5000
output:
951
result:
ok single line: '951'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
1024
output:
182
result:
ok single line: '182'
Test #7:
score: 0
Accepted
time: 3ms
memory: 3608kb
input:
2048
output:
355
result:
ok single line: '355'
Test #8:
score: 0
Accepted
time: 12ms
memory: 3548kb
input:
4096
output:
708
result:
ok single line: '708'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
2
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
4
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
3
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
1111
output:
131
result:
ok single line: '131'