QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#864534 | #9852. Divisions | ZhenLiu# | WA | 1ms | 3584kb | C++14 | 2.1kb | 2025-01-20 18:29:05 | 2025-01-20 18:29:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
int ans[500];
int ansbit=0,ansnum=1;
int cnt=0;
int bitget[30],bitnum,num1;
void getnum1(int x){
bitnum=0; num1=0;
while(x>0){
bitget[bitnum++]=x&1;
if(x&1){
++num1;
}
x>>=1;
}
return ;
}
int main(){
bool tag=false;
int k;
cin >> k;
if(k==1){
printf("6\n1 1 4 5 1 4\n");
return 0;
}
if(k==3){
printf("3\n1 1 2\n");
return 0;
}
int nowneed=k;
while(1){
getnum1(nowneed);
if(!tag || nowneed==1)
nowneed=num1-1;
else
nowneed=num1;
tag = true;
for(int i=bitnum-1;i>=0;--i){
if(bitget[i]==1){
if(i>=1)
for(int j=1;j<=i;++j)
ans[++ansbit]=ansnum;
else
ans[++ansbit]=ansnum;
++ansnum;
}
}
if(ansbit>365){
printf("-1");
return 0;
}
if(nowneed==0)
break;
}
printf("%d\n",ansbit);
for(int i=1;i<=ansbit;++i)
printf("%d ",ans[i]);
return 0;
}
*/
int two[31];
int fp(int a, int n){
int ans = 1;
while(n){
if(n & 1){
ans *= a;
}
a *= a;
n >>= 1;
}
return ans;
}
int ans[366];
int main(){
int k;
int cnt = 1;
int num = 1;
cin >> k;
if(k == 1){
cout << 6 << endl;
cout << "1 1 4 5 1 4" << endl;
return 0;
}
for(int i = 0; i <= 31; ++i){
two[i] = fp(2, i);
}
while(1){
int temp = upper_bound(two, two + 32, k) - two;
for(int i = 1; i < temp; ++i){
ans[cnt++] = num;
}
num++;
k -= two[temp - 1];
if(k <= 0){
break;
}
k++;
}
cout << cnt - 1 << endl;
for(int i = 1; i < cnt; ++i){
cout << ans[i] << " ";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
1
output:
6 1 1 4 5 1 4
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2
output:
1 1
result:
ok correct
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3584kb
input:
0
output:
0
result:
wrong answer empty sequence found