QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#277942 | #7881. Computational Complexity | zhouhuanyi | WA | 60ms | 9820kb | C++20 | 2.6kb | 2023-12-07 09:39:38 | 2023-12-07 09:39:39 |
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),s.insert((reads){i,0});
if (g[i]!=(i?g[i-1]:0)) dp[(reads){i,1}]=g[i]-(i?g[i-1]:0),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: 53ms
memory: 9820kb
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: 60ms
memory: 9764kb
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: 53ms
memory: 9764kb
input:
2023 2023 10 2023 0 1 2 3 4 5 6 7 8 9
output:
0 0 4046 4046 8092 8092 12138 12138 16184 22253 20230 26299 30345 36414 34391 36414 44506 46529 48552 50575
result:
wrong answer 3rd numbers differ - expected: '0', found: '4046'