比赛 2024.5.23练习赛 评测结果 AAAAAAAAAA
题目名称 Rotate Columns 最终得分 100
用户昵称 ┭┮﹏┭┮ 运行时间 0.051 s
代码语言 C++ 内存使用 3.13 MiB
提交时间 2024-05-23 20:24:27
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define in inline
#define re register
#define pii pair<int,int>
#define fi first 
#define se second
#define pb(x) push_back(x)
#define D(i,a,b) for(re int i = a;i >= b;i--)
#define F(i,a,b) for(re int i = a;i <= b;i++)
const int N = 1e4+10,M = 320;
const ll inf = 1e17;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c >= '0' && c <= '9';c = getchar())x = (x<<1) + (x<<3) + c-'0';
    return x * f;
}

int t,n,m;
int cnt,ans,c[N],sum,b[10][N],id[N];
pii a[N];
void sou(int x){
    if(x == sum+1){
        int s = 0;
        F(i,1,n){
            int mx = 0;
            F(j,1,m)mx = max(mx,b[(i+id[j])%n][j]);
            s += mx;
        }
        return ans = max(s,ans),void();
    }
    for(int i = 0;i < n;i++){
        id[c[x]] = i;
        sou(x+1);
        id[c[x]] = 0;
    } 
}
int main(){
    freopen("happygameT1.in","r",stdin);
    freopen("happygameT1.out","w",stdout);
    t = read();
    F(_,1,t){
        n = read(),m = read();ans = cnt = sum = 0;
        F(i,0,n-1){
            F(j,1,m)b[i][j] = read(),a[++cnt].fi = b[i][j],a[cnt].se = j;
        }
        sort(a+1,a+1+cnt);
        for(int i = 1,j = cnt;i <= n;i++,j--)c[++sum] = a[j].se;
        sort(c+1,c+1+sum);
        sum = unique(c+1,c+1+sum) - (c+1);
        sou(1); 
        printf("%d\n",ans);
    }
    
	return cerr << "Time : " << clock() << " ms" << endl, 0;
        
}
/*
5
2 2 4 1 2
12
2 1 5 4
2 1 5 1
*/