比赛 20191022轻松模拟测试 评测结果 WWWWWWWWWW
题目名称 Rotate Columns 最终得分 0
用户昵称 djj 运行时间 0.017 s
代码语言 C++ 内存使用 14.32 MiB
提交时间 2019-10-22 17:24:40
显示代码纯文本
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

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

int ans[5], a_[5], aa[5];
int T, n, m, id;
int a[5][200];

void djj_lxy () {
    for (T = read(); T; T --) {
        n = read(), m = read();
        for (register int i = 1; i <= n; i ++)
            for (register int j = 1; j <= m; j ++)
                a[i][j] = read();
        for (register int i = 1; i <= n; i ++)
            ans[i] = a[1][i];
        for (register int i = 2; i <= m; i ++) {
            int s = 0;
            for (register int j = 1; j <= n; j ++) {
                int s_ = 0;
                for (register int k = 0; k <= n; k ++)
                    a[k][i] = a[k + 1][i];
                a[n][i] = a[0][i];
                for (register int k = 1; k <= n; k ++)
                    aa[k] = max (ans[k], a[k][i]);
                for (register int k = 1; k <= n; k ++)
                    s_ += aa[k] - ans[k];
                if (s_ > s) {
                    for (register int k = 1; k <= n; k ++)
                        a_[k] = aa[k];
                    s = s_;
                }
            }
            for (register int j = 1; j <= n; j ++)
                ans[j] = max (ans[j], a_[j]);
        }
        int ans_ = 0;
        for (register int i = 1; i <= n; i ++)
            ans_ += ans[i];
        printf ("%d\n", ans_);
        memset (ans, 0, sizeof ans);
        memset (a_, 0, sizeof a_);
        memset (aa, 0, sizeof aa);
    }
}

int main () {
    freopen ("happygameT1.in", "r", stdin);
    freopen ("happygameT1.out", "w", stdout);
    djj_lxy ();
}

/*
2
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7

12
29
*/