比赛 20191022轻松模拟测试 评测结果 AWWWAWWWAW
题目名称 Rotate Columns 最终得分 30
用户昵称 liujiaqi 运行时间 0.014 s
代码语言 C++ 内存使用 5.04 MiB
提交时间 2019-10-22 17:26:00
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
int v, c;
template <class T> T read(T& x) {
	x = 0; v = 1; c = getchar();
	for (; c < '0' || c > '9'; c = getchar()) if (c == '-') v = -1;
	for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x *= v;
}
template <class T> inline T max(T x, T y) {return x > y ? x : y;}
const int N = 410;
int Q, n, m, res, ans, a[N][N], f[N], s[N];
int main() {
	freopen("happygameT1.in", "r", stdin);
	freopen("happygameT1.out", "w", stdout);
	read(Q);
	for (; Q; --Q) {
		read(n); read(m);
		memset(s, 0, sizeof(s));
		memset(f, 0, sizeof(f));
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				read(a[i][j]);
				s[j] += a[i][j];
				f[j] = max(f[j], a[i][j]);
			}
		}
		ans = 0;
		for (int i = 1; i <= m; ++i) {
			ans = max(ans, s[i]);
		}
		if (n <= m) {
			std::sort(f + 1, f + m + 1);
			res = 0;
			for (int i = m; i >= m - n + 1; --i) {
				res += f[i];
			}
			printf("%d\n", max(res, ans));
			continue;
		} else {
			if (m == 1) {
				printf("%d\n", ans); continue;
			}
			if (m == 2) {
				for (int k = 1; k <= n; ++k) {
					res = 0;
					for (int i = 1; i <= n; ++i) {
						int j = (i + k) % n;
						if (!j) j = n;
						res += max(a[i][1], a[j][2]);
					}
					ans = max(ans, res);
				}
				printf("%d\n", ans); continue;
			}
			if (m == 3) {
				for (int p = 1; p <= n; ++p) {
					for (int q = 1; q <= n; ++q) {
						res = 0;
						for (int i = 1; i <= n; ++i) {
							int j = (i + p) % n;
							if (!j) j = n;
							int k = (i + q) % n;
							if (!k) k = n;
							res += max(a[i][1], max(a[j][2], a[k][3]));
						}
						ans = max(ans, res);
					}
				}
				printf("%d\n", ans); continue;
			}
		}
	}
	return 0;
}