Codeforces Team Olympiad
#include<bits/stdc++.h>
using namespace std;
typedef map<int, bool>mpbi;
struct my
{
int in, v;
};
bool cmp(my a, my b)
{
return a.v < b.v;
}
my ar[5010];
//int ar[100];
int main()
{
ios_base::sync_with_stdio(false);
int n;
mpbi mp;
while(cin >> n)
{
mp.clear();
int i=0 , x, quotient=0 , one=0, two=0, three=0, mini=100000 ;
for(i=0; i<n; i++)
{
cin >> x;
ar[i].in = i;
ar[i].v = x;
//ar[i] = x;
if(x == 1) one++;
else if(x == 2) two++;
else if(x == 3) three++;
mini = min(one, two);
mini = min(mini, three);
}
//sort(ar, ar+n , cmp);
if(one==0 or two==0 or three==0)
{
cout << "0\n";
continue;
}
cout << mini << "\n";
sort(ar, ar+n, cmp);
// for(i=0; i<n; i++)
// {
// cout << "index: " << ar[i].in << "-" << ar[i].v << "\n";
// //cout << ar[i] << " ";
// }
while(mini--)
{
mp.clear();
bool f=false;
for(i=0; i<=n; i++)
{
if(!mp[ar[i].v])
{
if(!f)
{
if(ar[i].v)
{
cout << ar[i].in+1;
f=true;
mp[ar[i].v] = true;
ar[i].v = 0;
}
}
else
{
if(ar[i].v)
{
cout << " " << ar[i].in+1;
mp[ar[i].v] = true;
ar[i].v = 0;
}
}
}
}
cout << "\n";
}
}
return 0;
}
using namespace std;
typedef map<int, bool>mpbi;
struct my
{
int in, v;
};
bool cmp(my a, my b)
{
return a.v < b.v;
}
my ar[5010];
//int ar[100];
int main()
{
ios_base::sync_with_stdio(false);
int n;
mpbi mp;
while(cin >> n)
{
mp.clear();
int i=0 , x, quotient=0 , one=0, two=0, three=0, mini=100000 ;
for(i=0; i<n; i++)
{
cin >> x;
ar[i].in = i;
ar[i].v = x;
//ar[i] = x;
if(x == 1) one++;
else if(x == 2) two++;
else if(x == 3) three++;
mini = min(one, two);
mini = min(mini, three);
}
//sort(ar, ar+n , cmp);
if(one==0 or two==0 or three==0)
{
cout << "0\n";
continue;
}
cout << mini << "\n";
sort(ar, ar+n, cmp);
// for(i=0; i<n; i++)
// {
// cout << "index: " << ar[i].in << "-" << ar[i].v << "\n";
// //cout << ar[i] << " ";
// }
while(mini--)
{
mp.clear();
bool f=false;
for(i=0; i<=n; i++)
{
if(!mp[ar[i].v])
{
if(!f)
{
if(ar[i].v)
{
cout << ar[i].in+1;
f=true;
mp[ar[i].v] = true;
ar[i].v = 0;
}
}
else
{
if(ar[i].v)
{
cout << " " << ar[i].in+1;
mp[ar[i].v] = true;
ar[i].v = 0;
}
}
}
}
cout << "\n";
}
}
return 0;
}
Comments
Post a Comment