QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646671 | #7704. Plus Minus Four Squares | zeyu# | AC ✓ | 341ms | 32940kb | C++23 | 2.4kb | 2024-10-17 02:58:58 | 2024-10-17 02:58:59 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pl pair<ll, ll>
#define pi pair<int, int>
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;
#if 1
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "]";}
void _print() {cerr << endl << flush;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "*["<<__LINE__<<"]\t"<< #x << " = "; _print(x)
#endif
const ll mod = 1e9 + 7;
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll gcd(ll a, ll b) {if(b == 0){return a;} return gcd(b, a % b);}
int dp[10010][75][5][2];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n; int m = ceil(sqrt(n));
for (int i = 0; i <= m; i ++) if (i * i <= n) dp[i * i][i][1][0] = 1;
for (int k = 2; k <= 4; k ++){
for (int i = 0; i <= 2 * n; i ++){
for (int prv = 0; prv <= m; prv ++){
for (int cur = 0; cur <= prv; cur ++){
if (i >= cur * cur) dp[i][cur][k][0] += dp[i - cur * cur][prv][k - 1][0];
if (i >= cur * cur && prv != cur) dp[i][cur][k][0] += dp[i - cur * cur][prv][k - 1][1];
if (cur != 0){
if (i + cur * cur <= 2 * n) dp[i][cur][k][1] += dp[i + cur * cur][prv][k - 1][1];
if (i + cur * cur <= 2 * n && prv != cur) dp[i][cur][k][1] += dp[i + cur * cur][prv][k - 1][0];
}
}
}
}
}
int ans = 0; for (int i = 0; i <= m; i ++) for (int j = 0; j < 2; j ++) ans += dp[n][i][4][j];
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4028kb
input:
64
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4152kb
input:
65
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 54ms
memory: 15568kb
input:
2023
output:
245
result:
ok single line: '245'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 341ms
memory: 32940kb
input:
5000
output:
951
result:
ok single line: '951'
Test #6:
score: 0
Accepted
time: 13ms
memory: 9732kb
input:
1024
output:
182
result:
ok single line: '182'
Test #7:
score: 0
Accepted
time: 52ms
memory: 15612kb
input:
2048
output:
355
result:
ok single line: '355'
Test #8:
score: 0
Accepted
time: 220ms
memory: 27524kb
input:
4096
output:
708
result:
ok single line: '708'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
2
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
4
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
3
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 13ms
memory: 10152kb
input:
1111
output:
131
result:
ok single line: '131'