QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#584706 | #9378. Strange Binary | sn933 | AC ✓ | 13ms | 3552kb | C++20 | 921b | 2024-09-23 16:19:05 | 2024-09-23 16:19:06 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define int long long
#define ull unsigned long long
#define ii __int128
#define endl '\n'
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+5;
void solve(){
int x;cin>>x;
vector<int>ans;
for(int i=31;i>=0;--i){
if(x>>i&1)ans.push_back(1);
else{
if(i==0){
ans.push_back(0);
break;
}
int j=i;
while(j>=0&&((x>>j&1)==0))j--;
if(j<0){
cout<<"NO"<<endl;
return;
}
ans.push_back(1);
for(int k=i-1;k>=j;--k)ans.push_back(-1);
i=j;
}
}
cout<<"YES"<<endl;
reverse(ans.begin(),ans.end());
int cnt=0;
for(auto i:ans){
cnt++;
cout<<i<<(cnt%4==0 ? '\n':' ');
}
}
signed main(){
IOS;
int _=1;
cin>>_;
while(_--)
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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: 3524kb
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: 13ms
memory: 3552kb
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