QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#283868 | #7881. Computational Complexity | Iris | TL | 199ms | 160460kb | C++20 | 2.2kb | 2023-12-15 17:11:02 | 2023-12-15 17:11:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long long mx=10000000ll,inf=100000000ll;
long long x,y,z,n,m,f[10000011],g[10000011],ansx,ansy,sx[4011],sy[4011],p[4011][11];
vector<long long> vec;
void solve(){
if(z<=mx){
ansx=f[z];
ansy=g[z];
return;
}
long long c=vec.size()-1ll;
while((z/vec[c])<=mx)c--;
for(int i=c,s;i>=0;i--){
sx[i]=0ll;
sy[i]=0ll;
s=z/vec[i];
if(p[i][2]<=c){
sx[i]=sx[i]+sy[p[i][2]];
sy[i]=sy[i]+sx[p[i][2]];
}else{
sx[i]=sx[i]+g[s>>1];
sy[i]=sy[i]+f[s>>1];
}
if(p[i][3]<=c){
sx[i]=sx[i]+sy[p[i][3]];
sy[i]=sy[i]+sx[p[i][3]];
}else{
sx[i]=sx[i]+g[s/3ll];
sy[i]=sy[i]+f[s/3ll];
}
if(p[i][5]<=c){
sx[i]=sx[i]+sy[p[i][5]];
sy[i]=sy[i]+sx[p[i][5]];
}else{
sx[i]=sx[i]+g[s/5ll];
sy[i]=sy[i]+f[s/5ll];
}
if(p[i][4]<=c){
sy[i]=sy[i]+sx[p[i][4]];
}else{
sy[i]=sy[i]+f[s>>2];
}
if(p[i][7]<=c){
sx[i]=sx[i]+sy[p[i][7]];
}else{
sx[i]=sx[i]+g[s/7ll];
}
while(sx[i]>=m)sx[i]=sx[i]-m;
while(sy[i]>=m)sy[i]=sy[i]-m;
}
ansx=sx[0ll];
ansy=sy[0ll];
}
int main(){
for(long long i=1ll;i<=inf;i=i*2ll){
for(long long j=i;j<=inf;j=j*3ll){
for(long long a=j;a<=inf;a=a*5ll){
for(long long b=a;b<=inf;b=b*7ll){
vec.push_back(b);
}
}
}
}
sort(vec.begin(),vec.end());
for(long long i=0ll;i<vec.size();i++){
p[i][2]=mx;
p[i][3]=mx;
p[i][4]=mx;
p[i][5]=mx;
p[i][7]=mx;
for(long long j=i+1ll;j<vec.size();j++){
if(vec[j]==vec[i]*2ll)p[i][2]=j;
if(vec[j]==vec[i]*3ll)p[i][3]=j;
if(vec[j]==vec[i]*4ll)p[i][4]=j;
if(vec[j]==vec[i]*5ll)p[i][5]=j;
if(vec[j]==vec[i]*7ll)p[i][7]=j;
}
}
scanf("%lld%lld%lld%lld",&x,&y,&n,&m);
f[0]=x;
g[0]=y;
for(int i=1;i<=100;i++){
f[i]=max(1ll*i,g[i/2]+g[i/3]+g[i/5]+g[i/7]);
g[i]=max(1ll*i,f[i/2]+f[i/3]+f[i/4]+f[i/5]);
}
for(int i=0;i<=100;i++){
f[i]=f[i]%m;
g[i]=g[i]%m;
}
for(int i=101;i<=mx;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];
while(f[i]>=m)f[i]=f[i]-m;
while(g[i]>=m)g[i]=g[i]-m;
}
while(n){
n--;
scanf("%lld",&z);
solve();
printf("%lld %lld\n",ansx,ansy);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 28ms
memory: 160340kb
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: 48ms
memory: 160356kb
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: 0
Accepted
time: 36ms
memory: 160460kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 20 numbers
Test #4:
score: 0
Accepted
time: 103ms
memory: 160316kb
input:
36092 30559 2149 729566623185 909730017626 961811467628 978809456383 494310140318 760462959632 726343527430 220697276132 366336227300 456813204361 569783542145 13854148170 51526515764 564416233246 876430686824 862897449267 956440673661 512777546436 728860125927 799238602356 978766770799 47962348351 ...
output:
192287632545 510282654057 513694515018 658644741565 90751152870 6088748556 138070013247 301112114677 224113421002 105290451187 630454127249 196841848259 546918129568 526274849982 226761501362 157889210040 135623074930 620463814922 78467045157 602244472172 51639549042 411354142414 329188915935 306494...
result:
ok 4298 numbers
Test #5:
score: 0
Accepted
time: 199ms
memory: 160244kb
input:
46012 72474 6895 931299293479 635558333906 151352929427 186830308154 201652909474 130684521091 862625793178 335372663856 565394770762 609752364488 636658378167 568072145317 23602174799 74849827839 567735061723 964475612065 721588322843 526921882143 141483206690 794896616456 923141155683 443983986019...
output:
737640936783 269480550026 785950579990 586907405473 274405996613 356240054012 164145774405 803378519477 613956922400 426121843045 509646717167 788278629379 95131481441 672600899832 720839818877 52329269906 131977527669 257593035330 737640936783 269480550026 202443098753 171133839273 188615102144 605...
result:
ok 13790 numbers
Test #6:
score: -100
Time Limit Exceeded
input:
4625 65696 87448 104757899185 324541097749 340894391228 353710640194 913290645927 500906082550 994613091630 486893604015 755863379632 795242109754 670982629049 89739557323 995677833835 622128974870 291590021762 74643709454 491030939322 504220665415 590951839890 749414110824 908656060298 831415689095...
output:
24017028596 61020984279 90036018081 8518714361 4807132724 94915889679 60642395760 99169995073 45912197521 30663794937 26807208137 73005099296 31855861883 38442189712 61377861921 69296474844 15633158436 24561226404 83188091024 101278210525 92283972576 51782451279 22904017080 27746280119 46615471334 7...