QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#697113 | #7704. Plus Minus Four Squares | BackToSquare1 | AC ✓ | 17ms | 3704kb | C++20 | 2.2kb | 2024-11-01 10:41:30 | 2024-11-01 10:41:30 |
Judging History
answer
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef pair<ld,ld> pd;
typedef vector<ll> vl;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define G(x) ll x; cin >> x;
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define all(a) begin(a), end(a)
#define K first
#define V second
#define OK(i,j) i >= 0 && i < n && j >= 0 && j < m
#define NN 2000005
#define MM 5005
#define MOD 1000000007
ll count(ll a, ll b, ll c, ll d, ll target) {
ll num = 0;
for(ll sgna = 1; sgna <= 1; sgna += 2) {
ll aa = sgna*a;
for(ll sgnb = -1; sgnb <= 1; sgnb += 2) {
if(a == b) sgnb = sgna;
ll bb = sgnb*b;
for(ll sgnc = -1; sgnc <= 1; sgnc += 2) {
if(b == c) sgnc = sgnb;
ll cc = sgnc*c;
for(ll sgnd = -1; sgnd <= 1; sgnd += 2) {
if(c == d) sgnd = sgnc;
ll dd = sgnd*d;
if(aa + bb + cc + dd == target) {
num++;
// cout << aa << ' ' << bb << ' ' << cc << ' ' << dd << '\n';
}
if(c == d || d == 0) break;
}
if(b == c || c == 0) break;
}
if(a == b || b == 0) break;
}
if(a == 0) break;
}
return num;
}
void solve() {
ll n;
cin >> n;
if(n == 0) {
cout << 1 << '\n';
return;
}
ll c = 1;
while(c*c <= n) c++;
c--;
ll ans = 0;
for(ll i1=0; i1 <= c; i1++) {
for(ll i2=0; i2 <= i1; i2++) {
for(ll i3=0; i3 <= i2; i3++) {
for(ll i4=0; i4<= i3; i4++) {
ans += count(i1*i1,i2*i2,i3*i3,i4*i4,n);
}
}
}
}
cout << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
// G(t);
// while(t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
64
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
65
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3612kb
input:
2023
output:
245
result:
ok single line: '245'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 17ms
memory: 3584kb
input:
5000
output:
951
result:
ok single line: '951'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
1024
output:
182
result:
ok single line: '182'
Test #7:
score: 0
Accepted
time: 3ms
memory: 3652kb
input:
2048
output:
355
result:
ok single line: '355'
Test #8:
score: 0
Accepted
time: 13ms
memory: 3592kb
input:
4096
output:
708
result:
ok single line: '708'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
2
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
4
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
1111
output:
131
result:
ok single line: '131'