QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#420863 | #8678. A Recurring Problem | bulijiojiodibuliduo | WA | 18636ms | 380700kb | C++17 | 2.8kb | 2024-05-25 01:28:30 | 2024-05-25 01:28:30 |
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<pair<VI,VI>> ret;
void dfs(VI s,VI coef,VI p1,VI p2) {
if (s[0]==0) {
bool z=1;
for (auto x:s) z&=(x==0);
if (z) {
reverse(all(p1));
reverse(all(p2));
ret.pb(mp(p1,p2));
}
}
if (SZ(s)>=2) {
VI ss=s,cc=coef;
ss.pop_back(); cc.pop_back();
if (count(ss,cc).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;
}
}
}
dfs(seq,seq,VI{},VI{});
assert(SZ(ret)==v);
sort(all(ret));
fprintf(stderr,"!! %d\n",K);
auto [p1,p2]=ret[K-1];
printf("%d\n",SZ(p1));
for (auto x:p1) printf("%lld ",x); puts("");
for (auto x:p2) printf("%lld ",x); puts("");
for (auto x:seq) printf("%lld ",x); puts("");
}
詳細信息
Test #1:
score: 100
Accepted
time: 238ms
memory: 15844kb
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: 0ms
memory: 4132kb
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: 0ms
memory: 3784kb
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: 0ms
memory: 3836kb
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: 0ms
memory: 3860kb
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: 0ms
memory: 3928kb
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: 0ms
memory: 3912kb
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: 4148kb
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: 0ms
memory: 3848kb
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: 0ms
memory: 4148kb
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: 0ms
memory: 4104kb
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: 0ms
memory: 3788kb
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: 0ms
memory: 3848kb
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: 0ms
memory: 3824kb
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: 3856kb
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: 3856kb
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: 0ms
memory: 4148kb
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: 0ms
memory: 4136kb
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: 3896kb
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: 3948kb
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: 3964kb
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: 3896kb
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: 3936kb
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: 3936kb
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: 8ms
memory: 5032kb
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: 4712kb
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: 4684kb
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: 7ms
memory: 4776kb
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: 3ms
memory: 4996kb
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: 4288kb
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: 52ms
memory: 7680kb
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: 575ms
memory: 24048kb
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: 10ms
memory: 4732kb
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: 4042ms
memory: 92868kb
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: 4000ms
memory: 103144kb
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: -100
Wrong Answer
time: 18636ms
memory: 380700kb
input:
419411797
output:
21 1 1 1 1 1 1 1 1 1 1 3 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:
wrong answer 1st lines differ - expected: '23', found: '21'