自己写的代码还是太挫啊。。。
#include <iostream>
#include <stack>
using namespace std;
int n;
stack<int> ids[101];
int hp[200];
int df[2];
int main()
{
cin >> n;
for (int i = 0; i < 2*n; i++)
{
int a;
cin >> a;
ids[a].push(i);
}
int x = 0;
for (int i = 0; i <= 100; i++)
if (ids[i].size() == 1)
{
int id = ids[i].top();
ids[i].pop();
hp[id] = x;
df[x]++;
x = (x+1)%2;
}
for (int i = 0; i <= 100; i++)
if (!ids[i].empty())
{
df[0]++;
df[1]++;
while (!ids[i].empty())
{
int id = ids[i].top();
ids[i].pop();
hp[id] = x;
x = (x+1)%2;
}
}
cout << df[0]*df[1] << "\n";
for (int i = 0; i < 2*n; i++)
cout << hp[i]+1 << " ";
return 0;
}