QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#273044 | #7881. Computational Complexity | ucup-team191# | WA | 46ms | 159884kb | C++14 | 2.7kb | 2023-12-02 20:59:31 | 2023-12-02 20:59:33 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using pii=pair<int,int>;
#define pb push_back
#define all(a) begin(a),end(a)
const char en='\n';
const ll MAXN=1e15,T=1e7,V=MAXN/T;
ll m,f[T+10],g[T+10],dp1[10000],dp2[10000];
int t;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>f[0]>>g[0]>>t>>m;
for (int i=1;i<=100;++i)
{
f[i]=max(i*1ll,g[i/2]+g[i/3]+g[i/5]+g[i/7]);
g[i]=max(i*1ll,f[i/2]+f[i/3]+f[i/4]+f[i/5]);
}
for (int i=1;i<=100;++i) f[i]%=m,g[i]%=m;
for (int i=101;i<=T;++i)
{
f[i]=g[i/2]+g[i/3]+g[i/5]+g[i/7];
g[i]=f[i/2]+f[i/3]+f[i/4]+f[i/5];
if (f[i]>=2*m) f[i]-=2*m;
if (f[i]>=m) f[i]-=m;
if (g[i]>=2*m) g[i]-=2*m;
if (g[i]>=m) g[i]-=m;
}
vi s2357;
s2357.pb(1);
while (1)
{
vi nov;
for (auto x: s2357)
{
nov.pb(x);
if (x*2<=V) nov.pb(x*2);
if (x*3<=V) nov.pb(x*3);
if (x*5<=V) nov.pb(x*5);
if (x*7<=V) nov.pb(x*7);
}
sort(all(nov));
nov.erase(unique(all(nov)),nov.end());
if (nov==s2357) break;
s2357=nov;
}
vi nov;
for (auto x: s2357)
{
nov.pb(x);
nov.pb(x*2);
nov.pb(x*3);
nov.pb(x*4);
nov.pb(x*5);
nov.pb(x*7);
}
sort(all(nov));
nov.erase(unique(all(nov)),nov.end());
vector<array<int,5>> tra;
array<int,5> um={2,3,4,5,7};
for (int i=0;i<(int)s2357.size();++i)
{
array<int,5> re;
for (int j=0;j<5;++j)
{
re[j]=lower_bound(all(nov),s2357[i]*um[j])-nov.begin();
}
tra.pb(re);
}
int sm=s2357.size(),sn=nov.size();
while (t--)
{
ll n;
cin>>n;
if (n<=T)
{
cout<<f[n]<<' '<<g[n]<<en;
continue;
}
int i;
if (n<=V*300)
{
for (i=0;i<(int)s2357.size() && n/s2357[i]>T;++i)
{
for (int j=0;j<5;++j)
{
if (n/(um[j]*s2357[i])<=T)
{
dp1[tra[i][j]]=f[n/(um[j]*s2357[i])];
dp2[tra[i][j]]=g[n/(um[j]*s2357[i])];
}
}
}
for (--i;i>=0;--i)
{
dp1[i]=dp2[tra[i][0]]+dp2[tra[i][1]]+dp2[tra[i][3]]+dp2[tra[i][4]];
dp2[i]=dp1[tra[i][0]]+dp1[tra[i][1]]+dp1[tra[i][2]]+dp1[tra[i][3]];
if (dp1[i]>=2*m) dp1[i]-=2*m;
if (dp1[i]>=m) dp1[i]-=m;
if (dp2[i]>=2*m) dp2[i]-=2*m;
if (dp2[i]>=m) dp2[i]-=m;
}
}
else
{
for (int i=sm;i<sn;++i)
{
dp1[i]=f[n/nov[i]];
dp2[i]=g[n/nov[i]];
}
for (int i=sm-1;i>=0;--i)
{
dp1[i]=dp2[tra[i][0]]+dp2[tra[i][1]]+dp2[tra[i][3]]+dp2[tra[i][4]];
dp2[i]=dp1[tra[i][0]]+dp1[tra[i][1]]+dp1[tra[i][2]]+dp1[tra[i][3]];
if (dp1[i]>=2*m) dp1[i]-=2*m;
if (dp1[i]>=m) dp1[i]-=m;
if (dp2[i]>=2*m) dp2[i]-=2*m;
if (dp2[i]>=m) dp2[i]-=m;
}
}
cout<<dp1[0]<<' '<<dp2[0]<<en;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 40ms
memory: 159824kb
input:
1958 920 10 100000000000 0 1 2 3 10 100 200 1000 19580920 20232023
output:
1958 920 3680 7832 10592 9554 17504 11276 50294 64826 784112 893714 1894550 1905470 12057866 12979424 71481494756 48626708512 28127864908 7251681354
result:
ok 20 numbers
Test #2:
score: 0
Accepted
time: 35ms
memory: 159848kb
input:
0 0 10 100000000000 0 1 2 3 4 10 20 30 40 100
output:
0 0 1 1 2 2 3 3 4 4 11 12 25 26 41 41 55 58 162 172
result:
ok 20 numbers
Test #3:
score: -100
Wrong Answer
time: 46ms
memory: 159884kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
2023 2023 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st numbers differ - expected: '0', found: '2023'