QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#864609#9852. DivisionsZhenLiuWA 0ms3584kbC++142.2kb2025-01-20 20:12:582025-01-20 20:12:58

Judging History

你现在查看的是最新测评结果

  • [2025-01-20 20:12:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3584kb
  • [2025-01-20 20:12:58]
  • 提交

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;
    }
    if(k == 0){
        cout << 4 << endl;
        cout << "2 4 1 3" << 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
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:

4
2 4 1 3

result:

wrong answer wrong answer