QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593728#9378. Strange Binarywjynb666WA 0ms4088kbC++111.5kb2024-09-27 15:42:022024-09-27 15:42:02

Judging History

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

  • [2024-09-27 15:42:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4088kb
  • [2024-09-27 15:42:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define  read_fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

void solve(){
    int n;
    scanf("%d",&n);
    if(n % 4==0){
        printf("NO\n");
        return ;
    }
    vector<int> b(32,-2);
    for(int i=31;i>=1;i--){
        int cur=(n>>i)&1;
        if(cur==0 && b[i]==-2 ){
            b[i]=1;
            b[i-1]=-1;
        }else if(cur==0 && b[i]==-1){
            b[i-1]=-1;
        }else if(cur && b[i]==-2) {
            b[i]=1;
        }
    }
    
    printf("YES\n");
    for(int i=0;i<32;i++){
        printf("%d ",b[i]);
        if((i+1)%8==0) printf("\n");
    }
   
}

// void solve() {
//     int n;
//     scanf("%d", &n);
//     if (n % 4 == 0) {
//         printf("NO\n");
//         return;
//     }
//     vector<int> bit(32);
//     int  m = 32;
//     for (int i = 0; i < m; ++i) {
//         bit[i] = n % 2; // 存储 n 的 原始bit位
//         n /= 2;
//     }
//     for (int i = 0; i < m; ++i) {
//     // 贪心替换 位置为0的地方
//         while (i + 1 < m && (bit[i] && !bit[i+1])) {
//             bit[i+1] = 1;
//             bit[i] = -1;
//             ++i; 
//             }
//     }
//         printf("YES\n");
//         for (int i = 0; i < m; ++i) {
//         printf("%d ", bit[i]);
//         if ((i + 1) % 8 == 0) {
//         printf("\n");
//         }
//     }
// }
int main()
{
    //read_fast;
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4088kb

input:

3
0
3
5

output:

NO
YES
-2 -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 
YES
-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 1 

result:

wrong answer Integer parameter [name=Offend Limitation 1.] equals to -2, violates the range [-1, 1] (test case 3)