QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#478469#7937. Fast XORtingembusca#WA 20ms5280kbC++17801b2024-07-14 23:55:092024-07-14 23:55:10

Judging History

你现在查看的是最新测评结果

  • [2024-07-14 23:55:10]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:5280kb
  • [2024-07-14 23:55:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rp(i,a,b)        for(int i=a;i<b;i++)

void solvetask(){
    int n;
    cin >> n;
    vector<int> nums(n);
    rp(i, 0, n) cin >> nums[i];
    ll resp = 1e18, comp = 0;

    rp(i, 0, n) comp += abs(nums[i]-i);
    comp /= 2;
    resp = min(comp, resp);
    bool flag = false;
    rp(i, 0, 18){
        vector<int> temp = nums;
        rp(j, 0, n) temp[j] ^= (1<<i);
        comp = 0;
        rp(j, 0, n) comp += abs(temp[j]-j);
        comp /= 2;
        if(comp <= resp){
            nums = temp;
            resp = comp;
            flag = true;
        }
    }
    cout << resp + flag<< "\n";
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    ll t = 1;
    while(t--) solvetask();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

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: 3612kb

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: 20ms
memory: 5280kb

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:

11432318708

result:

wrong answer 1st numbers differ - expected: '17137565829', found: '11432318708'