QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#332839 | #1840. K-onstruction | Crying | AC ✓ | 458ms | 16012kb | C++20 | 2.4kb | 2024-02-19 16:10:59 | 2024-02-19 16:10:59 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int MAXM = 1e4+10,MAXN = 1e6+10,N = 1e6,INF = 1e9;
ll T,k;
vector<ll> ans;
const ll val[6] = {-3,-2,-1,1,2,3};
typedef array<ll,6> node; //(-3,-2,-1,1,2,3)
node tmp;
struct vec{
node state;
ll w,x,y;
bool operator<(const vec& v2)const{
return w < v2.w;
}
};
vec t[MAXM]; int tot;
ll r[10];
int dp[MAXN],pre[MAXN],pp[MAXN],C[20][20];
void rdfs(int now,int sum,int w,int& x,int& y){
if(now == 6){
if(sum == 0)x+=w;
else if(sum == -1)y+=w;
return;
}
rep(i,0,r[now]){
rdfs(now+1,sum + i * val[now],w * C[r[now]][i],x,y);
}
}
void dfs(int now,int sum){
if(now == 6){ //新的 转移
int x = 0,y = 0;
rdfs(0,0,1,x,y);
tot++;
rep(i,0,5)t[tot].state[i] = r[i];
t[tot].w = sum; t[tot].x = x; t[tot].y = y;
return;
}
rep(i,0,10){
if(sum + i > 10)break;
r[now] = i;
dfs(now+1,sum+i);
}
}
vector<int> path;
void solve(){
cin>>k; ans.clear();
path.clear(); while(k>1){
path.push_back(pre[k]);
k = pp[k];
}
reverse(path.begin(),path.end());
ll P = 2,N = -1;
ans.push_back(2); ans.push_back(-1);
for(auto j : path){
ll bv;
if(P+N>0)bv = P;
else bv = N;
rep(i,0,5){
rep(r,1,t[j].state[i]){
ll w = val[i] * bv;
if(w > 0)P += w;
else N += w;
ans.push_back(w);
}
}
}
cout<<ans.size()<<"\n";
for(auto u : ans)cout<<u<<" ";cout<<"\n";
}
int main(){
//freopen("zero.in","r",stdin);
//freopen("zero.out","w",stdout);
ios::sync_with_stdio(false); cin.tie(0);
C[0][0] = 1;
rep(i,1,19){
C[i][0] = 1;
rep(j,1,i)C[i][j] = C[i-1][j-1] + C[i-1][j];
}
dfs(0,0);
sort(t+1,t+1+tot);
rep(i,2,N)dp[i] = INF; dp[1] = 2;
rep(i,1,N){
rep(j,1,tot){
if(dp[i] + t[j].w > 30)break;
ll to = 1ll * i * t[j].x + t[j].y;
if(to > N) continue;
if(dp[to] > dp[i] + t[j].w){
dp[to] = dp[i] + t[j].w;
pre[to] = j;
pp[to] = i;
}
}
}
cin>>T;
while(T--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 448ms
memory: 15904kb
input:
2 3 16
output:
4 2 -1 -2 2 7 2 -1 -2 3 3 -3 -3
result:
ok correct (2 test cases)
Test #2:
score: 0
Accepted
time: 446ms
memory: 16012kb
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:
2 2 -1 3 2 -1 -2 4 2 -1 -2 2 5 2 -1 -6 -2 6 5 2 -1 -2 3 -3 5 2 -1 -2 -2 2 6 2 -1 -4 -4 2 2 6 2 -1 -4 -2 2 2 6 2 -1 -2 3 3 -3 6 2 -1 -2 -2 -2 2 7 2 -1 -2 -2 2 2 4 7 2 -1 -4 -4 2 2 4 7 2 -1 -2 -2 2 5 -5 7 2 -1 -4 -4 2 2 2 7 2 -1 -2 -2 2 2 2 7 2 -1 -2 3 3 -3 -3 8 2 -1 -6 -6 2 4 4 4 8 2...
result:
ok correct (1000 test cases)
Test #3:
score: 0
Accepted
time: 438ms
memory: 15924kb
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:
16 2 -1 -2 3 3 -3 -24 -24 -24 -16 -16 16 24 24 24 24 15 2 -1 -6 -2 6 18 9 9 9 -9 -9 -9 -9 -9 -9 15 2 -1 -2 -2 2 10 5 5 5 5 -5 -5 -5 -10 -15 15 2 -1 -2 -2 -2 2 14 7 7 7 7 -7 -7 -14 -14 16 2 -1 -4 -2 2 2 21 21 21 7 -7 -14 -14 -14 -14 -14 16 2 -1 -2 -2 -2 -2 2 4 18 9 9 9 9 9 -9 -18 15 2 -1 -2 3 -...
result:
ok correct (1000 test cases)
Test #4:
score: 0
Accepted
time: 439ms
memory: 15920kb
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:
30 2 -1 -4 -2 -2 -2 -2 2 4 4 26 26 26 26 26 26 26 -39 -39 -39 -388 -194 -194 -194 -194 -194 -194 -194 388 388 30 2 -1 -4 -4 -4 -4 -2 2 4 4 57 38 19 19 19 19 -19 -38 -38 -38 -549 -366 -183 -183 -183 -183 -183 183 183 549 30 2 -1 -6 -4 -4 -2 -2 2 4 4 6 19 19 19 19 19 19 19 19 -19 -57 -510 -340 -340 ...
result:
ok correct (1000 test cases)
Test #5:
score: 0
Accepted
time: 458ms
memory: 15868kb
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 2 -1 -2 -2 -2 -2 2 2 2 2 -20 -10 -10 -10 -10 10 30 30 30 30 20 2 -1 -6 -2 -2 -2 2 4 4 4 -48 -48 -48 -32 -16 48 48 48 48 48 19 2 -1 -2 3 3 3 -3 -3 -3 24 12 12 -12 -12 -12 -12 -12 -12 -12 19 2 -1 -2 -2 -2 -2 2 2 2 18 9 9 9 9 9 9 -27 -27 -27 19 2 -1 -2 -2 -2 -2 2 2 2 9 9 9 9 9 9 9 -27 -27 -27 2...
result:
ok correct (1000 test cases)
Test #6:
score: 0
Accepted
time: 442ms
memory: 15916kb
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 2 -1 -2 -2 -2 -2 2 2 18 9 9 9 9 9 -9 -9 -18 -69 -69 -69 69 69 69 69 25 2 -1 -2 -2 -2 2 21 21 21 7 -7 -7 -7 -14 -14 -21 154 77 77 77 77 77 -77 -77 -154 25 2 -1 -2 3 -3 18 6 6 6 6 6 6 -6 -6 -18 -118 -59 -59 -59 -59 -59 -59 59 59 177 24 2 -1 -6 -2 -2 -2 2 2 2 6 -14 -14 -14 -14 14 14 14 14 14 14 -...
result:
ok correct (1000 test cases)
Test #7:
score: 0
Accepted
time: 449ms
memory: 15972kb
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 2 -1 -4 -2 -2 -2 -2 -2 2 4 4 6 -18 -18 -18 -18 -18 -18 36 36 246 123 123 123 123 -123 -123 -246 -369 29 2 -1 -2 -2 -2 -2 -2 2 2 2 2 2 -36 -36 -36 36 36 36 -120 -120 120 120 -1080 -1080 -360 360 360 1080 1080 29 2 -1 -2 3 3 3 3 3 -3 -3 -3 -3 -3 18 18 18 18 -18 -18 -267 -178 -178 -178 -178 -89 89...
result:
ok correct (1000 test cases)
Test #8:
score: 0
Accepted
time: 436ms
memory: 15948kb
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 2 -1 -2 -2 -2 -2 2 2 2 27 18 9 9 9 9 -18 -18 -18 -27 270 180 90 90 90 -90 -90 -270 -270 -270 29 2 -1 -2 -2 -2 -2 2 2 2 2 -30 -20 -20 -10 -10 20 20 20 20 198 99 99 99 99 99 99 99 -198 -297 29 2 -1 -2 3 3 3 3 -3 -3 -3 -3 -3 36 18 18 18 -18 -18 -36 -312 -208 -208 -208 -104 104 104 104 104 208 29 ...
result:
ok correct (1000 test cases)