天天看點

Codeforces Contest 1138 problem B Circus —— 死亡1700,暴力

Polycarp is a head of a circus troupe. There are n — an even number — artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then ci=1, otherwise ci=0), and whether they can perform as an acrobat (if yes, then ai=1, otherwise ai=0).

Split the artists into two performances in such a way that:

each artist plays in exactly one performance,

the number of artists in the two performances is equal (i.e. equal to n2),

the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance.

Input

The first line contains a single integer n (2≤n≤5000, n is even) — the number of artists in the troupe.

The second line contains n digits c1c2…cn, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise.

The third line contains n digits a1a2…an, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise.

Output

Print n2 distinct integers — the indices of the artists that should play in the first performance.

If there are multiple answers, print any.

If there is no solution, print a single integer −1.

Examples

inputCopy

4

0011

0101

outputCopy

1 4

inputCopy

6

000000

111111

outputCopy

-1

inputCopy

4

0011

1100

outputCopy

4 3

inputCopy

8

00100101

01111100

outputCopy

1 2 3 6

Note

In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 1 and 4 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 1. And the number of artists in the second performance who can perform as acrobats is 1 as well.

In the second example, the division is not possible.

In the third example, one of the possible divisions is as follows: in the first performance artists 3 and 4 should take part. Then in the first performance there are 2 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 2 as well.

題意:

給你n個人的兩種技能,1代表會,0代表不會。現在有兩場演出,每場需要配置設定n/2個人,每個人隻能去一場,讓你輸出第一場去的人使得在第一場會第一個技能的人的數量=第二場會第二個技能的人的數量。

題解:

我真的服了,這是B該有的難度嗎?而且為什麼每個1700難度對我都這麼不友好?sun dog。

還是不要看我的代碼了,去看别人的吧,我自己寫留個紀念。

我設會第一個技能但不會第二個技能為oz:one zero 同理可得:zo,oo,zz

首先如果zo有0個且oz也是0個且oo有奇數個,那麼不論怎麼配置設定都不可能相等

然後如果zo的數量-zz的數量>oz的數量+oo的數量,或者相反。也就是說一邊無論怎麼拿,會這個的人數都比另一邊大,那麼也是不可能的。

之後要考慮oz.size()和zo.size()的大小,我是直接做小的。如果(int)zo.size()>(int)oz.size()

重點:size()的有關操作最好是強轉之後做,否則會re

那麼oz肯定全部要取,之後就是while一下,看看要取多少oo,然後這裡還有一個判斷,我舉個栗子:

oo zo oz+oo(給oz的oo,一開始假設全都給zo)
3  4   4
           

如果oo讓給oz一個

那麼就變成

oo zo oz+oo
2  4  5
           

如果再給一個,那麼oz+oo就比zo最終所擁有的1多了,但是這是不被允許的,因為我後面并沒有把zo的1補回來的辦法。那麼就要numoo+(int)zo.size()>(int)oz.size()+res+1的時候才能給。

注意這時候oo和zo的1的數量比oz多,那麼我們之後把一個zo給oz,這樣的話zo+oo的1的數量就會-1,但是oz的1的數量并不會加!

最後隻需要加上少掉的zz就可以了。

第二種情況oz>zo。這時候一開始都一樣,隻要翻轉一下,但是注意最後輸出不能輸出剛才找的這些,因為它是第二場。如果輸出了第二場的技能1的話,可能就不對了,因為我們最後還有消去oz的過程。那麼我們要用一個vis記錄一下那些是第二場的,最後輸出的時候判一下即可。

#include<bits/stdc++.h>
using namespace std;
#define pa pair<int,int>
const int N=5e3+5;
int a[N],b[N];
vector<int>ans,zz,zo,oz,oo;
int vis[N];
int main()
{
    int n,sec=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%1d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        scanf("%1d",&b[i]);
        if(a[i]==0&&b[i]==0)
            zz.push_back(i);
        else if(a[i]==0&&b[i]==1)
            zo.push_back(i);
        else if(a[i]==1&&b[i]==0)
            oz.push_back(i);
        else if(a[i]==1&&b[i]==1)
            oo.push_back(i);
    }
    if((int)zo.size()==0&&(int)oz.size()==0&&((int)oo.size())%2==1)
        return 0*printf("-1\n");
    if((int)zo.size()-(int)zz.size()>(int)oz.size()+(int)oo.size()||(int)oz.size()-(int)zz.size()>(int)zo.size()+(int)oo.size())
        return 0*printf("-1\n");
    //if(n==4990)
        //printf("%d %d %d %d\n",zo.size(),oz.size(),zz.size(),oo.size());
    if((int)zo.size()>(int)oz.size())
    {
        int i=0;
        for(int i=0;i<(int)oz.size();i++)
            printf("%d ",oz[i]);
        int numoo=(int)oo.size(),res=0;
        while(numoo+(int)zo.size()>(int)oz.size()+res+1&&numoo)
        {
            numoo--;
            printf("%d ",oo[res++]);
        }
        while(numoo+(int)zo.size()>(int)oz.size()+res)
            printf("%d ",zo[i++]),res++;
        while(i<zo.size()&&oz.size()+res<n/2)
            printf("%d ",zz[i++]),res++;
    }

    else
    {
        int azo=0,aoz=0,aoo=0,azz=0;
        for(int i=0;i<(int)zo.size();i++)
            vis[zo[i]]=1,azo+=(a[zo[i]]==0&&b[zo[i]]==1);
        int numoo=oo.size(),res=0;
        while(numoo+(int)oz.size()>(int)zo.size()+res+1&&numoo)
        {
            numoo--;
            vis[oo[res++]]=1,aoo+=(a[oo[res-1]]==1&&b[oo[res-1]]==1);
        }
        int i=0;
        while(i<(int)oz.size()&&numoo+(int)oz.size()>(int)zo.size()+res)
            vis[oz[i++]]=1,res++,aoz+=(a[oz[0]]==1&&b[oz[0]]==1);
        //if(n==5000)
            //printf("%d\n",res);
        while((int)zo.size()+res<n/2)
            vis[zz[i]]=1,i++,res++,azz+=(a[zz[i-1]]==0&&b[zz[i-1]]==0);
        //if(n==4990)
            //printf("%d %d %d\n",azo+aoo+azz+aoz,azo+aoo,oz.size()-aoz+oo.size()-aoo);
        for(int i=1;i<=n;i++)
            if(!vis[i])
                printf("%d ",i);
    }
    printf("\n");
    return 0;
}