Codeforces Round #762 (Div. 3) D
D. New Year's Problem
显然二分
我们二分出一个最小值
然后装进一个桶里
然后要是这一列一个也没装显然不行 没有答案
还有一种没有答案的就是 大家装的都不一样 每个桶里只有1个
显然没有重叠 这个他要求的就是必然要有两个选择是重叠的
时间复杂度O(nlogV)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
vector<int>a[N];
int n,m;
bool check(int x){
vector<int>st(n+1);
for(int j=1;j<=m;j++){
int flag=0;
for(int i=1;i<=n;i++){
if(a[i][j]>=x){
st[i]++;
flag=1;
}
}
if(!flag)return false;
}
for(int i=1;i<=n;i++)if(st[i]>=2)return true;
return false;
}
void solve() {
cin>>n>>m;
for(int i=1;i<=n;i++)a[i].resize(m+1);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
int l=1,r=1e9;
while(l<r){
int mid=l+r+1>>1;
if(check(mid))l=mid;
else r=mid-1;
}
cout<<l<<endl;
}
signed main(){
fast
int t;t=1;cin>>t;
while(t--) {
solve();
}
return ~~(0^_^0);
}

浙公网安备 33010602011771号