QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#588928 | #9378. Strange Binary | Hide_In_The_Shadow | AC ✓ | 6ms | 3776kb | C++23 | 1.6kb | 2024-09-25 15:15:43 | 2024-09-25 15:15:44 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fio std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
template<typename T>inline void read(T &x){
x=0;
char c=getchar();
T ret=0;
while(!isdigit(c))ret|=!(c^'-'),c=getchar();
while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(ret)x=(~x)+1;
return;
}
template<typename T>inline void print(T x){
if(x<0)putchar('-'),x=(~x)+1;
if(x>9)print(x/10);
putchar((x-x/10*10)^48);
return;
}
template<typename T>inline void wr1(T x){
print(x);
putchar(' ');
return;
}
template<typename T>inline void wr2(T x){
print(x);
putchar('\n');
return;
}
int t,n;
stack<int>out;
int main(){
read(t);
while(t--){
read(n);
if(n==0||((n&(-n))>2)){
puts("NO");
continue;
}
puts("YES");
bool pre=0;
for(int i=31;i>=0;--i){
if(!n){
out.push(0);
continue;
}
if(pre){
out.push(-1);
if(1&(n>>i)){
pre=0;
n^=1<<i;
}
}
else{
out.push(1);
if(!(1&(n>>i))){
pre=1;
}
else{
n^=1<<i;
}
}
}
while(out.size()){
wr1(out.top());
if((out.size()-1)%8==0)putchar('\n');
out.pop();
}
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3492kb
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: 3588kb
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: 6ms
memory: 3776kb
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...
result:
ok Accepted! (10000 test cases)
Extra Test:
score: 0
Extra Test Passed