提出 #4464140


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/04  Problem: ABC 100 D / Link: http://abc100.contest.atcoder.jp/tasks/abc100_d  ----- */

LL dp[1003][1003][2][2][2];

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	fill(****dp, ****dp + 1003 * 1003 * 2 * 2 * 2, -LINF);
	LL N, M; cin >> N >> M;
	VL x(N), y(N), z(N);
	FOR(i, 0, N) {
		cin >> x[i] >> y[i] >> z[i];
	}
	auto chmax = [](LL &a, LL b) {
		a = max(a, b);
	};

	FOR(a, 0, 2)FOR(b, 0, 2)FOR(c, 0, 2) {
		dp[0][0][a][b][c] = 0;
	}
	FOR(i, 0, N) {
		FOR(j, 0, i + 1) {
			FOR(a, 0, 2) {
				FOR(b, 0, 2) {
					FOR(c, 0, 2) {
						LL addval = (a ? x[i] : -x[i]) + (b ? y[i] : -y[i]) + (c ? z[i] : -z[i]);
						chmax(dp[i + 1][j][a][b][c], dp[i][j][a][b][c]);
						chmax(dp[i + 1][j + 1][a][b][c], dp[i][j][a][b][c] + addval);
					}
				}
			}
		}
	}



	LL ans = 0;
	FOR(a, 0, 2)FOR(b, 0, 2)FOR(c, 0, 2) {
		ans = max(ans, dp[N][M][a][b][c]);
	}
	cout << (ans) << "\n";

	return 0;
}

提出情報

提出日時
問題 D - Patisserie ABC
ユーザ Yang33
言語 C++14 (GCC 5.4.1)
得点 400
コード長 1936 Byte
結果 AC
実行時間 34 ms
メモリ 63104 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 4
AC × 20
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
ケース名 結果 実行時間 メモリ
in01.txt AC 34 ms 63104 KiB
in02.txt AC 34 ms 63104 KiB
in03.txt AC 34 ms 63104 KiB
in04.txt AC 34 ms 63104 KiB
in05.txt AC 34 ms 63104 KiB
in06.txt AC 34 ms 63104 KiB
in07.txt AC 34 ms 63104 KiB
in08.txt AC 34 ms 63104 KiB
in09.txt AC 34 ms 63104 KiB
in10.txt AC 34 ms 63104 KiB
in11.txt AC 34 ms 63104 KiB
in12.txt AC 34 ms 63104 KiB
in13.txt AC 31 ms 63104 KiB
in14.txt AC 31 ms 63104 KiB
in15.txt AC 31 ms 63104 KiB
in16.txt AC 31 ms 63104 KiB
sample_01.txt AC 17 ms 63104 KiB
sample_02.txt AC 17 ms 63104 KiB
sample_03.txt AC 17 ms 63104 KiB
sample_04.txt AC 17 ms 63104 KiB