QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#328364#7881. Computational Complexity11d10xyWA 118ms30568kbC++141.2kb2024-02-15 19:34:512024-02-15 19:34:51

Judging History

你现在查看的是最新测评结果

  • [2024-02-15 19:34:51]
  • 评测
  • 测评结果:WA
  • 用时:118ms
  • 内存:30568kb
  • [2024-02-15 19:34:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64=long long;
constexpr i64 N=1000000000000000ll;
i64 f[20],g[20],mod;
map<i64,i64>df,dg,vf,vg;
basic_string<i64>v{1,2,3,4,5,6,7,8,9,10,11,12,13};
int main(){
   for(int p:{2,3,5,7}){
      basic_string<i64>v1;
      for(i64 x=p;x<=N;x*=p)for(i64 u:v)if(u*x>N)break;else v1+=u*x;
      v+=v1,sort(begin(v),end(v));
      v.erase(unique(begin(v),end(v)),end(v));
   }int T;
   cin>>f[0]>>g[0]>>T>>mod;
   for(int i=1;i<=13;i++)
   f[i]=max((i64)i,g[i/2]+g[i/3]+g[i/5]+g[i/7]),
   g[i]=max((i64)i,f[i/2]+f[i/3]+f[i/4]+f[i/5]);
   i64 sf=0,sg=0;
   for(i64 w:v){
      if(w<=13)vf[w]=sf=f[w],vg[w]=sg=g[w],df[w]=f[w]-f[w-1],dg[w]=g[w]-g[w-1];
      else{
         i64 x=(w%2==0)*dg[w/2]+(w%3==0)*dg[w/3]+(w%5==0)*dg[w/5]+(w%7==0)*dg[w/7],
             y=(w%2==0)*df[w/2]+(w%3==0)*df[w/3]+(w%4==0)*df[w/4]+(w%5==0)*df[w/5];
         df[w]=x,dg[w]=y,vf[w]=sf+=x,vg[w]=sg+=y;
      }vf[w]%=mod,vg[w]%=mod,df[w]%=mod,dg[w]%=mod;
   }
   for(;T--;){
      i64 m;scanf("%lld",&m);
      if(!m){printf("%lld %lld\n",f[0],g[0]);continue;}
      printf("%lld %lld\n",prev(vf.upper_bound(m))->second,prev(vg.upper_bound(m))->second);
   }
   return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 118ms
memory: 30508kb

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: 115ms
memory: 30440kb

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: 107ms
memory: 30568kb

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'