QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#808624 | #79. Fabricating Sculptures | LaVuna47 | TL | 396ms | 11556kb | C++17 | 2.4kb | 2024-12-10 22:27:26 | 2024-12-10 22:27:27 |
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 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
ll f(int p, int st, int prev, bool inc)
{
if(p==0)
{
if(st==0) return 1;
return 0;
}
ll res=0;
if(inc)
{
for(int i=0;st-prev-i>=0;++i)
res += f(p-1, st-prev-i, prev+i, inc);
for(int i=prev-1;i >= 0;--i)
res += f(p-1, st-i, i, false);
}
else
{
for(int i=prev;i >= 0;--i)
res += f(p-1, st-i, i, false);
}
return res;
}
#define MAX_N 501
ll dp[2][MAX_N][MAX_N][2];
int solve()
{
int n,m;
if(!(cin>>n>>m))
return 1;
m-=n;
FOR(i,0,MAX_N)FOR(j,0,2)dp[0][0][i][j]=1;
FOR(p,0,n)
{
RFOR(st,MAX_N,0)
{
FOR(prev,0,MAX_N)
{
ll res=0;
for(int i=0;st-prev-i>=0 && prev+i<MAX_N;++i)
res += dp[p&1][st-prev-i][prev+i][true];
for(int i=0;i <= prev-1 && i <= st;++i)
res += dp[p&1][st-i][i][false];
dp[(p+1)&1][st][prev][true]=res;
}
FOR(prev,0,MAX_N)
{
ll res=0;
for(int i=0;i <= prev && st-i >= 0; ++i)
res += dp[p&1][st-i][i][false];
dp[(p+1)&1][st][prev][false]=res;
}
}
}
cout<<dp[n&1][m][0][true]<<'\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cout << "__________________________" << endl;
#endif
}
#ifdef ONPC
cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 213ms
memory: 11536kb
input:
3 6
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 137ms
memory: 11492kb
input:
2 3
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 208ms
memory: 11532kb
input:
3 5
output:
5
result:
ok single line: '5'
Test #4:
score: 0
Accepted
time: 269ms
memory: 11484kb
input:
4 6
output:
7
result:
ok single line: '7'
Test #5:
score: 0
Accepted
time: 336ms
memory: 11472kb
input:
5 7
output:
9
result:
ok single line: '9'
Test #6:
score: 0
Accepted
time: 389ms
memory: 11468kb
input:
6 8
output:
11
result:
ok single line: '11'
Test #7:
score: 0
Accepted
time: 396ms
memory: 11548kb
input:
6 9
output:
20
result:
ok single line: '20'
Test #8:
score: 0
Accepted
time: 267ms
memory: 11556kb
input:
4 10
output:
42
result:
ok single line: '42'
Test #9:
score: -100
Time Limit Exceeded
input:
2505 5000