QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#277944 | #7881. Computational Complexity | zhouhuanyi | WA | 72ms | 15276kb | C++20 | 2.6kb | 2023-12-07 09:40:26 | 2023-12-07 09:40:27 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#define N 21
#define M 1000000
using namespace std;
const long long inf=(long long)(1e15);
long long read()
{
char c=0;
long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct reads
{
long long num;
int type;
bool operator < (const reads &t)const
{
return num!=t.num?num<t.num:type<t.type;
}
};
set<reads>s;
map<reads,long long>dp;
struct rds
{
long long num,data;
bool operator < (const rds &t)const
{
return num<t.num;
}
};
rds tong[M+1],tong2[M+1];
int T,length,length2;
long long f[N+1],g[N+1],delta[M+1],delta2[M+1],mod;
reads operator * (reads a,int d)
{
return (reads){a.num*d,a.type^1};
}
long long MD(long long x)
{
return x>=mod?x-mod:x;
}
void Adder(long long &x,long long d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void bfs()
{
reads top;
set<reads>s;
for (int i=0;i<=20;++i)
{
if (f[i]!=(i?f[i-1]:0)) dp[(reads){i,0}]=(f[i]-(i?f[i-1]:0))%mod,s.insert((reads){i,0});
if (g[i]!=(i?g[i-1]:0)) dp[(reads){i,1}]=(g[i]-(i?g[i-1]:0))%mod,s.insert((reads){i,1});
}
while (!s.empty())
{
top=(*s.begin()),s.erase(s.begin());
if (!top.type) tong[++length]=(rds){top.num,dp[top]};
else tong2[++length2]=(rds){top.num,dp[top]};
if (!top.type)
{
if ((top*2).num>=21&&(top*2).num<=inf) Adder(dp[top*2],dp[top]),s.insert(top*2);
if ((top*3).num>=21&&(top*3).num<=inf) Adder(dp[top*3],dp[top]),s.insert(top*3);
if ((top*4).num>=21&&(top*4).num<=inf) Adder(dp[top*4],dp[top]),s.insert(top*4);
if ((top*5).num>=21&&(top*5).num<=inf) Adder(dp[top*5],dp[top]),s.insert(top*5);
}
else
{
if ((top*2).num>=21&&(top*2).num<=inf) Adder(dp[top*2],dp[top]),s.insert(top*2);
if ((top*3).num>=21&&(top*3).num<=inf) Adder(dp[top*3],dp[top]),s.insert(top*3);
if ((top*5).num>=21&&(top*5).num<=inf) Adder(dp[top*5],dp[top]),s.insert(top*5);
if ((top*7).num>=21&&(top*7).num<=inf) Adder(dp[top*7],dp[top]),s.insert(top*7);
}
}
return;
}
int main()
{
long long x;
f[0]=read(),g[0]=read(),T=read(),mod=read();
for (int i=1;i<=21;++i) f[i]=max((long long)(i),g[i/2]+g[i/3]+g[i/5]+g[i/7]),g[i]=max((long long)(i),f[i/2]+f[i/3]+f[i/4]+f[i/5]);
bfs();
for (int i=1;i<=length;++i) delta[i]=MD(delta[i-1]+tong[i].data);
for (int i=1;i<=length2;++i) delta2[i]=MD(delta2[i-1]+tong2[i].data);
for (int i=1;i<=T;++i) x=read(),printf("%lld %lld\n",delta[lower_bound(tong+1,tong+length+1,(rds){x+1,0})-tong-1],delta2[lower_bound(tong2+1,tong2+length2+1,(rds){x+1,0})-tong2-1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 56ms
memory: 15084kb
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: 52ms
memory: 13284kb
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: 44ms
memory: 15276kb
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: 57ms
memory: 15180kb
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: 52ms
memory: 13232kb
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
Wrong Answer
time: 72ms
memory: 12968kb
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:
-8566130704574 -13347990111401 -13947522472709 -16438471457684 -13613719761326 -17609169072586 -153200164111895 -161542268447382 -38190721005004 -46377085544018 -177014042414513 -184719929063044 -38519051038197 -46578822947613 -102915637036934 -114954876830286 -114379992751584 -125999191493151 -8686...
result:
wrong answer 1st numbers differ - expected: '24017028596', found: '-8566130704574'