Educational Codeforces Round 80 (Rated for Div. 2) D. Minimax Problem

D. Minimax Problem

time limit per test

5 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

You are given nn arrays a1a1, a2a2, ..., anan; each array consists of exactly mm integers. We denote the yy-th element of the xx-th array as ax,yax,y.

You have to choose two arrays aiai and ajaj (1≤i,j≤n1≤i,j≤n, it is possible that i=ji=j). After that, you will obtain a new array bb consisting of mmintegers, such that for every k∈[1,m]k∈[1,m] bk=max(ai,k,aj,k)bk=max(ai,k,aj,k).

Your goal is to choose ii and jj so that the value of mink=1mbkmink=1mbk is maximum possible.

Input

The first line contains two integers nn and mm (1≤n≤3⋅1051≤n≤3⋅105, 1≤m≤81≤m≤8) — the number of arrays and the number of elements in each array, respectively.

Then nn lines follow, the xx-th line contains the array axax represented by mm integers ax,1ax,1, ax,2ax,2, ..., ax,max,m (0≤ax,y≤1090≤ax,y≤109).

Output

Print two integers ii and jj (1≤i,j≤n1≤i,j≤n, it is possible that i=ji=j) — the indices of the two arrays you have to choose so that the value of mink=1mbkmink=1mbk is maximum possible. If there are multiple answers, print any of them.

Example

input

Copy

6 5
5 0 3 1 2
1 8 9 1 3
1 2 3 4 5
9 1 0 3 7
2 3 0 6 3
6 4 1 7 0

output

Copy

1 5
 1 /*
 2 看到题目首先想到的就是二分答案,那么找到一个可能的答案之后就可以把所有数列转化成01数列,1代表该位置的数大于等于答案,0代表该位置的数小于答案。
 3
 4 选择两个数列使其满足答案,也就是使这两个数列的或和为(1<<m)-1,很显然不能n*n的枚举每个数列,但是2^8只有256,所以可以直接枚举数列对应的二进制数,判断答案是否可行,如果可行,就可以O(n)地寻找可行解
 5 */
 6 #include<iostream>
 7 #include<cstdio>
 8 #include<bitset>
 9 #include<cstring>
10 using namespace std;
11 int n,m,a[300010][10],ans1,ans2;
12 int b[300010];
13 bool vis[300];
14 bool check(int x){
15     memset(b,0,sizeof(b));
16     for(int i=1;i<=n;i++){
17         for(int j=1;j<=m;j++){
18             if(a[i][j]>=x)b[i]^=1<<(j-1);
19         }
20     }
21     memset(vis,0,sizeof(vis));
22     for(int i=1;i<=n;i++)vis[b[i]]=1;
23     bool flag=0;
24     int s1=0,s2=0;
25     for(int sta1=0;sta1<(1<<m);sta1++){
26         for(int sta2=sta1;sta2<(1<<m);sta2++){
27             if((sta1|sta2)==(1<<m)-1&&vis[sta1]&&vis[sta2]){
28                 s1=sta1;s2=sta2;
29                 flag=1;
30                 break;
31             }
32         }
33         if(flag)break;
34     }
35     if(!flag)return 0;
36     for(int i=1;i<=n;i++){
37         if(b[i]==s1){
38             ans1=i;
39             break;
40         }
41     }
42     for(int i=1;i<=n;i++){
43         if(b[i]==s2){
44             ans2=i;
45             break;
46         }
47     }
48     return 1;
49 }
50 int main(){
51     scanf("%d%d",&n,&m);
52     for(int i=1;i<=n;i++)
53         for(int j=1;j<=m;j++){
54             scanf("%d",&a[i][j]);
55         }
56     int l=0,r=1000000000;
57     while(l<=r){
58         int mid=(l+r)>>1;
59         if(check(mid)){
60             l=mid+1;
61         }
62         else r=mid-1;
63     }
64     printf("%d %d\n",ans1,ans2);
65     return 0;
66 }

原文地址:https://www.cnblogs.com/thmyl/p/12237546.html

时间: 2024-08-30 14:25:49

Educational Codeforces Round 80 (Rated for Div. 2) D. Minimax Problem的相关文章

Educational Codeforces Round 80 (Rated for Div. 2)

\[Educational\ Codeforces\ Round\ 80\ (Rated\ for\ Div.\ 2)\] A.Deadline 打勾函数找最小值,在\(\sqrt{d}\)邻域里找\(x\)最小化\(x+\lceil\frac{d}{x+1}\rceil\)即可 //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace

Educational Codeforces Round 80 (Rated for Div. 2)(C - Two Arrays )

C - Two Arrays 题目链接:https://codeforces.com/contest/1288/problem/C 题目: 题意:给你n,m,利用1~n之间的数(可重复)来组成长度为m的数组a,b,要求数组a非递减,数组b非递增,且a数组的数<=b数组中的数,求出a,b数组对数 思路:用动态规划,dp[i][j]是第i个位置放数字j的方案数,根据题意可以将b数组反置然后接在a后面,则该数组长度为2m,为一个非递减序列,则就是求1~n这些数字可重复组成多少种长度为2m的非递减序列,

Educational Codeforces Round 80 (Rated for Div. 2)参加感悟

这次比赛有14000+的人报名,结果我得了266名,创了新纪录. 进过这次比赛,我有回答了1800+. 寒假到了,又可以每次比赛都打了.平时进步很慢,我希望能在寒假有更大的进步. 作为寒假第一场比赛,发挥让我还是很满意的. 开始讲题: A: http://codeforces.com/contest/1288/problem/A 这题太水了,直接是sqrt(d)-1和sqrt(d),如果它们不行,那么其他的也肯定不行. 直接上代码: 1 #include<bits/stdc++.h> 2 #d

Educational Codeforces Round 80 (Rated for Div. 2(A Deadline )

(A) Deadline 题目: 思路:一开始还傻傻的暴力康康....只要求出令x=n的一半就行,然后判断 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 //freopen("text","r",stdin); 6 int T; 7 scanf("%d",&T); 8 while(T--) 9 { 10 //cout<<cei

题解 Educational Codeforces Round 80 [Rated for Div. 2](CF1288)

前言:11点的时候某天下第一可爱的萌神问我怎么不打CF,跑去开题,11:30终于开了C和D,秒了一下,考后萌神轻松上分并告诉我E的tag于是我赛后补题. A:n/x上取整是(n-1)/x+1,式子变形成x+1+(n-1)/(x+1)<=d.根据a+b>=2√ab随便化简一下.(20s秒了??) 1 #include<stdio.h> 2 #include<math.h> 3 using namespace std; 4 int T,n,d,x,y; 5 int main

Educational Codeforces Round 80 (Rated for Div. 2) C - Two Arrays(DP)

???♀? ???♀? ???♀? 题意:从1~n里面选出来m个数字组成a数组,再选出来m个组成b数组,要求a非递减,b非递增,且bi>=ai 1,说是选两个数组其实就是选出来一个长m*2的非递减数组 2,假设要从n的全排列中选出来m长的非递减数组,因为元素是可重复的,最多重复m次,其实就是相当于从下面这个矩阵中选择元素 从这个矩阵中选择元素,每行只能选择一个,枚举我们选出的k个元素的最小值为[ i , j ]位置,那么除去这个元素选择k-1个元素的方案数之和就是k个元素,如图中红色标出位置,最

Educational Codeforces Round 80 (Rated for Div. 2)C(DP)

1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 const long long mod = 1e9+7; 5 long long pre[1007][1007],temp[1007][1007]; 6 int main(){ 7 ios::sync_with_stdio(false); 8 cin.tie(NULL); 9 cout.tie(NULL); 10 int n,m;

Educational Codeforces Round 80 (Rated for Div. 2)部分题解

A. Deadline 题目链接 题目大意 给你\(n,d\)两个数,问是否存在\(x\)使得\(x+\frac{d}{x+1}\leq n\),其中\(\frac{d}{x+1}\)向上取整. 解题思路 方案一:利用均值不等式公式推导 \(x+\frac{d}{x+1}=x+1+\frac{d}{x+1}-1\geq2\sqrt{d}-1\) 所以 \(\min(x+\frac{x}{d+1})=2\sqrt{d}-1\) 因此去判断\(2\sqrt{d}-1\leq n\)是否成,即\(4\

Educational Codeforces Round 80 (Rated for Div. 2)【A,B,C,D】C题DP{GG了} D题【数组转化成二进制形式判断+二分】

A题直接暴力水过 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 #define int long long 5 #define N 6666666 6 int arr[N]; 7 8 signed main(){ 9 int _;cin>>_; 10 while(_--){ 11 int n,m; 12 cin>>n>>m; 13 if(n>=m){ 14 cout<<"