QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#387382 | #7937. Fast XORting | wizhao196 | WA | 137ms | 5976kb | C++17 | 1.3kb | 2024-04-12 14:19:48 | 2024-04-12 14:19:48 |
Judging History
answer
#include <iostream>
#include <cmath>
using namespace std;
long long arr[262144];
long long normal[18], reversed[18];
long long n;
long long cycler()
{
bool used[262144];
long long ans = 0;
for(int i =0; i<n; i++)
{
used[i] = false;
}
for(int i =0; i<n ; i++)
{
if(!used[i])
{
long long path = 1;
int x= arr[i];
//cout<<x<<" "<<i<<endl;
while(x!=i)
{
used[x] = true;
x = arr[x];
path++;
}
ans += (path-1);
}
}
return ans;
}
int main()
{
cin>>n;
for(int i =0; i<n; i++)
{
cin>>arr[i];
}
long long ans = cycler();
bool xors = false;
for(int i = log2(n)-1; i>=0; i--)
{
long long current_ans = ans;
//cout<<current_ans<<endl;
for(int j =0; j<n; j++)
{
arr[j] = arr[j] ^(1<<i);
//cout<<arr[j]<<" "<<(1<<i)<<endl;
}
long long new_ans =cycler()+1;
// cout<<new_ans<<endl;
if(new_ans > current_ans)
{
for(int j =0; j<n; j++)
{
arr[j] = arr[j] ^(1<<i);
}
}
else
{
ans = new_ans;
}
}
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3972kb
input:
8 0 1 3 2 5 4 7 6
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4036kb
input:
8 2 0 1 3 4 5 6 7
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 137ms
memory: 5976kb
input:
262144 47482 131703 90418 122675 166494 247529 196154 16950 66501 50357 246808 25929 10418 50538 26955 151884 63776 58023 20073 26544 74785 44064 41836 148543 87920 54172 3270 131495 130960 112122 167229 215767 77499 195004 21391 11039 168999 256346 109690 180904 172679 157200 78594 201857 52784 147...
output:
262123
result:
wrong answer 1st numbers differ - expected: '17137565829', found: '262123'