QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#97764 | #2351. Lost in Transfer | 2024zll | 0 | 12ms | 3284kb | C++20 | 1.4kb | 2023-04-18 11:11:47 | 2023-04-18 11:11:50 |
Judging History
answer
#include<algorithm>
#include<iostream>
#include<cstring>
#include<random>
using std::cin;
using std::cout;
const int maxn=100,maxval=500;
char op[10];
int T,n,a[maxn],b[maxn+1],xor_sum;
void transmit(){
cin>>n;
xor_sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
xor_sum^=a[i];
}
std::mt19937 mt(xor_sum);
std::shuffle(a,a+n,mt);
for(int i=0;i<n;i++)cout<<a[i]<<(i!=n-1?' ':'\n');
}
void recover(){
cin>>n;
xor_sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
xor_sum^=a[i];
}
{
std::mt19937 mt(xor_sum);
memcpy(b,a,sizeof(int)*n);
std::shuffle(b,b+n,mt);
bool flag=true;
for(int i=0;i<n;i++)
if(a[i]!=b[i]){
flag=false;
break;
}
if(flag){
for(int i=0;i<n;i++)cout<<a[i]<<(i!=n-1?' ':'\n');
return;
}
}
for(int i=1;i<=maxval;i++){
std::mt19937 mt(xor_sum^i);
memcpy(b,a,sizeof(int)*n);
std::shuffle(b,b+n+1,mt);
int l=0,r=n;
while(l<=n&&a[l]==b[l])l++;
while(r>=1&&a[r-1]==b[r])r--;
if(l==r){
for(int i=0;i<=n;i++)cout<<b[i]<<(i!=n?' ':'\n');
return;
}
}
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>op>>T;
if(op[0]=='t'&&op[1]=='r'&&op[2]=='a'&&op[3]=='n'&&op[4]=='s'&&op[5]=='m'&&op[6]=='i'&&op[7]=='t'&&op[8]=='\0')
while(T--)
transmit();
else if(op[0]=='r'&&op[1]=='e'&&op[2]=='c'&&op[3]=='o'&&op[4]=='v'&&op[5]=='e'&&op[6]=='r'&&op[7]=='\0')
while(T--)
recover();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 3284kb
input:
transmit 2 20 97 388 459 467 32 99 98 296 403 325 330 271 87 333 378 267 405 58 426 374 20 125 481 451 150 495 136 444 192 118 26 68 281 120 61 494 339 86 292 100 32
output:
426 403 97 459 98 388 374 271 296 405 87 330 99 267 378 32 467 325 333 58 61 120 118 150 68 339 136 32 495 192 292 125 481 451 494 26 281 100 444 86
input:
recover 2 19 426 403 97 459 98 388 374 271 296 405 87 330 99 267 378 32 467 325 333 19 61 120 118 150 339 136 32 495 192 292 125 481 451 494 26 281 100 444 86
output:
result:
wrong output format Unexpected end of file - int32 expected (test case 1)