結果

問題 No.1199 お菓子配り-2
ユーザー ymduuymduu
提出日時 2020-08-28 22:24:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 399 ms / 1,000 ms
コード長 4,118 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 110,692 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-08 22:49:57
合計ジャッジ時間 15,657 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 99 ms
4,376 KB
testcase_04 AC 247 ms
4,384 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 14 ms
4,380 KB
testcase_07 AC 120 ms
4,376 KB
testcase_08 AC 166 ms
4,380 KB
testcase_09 AC 101 ms
4,380 KB
testcase_10 AC 25 ms
4,384 KB
testcase_11 AC 77 ms
4,380 KB
testcase_12 AC 76 ms
4,380 KB
testcase_13 AC 27 ms
4,380 KB
testcase_14 AC 23 ms
4,376 KB
testcase_15 AC 19 ms
4,380 KB
testcase_16 AC 161 ms
4,376 KB
testcase_17 AC 77 ms
4,376 KB
testcase_18 AC 168 ms
4,384 KB
testcase_19 AC 44 ms
4,380 KB
testcase_20 AC 299 ms
4,380 KB
testcase_21 AC 185 ms
4,376 KB
testcase_22 AC 97 ms
4,384 KB
testcase_23 AC 135 ms
4,380 KB
testcase_24 AC 185 ms
4,376 KB
testcase_25 AC 29 ms
4,380 KB
testcase_26 AC 210 ms
4,384 KB
testcase_27 AC 170 ms
4,380 KB
testcase_28 AC 396 ms
4,376 KB
testcase_29 AC 396 ms
4,380 KB
testcase_30 AC 394 ms
4,380 KB
testcase_31 AC 399 ms
4,376 KB
testcase_32 AC 396 ms
4,380 KB
testcase_33 AC 396 ms
4,376 KB
testcase_34 AC 396 ms
4,380 KB
testcase_35 AC 395 ms
4,384 KB
testcase_36 AC 395 ms
4,376 KB
testcase_37 AC 396 ms
4,380 KB
testcase_38 AC 397 ms
4,380 KB
testcase_39 AC 397 ms
4,384 KB
testcase_40 AC 396 ms
4,380 KB
testcase_41 AC 395 ms
4,376 KB
testcase_42 AC 396 ms
4,380 KB
testcase_43 AC 396 ms
4,376 KB
testcase_44 AC 396 ms
4,380 KB
testcase_45 AC 395 ms
4,380 KB
testcase_46 AC 395 ms
4,376 KB
testcase_47 AC 397 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <new>
#include <sstream>
#include <complex>
#define BIT(nr) (1ULL << (nr))
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	
#define LL_HALFMAX 9223372036854775807 / 2	
#define MIN -(9223372036854775807 / 2)
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

using namespace std;

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;

	// libalgo のものに追加、メンバを追加するだけなので互換性は崩さないはず、逆辺のG[e.dstの]インデックスを保持
	int rev;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
	bool operator<(const Edge& right) const {
		return dst < right.dst;
	}
};

using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph& g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph& g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};

class Vector3D {
public:
	double x, y, z;
	Vector3D(double x, double y, double z) {
		this->x = x;
		this->y = y;
		this->z = z;
	}

	Vector3D operator- (Vector3D right) {
		return Vector3D(right.x - x, right.y - y, right.z - z);
	}

	double Length() {
		return sqrtl(x * x + y * y + z * z);
	}
};

bool solve() {
	return false;
}

int mod_pow(int x, int n, int mo) {
	int res = 1;

	while (n > 0) {
		if (n & 1LL) {
			res *= x;
			res %= mo;
		}
		x = x * x % mo;
		n >>= 1;
	}

	return res;
}

#ifdef DEBUG
template <class T>ostream& operator<<(ostream& o, const vector<T>& v)
{
	o << "{"; for (int i = 0; i < (int)v.size(); i++)o << (i > 0 ? ", " : "") << v[i]; o << "}"; return o;
}
#endif // DEBUG

template <class T>ostream& operator<<(ostream& o, const vector<T>& v)
{
	for (int i = 0; i < (int)v.size(); i++)o << (i > 0 ? " " : "") << v[i]; return o;
}

int dp[1010][2];

signed main() {
	int N, M;
	cin >> N >> M;
	vector<int> a(N + 1, 0);

	REPS(i, N) {
		int su = 0;
		rep(j, M) {
			int ip;
			cin >> ip;
			su += ip;
		}
		a[i] = su;

	}
	// dp[i][j] := i(1-indexed)番目を見終わったとき、j(mod 2)回おかしを食べている時の最大スコア
	dp[0][0] = 0;
	rep(i, N) {
		// たべる
		chmax(dp[i + 1][1], dp[i][0] + a[i + 1]);
		chmax(dp[i + 1][0], dp[i][1] - a[i + 1]);

		// たべない
		chmax(dp[i + 1][0], dp[i][0]);
		chmax(dp[i + 1][1], dp[i][1]);
	}

	cout << max(dp[N][0], dp[N][1]) << "\n";

}
0