QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#19718 | #1840. K-onstruction | yuyue | AC ✓ | 827ms | 119036kb | C++17 | 3.1kb | 2022-02-08 21:32:19 | 2022-05-06 06:48:06 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
//#define mp make_pair
//#define OO(x) fixed<<setprecision(x)
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int read(){
char ch=getchar(); int w=1,c=0;
for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
return w*c;
}
int k,A,B;
void check(vector<LL> s,bool fl){
int ret=0; A=0; B=0;
F(i,0,(1<<s.size())-1){
LL t=0;
F(j,0,SZ(s)){
if (i>>j&1){
t+=s[j];
}
}
if (t==0) ret++;
if (t==-1) B++;
}
A=ret;
if (fl) cerr<<ret<<" subsets\n";
}
vector<LL> h[200][200];
void dfs(int dep,int la,int sm,vector<LL> s){
if (sm>=0){
check(s,0);
if (!h[A][B].size()) h[A][B]=s;
else{
if (s.size()<h[A][B].size()) h[A][B]=s;
}
}
else{
if (la<=0) return ;
}
// cerr<<dep<<" "<<s.size()<<" "<<la<<" "<<sm<<"\n";
if (dep==10) return ;
DF(i,la,-5){
if (!i) continue;
vector<LL> t=s; t.pb(i);
dfs(dep+1,i,sm+i,t);
}
}
const int M=1e6+10;
vector<LL> ans,s[M];
int dis[M],fr[M];
bool in[M];
int q[M*10];
void dij(){
int lim=1000000;
F(i,1,lim) dis[i]=lim;
dis[1]=1; in[1]=1; int l=1,r=1; q[1]=1;
while (l<=r){
int x=q[l++]; in[x]=0;
F(i,2,56){
F(j,0,64){
if (x*i+j>lim) break;
if (h[i][j].size() && x*i+j<=lim && dis[x*i+j]>dis[x]+h[i][j].size()){
dis[x*i+j]=dis[x]+h[i][j].size();
fr[x*i+j]=x;
s[x*i+j]=h[i][j];
// if (x*i+j==120){
// cerr<<i<<" "<<j<<"???\n";
// }
if (!in[x*i+j]){
in[x*i+j]=1;
q[++r]=x*i+j;
}
}
}
}
}
cerr<<r<<"\n";
F(i,1,lim){
// cerr<<i<<" "<<dis[i]<<"\n";
if (dis[i]>30){
cerr<<i<<" "<<dis[i]<<"\n";
break;
}
}
}
LL ps;
void con(int x){
if (x==1){
ans.pb(1); ps++;
return ;
}
con(fr[x]);
LL ad=0;
for (LL o:s[x]){
ans.pb(o*ps);
if (o>0) ad+=o;
}
ps+=ad*ps;
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
dfs(1,5,0,{});
cerr<<" finish \n";
dij();
// F(i,0,7){
// cerr<<h[8][i].size()<<"\n";
// }
// return 0;
int T=read();
while (T--){
ans.clear(); ps=0;
k=read();
con(k);
cout<<ans.size()<<"\n";
for (LL x:ans){
cout<<x<<" ";
}
cout<<"\n";
}
// check(ans,1);
return 0;
if (k==1){
cout<<"1 1\n";
return 0;
}
int hi=0;
DF(i,30,0){
if (k>>i&1){
hi=i;
break;
}
}
ans.pb(1);
LL pos=1;
check(ans,1);
DF(i,hi-1,0){
if (k>>i&1){
ans.pb(pos);
// ans.pb(2*pos);
ans.pb(-pos);
pos+=pos;
}
else{
ans.pb(pos*2);
// ans.pb(pos*4);
ans.pb(-pos*2);
pos+=2*pos;
}
}
// check(ans);
cerr<<ans.size()<<"\n";
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 827ms
memory: 118848kb
input:
2 3 16
output:
3 1 1 -1 7 1 5 5 4 -1 -5 -5
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 782ms
memory: 118836kb
input:
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
1 1 3 1 5 -5 3 1 1 -1 4 1 2 -1 -1 5 1 5 4 -1 -5 5 1 5 5 -1 -5 5 1 2 1 -1 -1 6 1 3 3 -2 -2 -2 6 1 5 5 -1 -1 -5 5 1 1 1 -1 -1 6 1 3 1 -1 -1 -1 6 1 2 2 -1 -1 -2 7 1 3 3 3 -2 -2 -2 7 1 5 3 2 -3 -3 -3 6 1 2 1 -1 -1 -1 7 1 5 5 4 -1 -5 -5 7 1 3 3 1 -2 -2 -2 7 1 3 2 1 -2 -2 -2 8 1 5 5 2 2 ...
result:
ok correct (1000 test cases)
Test #3:
score: 0
Accepted
time: 821ms
memory: 118968kb
input:
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 ...
output:
15 1 5 5 4 -1 -1 -4 -5 15 15 15 15 -15 -15 -15 15 1 1 1 1 -1 -1 -1 12 12 12 -4 -4 -4 -4 -12 15 1 1 1 1 -1 -1 -1 20 16 4 -4 -4 -4 -12 -16 15 1 3 1 -1 -1 -1 -1 10 10 10 -5 -5 -5 -5 -5 15 1 1 1 1 -1 -1 -1 20 8 8 -4 -4 -4 -4 -20 15 1 1 1 1 -1 -1 -1 16 16 4 -4 -4 -8 -8 -8 15 1 1 1 1 -1 -1 -1 16 12 ...
result:
ok correct (1000 test cases)
Test #4:
score: 0
Accepted
time: 773ms
memory: 118976kb
input:
1000 993583 891827 976796 828946 983149 933824 989543 985227 981826 917123 995813 961139 945833 875509 983784 994507 998827 941562 865682 996623 971299 953499 918651 971707 966313 980053 996657 976037 870307 935389 927903 998826 923969 987837 905739 996643 979733 952467 881278 929789 956447 976709 9...
output:
29 1 2 2 -1 -1 -1 -1 5 5 5 -5 -5 -5 20 20 20 20 -20 -20 -20 500 500 -100 -100 -100 -100 -100 -200 -200 29 1 1 1 1 -1 -1 -1 16 16 -8 -8 -8 -8 180 180 180 180 -180 -180 -180 3780 3024 1512 1512 1512 -1512 -1512 -1512 -3780 29 1 1 1 -1 -1 6 3 3 3 -3 -3 -3 -3 90 72 -18 -18 -18 -18 -18 -36 -36 360 180 ...
result:
ok correct (1000 test cases)
Test #5:
score: 0
Accepted
time: 798ms
memory: 118920kb
input:
1000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 ...
output:
20 1 2 1 1 -1 -1 -1 -1 5 5 -5 45 45 45 15 -15 -15 -15 -15 -30 19 1 2 2 -1 -1 -1 -1 5 5 -5 -5 30 15 15 15 -15 -15 -15 -15 20 1 2 2 -1 -1 -1 -1 5 5 -5 -5 45 30 30 30 15 -15 -15 -30 -30 19 1 2 2 2 1 -1 -1 -2 -2 40 40 40 -40 -40 -40 128 128 -128 -128 20 1 2 2 -1 -1 -1 -1 5 5 -5 -5 45 45 45 30 -15 -3...
result:
ok correct (1000 test cases)
Test #6:
score: 0
Accepted
time: 805ms
memory: 118828kb
input:
1000 99001 99002 99003 99004 99005 99006 99007 99008 99009 99010 99011 99012 99013 99014 99015 99016 99017 99018 99019 99020 99021 99022 99023 99024 99025 99026 99027 99028 99029 99030 99031 99032 99033 99034 99035 99036 99037 99038 99039 99040 99041 99042 99043 99044 99045 99046 99047 99048 99049 9...
output:
24 1 5 3 3 2 -3 -3 -3 -3 14 14 14 14 14 -14 -14 -14 84 84 84 84 -84 -84 -84 25 1 1 1 1 -1 -1 -1 20 8 4 -4 -4 -4 -4 -4 -8 144 108 72 36 -36 -36 -72 -72 -72 25 1 1 1 1 -1 -1 -1 20 16 4 -4 -4 -4 -4 -12 -12 176 132 132 -44 -44 -44 -44 -88 -132 25 1 1 1 1 -1 -1 -1 20 8 4 -4 -4 -4 -4 -4 -8 144 108 72 3...
result:
ok correct (1000 test cases)
Test #7:
score: 0
Accepted
time: 767ms
memory: 119036kb
input:
1000 998001 998002 998003 998004 998005 998006 998007 998008 998009 998010 998011 998012 998013 998014 998015 998016 998017 998018 998019 998020 998021 998022 998023 998024 998025 998026 998027 998028 998029 998030 998031 998032 998033 998034 998035 998036 998037 998038 998039 998040 998041 998042 9...
output:
29 1 1 -1 4 4 2 -2 -2 -2 -2 -2 12 12 12 12 12 -12 -12 -12 144 144 144 -72 -72 -72 -72 -144 504 -504 30 1 1 1 1 -1 -1 -1 12 4 4 -4 -4 -4 -4 -4 120 72 72 -72 -72 -120 1440 864 864 864 576 -576 -864 -864 -864 30 1 1 -1 4 4 2 -2 -2 -2 -2 -2 12 12 12 12 12 -12 -12 -12 72 -72 720 720 432 -144 -144 -144 ...
result:
ok correct (1000 test cases)
Test #8:
score: 0
Accepted
time: 752ms
memory: 118896kb
input:
1000 999001 999002 999003 999004 999005 999006 999007 999008 999009 999010 999011 999012 999013 999014 999015 999016 999017 999018 999019 999020 999021 999022 999023 999024 999025 999026 999027 999028 999029 999030 999031 999032 999033 999034 999035 999036 999037 999038 999039 999040 999041 999042 9...
output:
29 1 2 1 1 -1 -1 -1 -1 10 10 10 -5 -5 -5 -5 35 35 35 -35 -35 -35 700 700 700 -700 -700 -700 2240 -2240 30 1 2 1 1 -1 -1 -1 -1 5 5 5 -5 -5 -5 100 100 100 -40 -40 -60 -60 1600 1280 320 320 320 -320 -320 -320 -1280 30 1 1 1 1 -1 -1 -1 12 12 12 4 -8 -8 -8 -8 220 220 220 -220 -220 -220 3520 3520 2112 2...
result:
ok correct (1000 test cases)