QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420873 | #8678. A Recurring Problem | bulijiojiodibuliduo | AC ✓ | 18580ms | 549896kb | C++17 | 3.2kb | 2024-05-25 02:02:37 | 2024-05-25 02:02:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<ll> VI;
typedef basic_string<int> BI;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
//ll f[1111],ret,g[30][30][1111],tg[30][1111];
map<pair<VI,VI>,map<ll,ll>> hs;
map<ll,ll> count(VI s,VI coef) {
map<ll,ll> v;
if (s[0]==0) {
bool z=1;
for (auto x:s) z&=(x==0);
if (z) v[0]=1;
return v;
}
if (hs.count(mp(s,coef))) return hs[mp(s,coef)];
if (SZ(s)>=2) {
VI ss=s,cc=coef;
ss.pop_back(); cc.pop_back();
if (count(ss,cc).empty()) return v;
}
for (int j=1;j<=s[0];j++) for (int k=1;k*j<=s[0];k++) {
VI ncoef=coef,ns=s; ncoef.insert(ncoef.begin(),k);
bool val=1;
rep(l,0,SZ(s)) {
ns[l]=ns[l]-j*ncoef[l];
if (ns[l]<0) { val=0; break; }
}
ncoef.pop_back();
if (val) {
auto d=count(ns,ncoef);
for (auto [key,val]:d) v[key+j*coef.back()]+=val;
}
}
return hs[mp(s,coef)]=v;
}
vector<array<VI,3>> ret;
void dfs(VI s,VI coef,VI p1,VI p2) {
//printf("?? %lld %d\n",s[0],SZ(p1));
if (s[0]==0) {
bool z=1;
for (auto x:s) z&=(x==0);
if (z) {
reverse(all(p1));
reverse(all(p2));
int d=SZ(p2);
VI p3=p2;
while (1) {
__int128_t x=0;
rep(j,0,d) x+=(__int128_t)p1[j]*p3[SZ(p3)-d+j];
if (x>=(1ll<<62)||SZ(p3)>=100) break;
p3.pb(x);
}
p3=VI(p3.begin()+d,p3.end());
ret.pb({p3,p1,p2});
}
}
if (!hs.count(mp(s,coef))) return;
if (hs[mp(s,coef)].empty()) return;
//assert(hs.count(mp(s,coef)));
//if (count(s,coef).empty()) return;
for (int j=1;j<=s[0];j++) for (int k=1;k*j<=s[0];k++) {
VI ncoef=coef,ns=s; ncoef.insert(ncoef.begin(),k);
bool val=1;
rep(l,0,SZ(s)) {
ns[l]=ns[l]-j*ncoef[l];
if (ns[l]<0) { val=0; break; }
}
VI q1=p1,q2=p2; q1.pb(j); q2.pb(k);
ncoef.pop_back();
if (val) dfs(ns,ncoef,q1,q2);
}
}
int K;
VI seq;
int main() {
scanf("%d",&K);
rep(i,1,25) {
auto d=count(VI{i},VI{i});
ll z=0;
for (auto [key,val]:d) {
z+=val;
}
if (K>z) {
K-=z;
} else {
seq.pb(i);
break;
}
}
ll v=0;
rep(rd,1,10) {
auto d=count(seq,seq);
for (auto [key,val]:d) {
if (K>val) {
K-=val;
} else {
seq.pb(key);
fprintf(stderr,"%lld %lld\n",key,val);
v=val;
break;
}
}
if (v<=400000) break;
}
//printf("?? %d\n",SZ(seq));
count(seq,seq);
dfs(seq,seq,VI{},VI{});
assert(SZ(ret)==v);
sort(all(ret));
fprintf(stderr,"!! %d\n",K);
auto [p3,p1,p2]=ret[K-1];
printf("%d\n",SZ(p1));
p3.resize(10);
for (auto x:p1) printf("%lld ",x); puts("");
for (auto x:p2) printf("%lld ",x); puts("");
for (auto x:p3) printf("%lld ",x); puts("");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 337ms
memory: 16180kb
input:
810832525
output:
1 23 1 23 529 12167 279841 6436343 148035889 3404825447 78310985281 1801152661463 41426511213649
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3900kb
input:
1
output:
1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3868kb
input:
2
output:
1 1 2 2 2 2 2 2 2 2 2 2 2
result:
ok 4 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
4
output:
1 2 1 2 4 8 16 32 64 128 256 512 1024
result:
ok 4 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 4168kb
input:
5
output:
1 1 3 3 3 3 3 3 3 3 3 3 3
result:
ok 4 lines
Test #6:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
6
output:
2 1 1 2 1 3 4 7 11 18 29 47 76 123 199
result:
ok 4 lines
Test #7:
score: 0
Accepted
time: 1ms
memory: 4176kb
input:
7
output:
2 1 1 1 2 3 5 8 13 21 34 55 89 144 233
result:
ok 4 lines
Test #8:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
8
output:
3 1 1 1 1 1 1 3 5 9 17 31 57 105 193 355 653
result:
ok 4 lines
Test #9:
score: 0
Accepted
time: 1ms
memory: 3940kb
input:
9
output:
2 2 1 1 1 3 5 11 21 43 85 171 341 683 1365
result:
ok 4 lines
Test #10:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
10
output:
2 1 2 1 1 3 7 17 41 99 239 577 1393 3363 8119
result:
ok 4 lines
Test #11:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
11
output:
1 3 1 3 9 27 81 243 729 2187 6561 19683 59049
result:
ok 4 lines
Test #12:
score: 0
Accepted
time: 1ms
memory: 3952kb
input:
12
output:
1 1 4 4 4 4 4 4 4 4 4 4 4
result:
ok 4 lines
Test #13:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
13
output:
2 1 1 3 1 4 5 9 14 23 37 60 97 157 254
result:
ok 4 lines
Test #14:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
14
output:
2 1 1 2 2 4 6 10 16 26 42 68 110 178 288
result:
ok 4 lines
Test #15:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
15
output:
3 1 1 1 2 1 1 4 6 11 21 38 70 129 237 436 802
result:
ok 4 lines
Test #16:
score: 0
Accepted
time: 0ms
memory: 4168kb
input:
20
output:
3 2 1 1 1 1 1 4 7 13 28 55 109 220 439 877 1756
result:
ok 4 lines
Test #17:
score: 0
Accepted
time: 1ms
memory: 3908kb
input:
23
output:
1 2 2 4 8 16 32 64 128 256 512 1024 2048
result:
ok 4 lines
Test #18:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
24
output:
2 2 1 1 2 4 8 16 32 64 128 256 512 1024 2048
result:
ok 4 lines
Test #19:
score: 0
Accepted
time: 1ms
memory: 3872kb
input:
333
output:
4 2 2 1 1 1 1 2 1 7 14 27 57 126 265 559 1190 2531 5369
result:
ok 4 lines
Test #20:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
361
output:
2 1 2 1 3 7 17 41 99 239 577 1393 3363 8119 19601
result:
ok 4 lines
Test #21:
score: 0
Accepted
time: 1ms
memory: 4204kb
input:
362
output:
3 1 3 1 1 1 3 7 17 41 99 239 577 1393 3363 8119 19601
result:
ok 4 lines
Test #22:
score: 0
Accepted
time: 1ms
memory: 3928kb
input:
1000
output:
2 3 1 1 5 8 23 47 116 257 605 1376 3191 7319 16892
result:
ok 4 lines
Test #23:
score: 0
Accepted
time: 0ms
memory: 4256kb
input:
2488
output:
1 3 3 9 27 81 243 729 2187 6561 19683 59049 177147
result:
ok 4 lines
Test #24:
score: 0
Accepted
time: 1ms
memory: 3952kb
input:
2489
output:
2 3 2 1 3 9 27 81 243 729 2187 6561 19683 59049 177147
result:
ok 4 lines
Test #25:
score: 0
Accepted
time: 1ms
memory: 4044kb
input:
2490
output:
2 6 1 1 3 9 27 81 243 729 2187 6561 19683 59049 177147
result:
ok 4 lines
Test #26:
score: 0
Accepted
time: 4ms
memory: 5844kb
input:
9276
output:
10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 11 21 41 81 161 321 641 1281 2561 5120
result:
ok 4 lines
Test #27:
score: 0
Accepted
time: 8ms
memory: 5544kb
input:
9277
output:
10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 11 21 41 81 161 321 641 1281 2561 5121
result:
ok 4 lines
Test #28:
score: 0
Accepted
time: 8ms
memory: 5556kb
input:
9278
output:
11 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 21 41 81 161 321 641 1281 2561 5121
result:
ok 4 lines
Test #29:
score: 0
Accepted
time: 8ms
memory: 5524kb
input:
9279
output:
10 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 21 41 81 161 321 641 1281 2561 5121
result:
ok 4 lines
Test #30:
score: 0
Accepted
time: 8ms
memory: 5552kb
input:
9280
output:
10 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 21 41 81 161 321 641 1281 2561 5131
result:
ok 4 lines
Test #31:
score: 0
Accepted
time: 5ms
memory: 4924kb
input:
100000
output:
6 1 1 1 2 1 1 4 3 1 2 1 1 14 23 43 98 203 425 904 1899 3997 8430
result:
ok 4 lines
Test #32:
score: 0
Accepted
time: 274ms
memory: 57952kb
input:
1000000
output:
8 2 1 2 2 1 1 2 1 1 2 2 1 1 1 1 2 16 32 76 165 374 851 1940 4417 10068 22911
result:
ok 4 lines
Test #33:
score: 0
Accepted
time: 1355ms
memory: 116032kb
input:
37481721
output:
6 3 1 1 1 1 1 1 2 3 2 9 1 20 41 82 159 330 635 1307 2636 5313 10698
result:
ok 4 lines
Test #34:
score: 0
Accepted
time: 9ms
memory: 4984kb
input:
810832526
output:
1 1 24 24 24 24 24 24 24 24 24 24 24
result:
ok 4 lines
Test #35:
score: 0
Accepted
time: 7876ms
memory: 214436kb
input:
987654321
output:
12 1 1 2 2 2 1 1 1 1 1 1 1 1 5 1 1 2 1 1 1 2 3 1 1 24 47 89 176 352 704 1407 2812 5644 11332
result:
ok 4 lines
Test #36:
score: 0
Accepted
time: 6316ms
memory: 126268kb
input:
1000000000
output:
12 1 1 1 1 1 3 1 1 1 1 1 1 3 1 1 1 3 1 2 1 5 2 1 1 24 47 91 189 371 737 1473 2990 6025 12133
result:
ok 4 lines
Test #37:
score: 0
Accepted
time: 18580ms
memory: 549896kb
input:
419411797
output:
23 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 23 45 89 177 353 705 1409 2817 5633 11265
result:
ok 4 lines
Test #38:
score: 0
Accepted
time: 14047ms
memory: 342372kb
input:
929102292
output:
19 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 24 46 91 204 429 902 1916 4056 8584 18180
result:
ok 4 lines
Test #39:
score: 0
Accepted
time: 14010ms
memory: 342628kb
input:
929102293
output:
13 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 10 1 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #40:
score: 0
Accepted
time: 13404ms
memory: 342320kb
input:
929102680
output:
14 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 9 1 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #41:
score: 0
Accepted
time: 11614ms
memory: 342320kb
input:
929103060
output:
21 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #42:
score: 0
Accepted
time: 11493ms
memory: 342424kb
input:
929103061
output:
21 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #43:
score: 0
Accepted
time: 10709ms
memory: 342356kb
input:
929103062
output:
21 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #44:
score: 0
Accepted
time: 10744ms
memory: 342372kb
input:
929103063
output:
22 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #45:
score: 0
Accepted
time: 11483ms
memory: 342428kb
input:
929103064
output:
21 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #46:
score: 0
Accepted
time: 12027ms
memory: 342376kb
input:
929104472
output:
19 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #47:
score: 0
Accepted
time: 13169ms
memory: 342364kb
input:
929106014
output:
11 1 12 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 24 46 91 204 429 902 1916 4056 8584 18181
result:
ok 4 lines
Test #48:
score: 0
Accepted
time: 13169ms
memory: 342612kb
input:
929106015
output:
19 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 24 46 91 204 429 902 1916 4056 8584 18182
result:
ok 4 lines
Test #49:
score: 0
Accepted
time: 262ms
memory: 15916kb
input:
810832522
output:
3 1 1 21 1 1 1 23 485 10209 214897 4523531 95219257 2004342825 42190942113 888109346455 18694491560493
result:
ok 4 lines
Test #50:
score: 0
Accepted
time: 277ms
memory: 16164kb
input:
810832000
output:
5 1 3 2 1 15 1 1 1 2 1 23 354 5342 80535 1214145 18304479 275958780 4160361416 62721711948 945594085778
result:
ok 4 lines
Extra Test:
score: 0
Extra Test Passed