QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586808#9378. Strange Binaryeastcloud#AC ✓3ms3940kbC++201.3kb2024-09-24 15:42:242024-09-24 15:42:24

Judging History

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

  • [2024-09-24 15:42:24]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3940kb
  • [2024-09-24 15:42:24]
  • 提交

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array

using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(int x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}


void solve(){
    int x=read();
    if(x%4==0){printf("NO\n");return;}
    printf("YES\n");
    int cnt=0,now=0;vi res;
    for(int i=31;i>=0;i--){
        if(i==0 && !(x&1)){res.pb(0);break;}
        int val=(1<<i);
        if(abs(now+val-x)<=abs(now-val-x))now+=val,res.pb(1);
        else now-=val,res.pb(-1);
    }
    reverse(res.begin(),res.end());
    for(int i=0;i<res.size();i++){
        write(res[i]);
        putchar((i%8==7?'\n':' '));
    }
}

int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    #endif

    int T=read();while(T--)solve();

    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3720kb

input:

3
0
3
5

output:

NO
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
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:

ok Accepted! (3 test cases)

Test #2:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

2
0
1073741823

output:

NO
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:

ok Accepted! (2 test cases)

Test #3:

score: 0
Accepted
time: 3ms
memory: 3856kb

input:

10000
324097321
555675086
304655177
991244276
9980291
383616352
1071036550
795625380
682098056
68370721
969101726
685975156
973896269
354857775
196188000
606494155
754416123
467588829
495704303
558090120
618002000
491488050
741575237
9937018
10028830
140094825
652839595
357724903
516690123
817724271...

output:

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
YES
0 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
NO
YES
1 -1 -1 -1 -1 -1 1 1
-1 -1 1 -1 -1 1...

result:

ok Accepted! (10000 test cases)

Extra Test:

score: 0
Extra Test Passed