QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581513 | #9378. Strange Binary | jack | WA | 1ms | 3600kb | C++14 | 1.5kb | 2024-09-22 13:10:23 | 2024-09-22 13:10:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
void solve()
{
int n;
cin>>n;
if(n==0)
{
cout<<"NO"<<'\n';
return;
}
vector<int> q;
for(int i=30;i>=0;i--)
{
if(n>>i&1)
{
q.push_back(1);
}else q.push_back(0);
}
reverse(q.begin(),q.end());
vector<int> ans;
ans.push_back(1);
int pos=0;
for(int i=q.size()-1;i>=0;i--)
{
if(q[i]==0)
{
ans.push_back(-1);
}else
{
pos=i;
ans.push_back(-1);
break;
}
}
int pos1=0;
for(int i=0;i<q.size();i++)
{
if(q[i]!=0)
{
pos1=i;
break;
}
}
if(pos1>=2)
{
cout<<"NO"<<'\n';
return;
}
cout<<"YES"<<'\n';
for(int i=pos-1;i>=pos1;i--)
{
if(q[i]==0)
{
if(q[i+1]==1) ans.push_back(1);
else ans.push_back(-1);
}else
{
ans.push_back(-1);
}
}
for(int i=pos1-1;i>=0;i--) ans.push_back(q[i]);
reverse(ans.begin(),ans.end());
for(int i=0;i<ans.size();i++)
{
cout<<ans[i]<<' ';
if((i+1)%8==0)
{
cout<<'\n';
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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: 1ms
memory: 3600kb
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:
wrong answer Offend Limitation 3. (test case 3)