链接
题解
这题就是要在 n − 1 n-1 n−1个位置放一些 1 , 0.5 , − 2 1,0.5,-2 1,0.5,−2,使得乘积等于 1 1 1,那么显然 0.5 0.5 0.5和 − 2 -2 −2的数量要相同,且 − 2 -2 −2要有偶数个,枚举 − 2 -2 −2的数量 i i i,那么这种情形对答案的贡献就是 C n − 1 i C n − 1 − i i C_{n-1}^iC_{n-1-i}^i Cn−1iCn−1−ii
代码
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(_,__) for(_=1;_<=(__);_++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
vector<ll> v[maxn];
ll n, m, sta[maxn], tb[maxn];
pll check(ll Min)
{
ll i, j;
rep(i,n)
{
sta[i]=0;
for(j=0;j<m;j++)sta[i] |= ( ll(v[i][j]>=Min) << j );
}
ll mask=(1<<m)-1;
for(i=0;i<=mask;i++)tb[i]=0;
rep(i,n)
{
tb[sta[i]]=i;
for(j=0;j<=mask;j++)if( (j|sta[i]) == mask )
{
if(tb[j])return pll(tb[j],i);
}
}
return pll(-1,-1);
}
int main()
{
ll i, j, k, l, r, mid;
pll ans;
n=read(), m=read();
rep(i,n)rep(j,m)v[i].emb(read());
l=0, r=1e9;
while(l<r)
{
mid=(l+r+1>>1);
auto pr=check(mid);
if(pr.first==-1)r=mid-1;
else l=mid, ans=pr;
}
ans = check(l);
cout<<ans.first<<' '<<ans.second;
return 0;
}