QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800872#8783. Cherry Pickingucup-team6015#TL 0ms0kbC++11848b2024-12-06 16:21:422024-12-06 16:21:42

Judging History

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

  • [2024-12-06 16:21:42]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-12-06 16:21:42]
  • 提交

answer

#include <bits/stdc++.h>

std::mt19937 rnd(time(0));

int main()
{
    int n;
    scanf("%d",&n);
    std::vector<int> ori(n),a(n),b(n);
    for(int i=0;i<n;i++)
        scanf("%d",&ori[i]);
    for(int i=0;i<n/2;i++)
        a[i]=ori[i];
    for(int i=0;i<n/2;i++)
        b[i]=ori[i+n/2];
    const int N=1e9;
    for(;;)
    {
        int sum=0;
        for(int i=0;i<n/2;i++)
            sum += a[i];
        if(sum == N)
            break;
        int pos=rnd()%(n/2),j=0;
        for(int i=0;i<n/2;i++)
            if(abs(N-(sum-a[pos]+b[i]))<abs(N-(sum-a[pos]+b[j])))
                j=i;
        std::swap(a[pos],b[j]);
    }
    printf("%d ",n/2);
    for(int i=0;i<n/2;i++)
        for(int j=0;j<n;j++)
            if(a[i] == ori[j])
                printf("%d%c",j+1," \n"[i == n/2-1]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

5 2
1 2 3 4 5
01101

output:


result: