結果

問題 No.1199 お菓子配り-2
ユーザー suzuken_wsuzuken_w
提出日時 2020-08-28 23:19:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 1,000 ms
コード長 1,376 bytes
コンパイル時間 2,240 ms
コンパイル使用メモリ 214,584 KB
実行使用メモリ 19,992 KB
最終ジャッジ日時 2023-08-08 22:59:48
合計ジャッジ時間 9,526 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 34 ms
10,616 KB
testcase_04 AC 81 ms
16,336 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 40 ms
10,956 KB
testcase_08 AC 55 ms
11,860 KB
testcase_09 AC 34 ms
8,212 KB
testcase_10 AC 11 ms
6,420 KB
testcase_11 AC 27 ms
7,784 KB
testcase_12 AC 25 ms
7,540 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 9 ms
6,608 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 53 ms
11,724 KB
testcase_17 AC 28 ms
10,280 KB
testcase_18 AC 55 ms
14,664 KB
testcase_19 AC 16 ms
9,360 KB
testcase_20 AC 95 ms
16,948 KB
testcase_21 AC 64 ms
15,564 KB
testcase_22 AC 35 ms
13,104 KB
testcase_23 AC 46 ms
13,832 KB
testcase_24 AC 60 ms
14,804 KB
testcase_25 AC 11 ms
6,468 KB
testcase_26 AC 70 ms
13,036 KB
testcase_27 AC 54 ms
12,048 KB
testcase_28 AC 121 ms
19,732 KB
testcase_29 AC 121 ms
19,864 KB
testcase_30 AC 120 ms
19,784 KB
testcase_31 AC 122 ms
19,856 KB
testcase_32 AC 120 ms
19,800 KB
testcase_33 AC 124 ms
19,732 KB
testcase_34 AC 120 ms
19,728 KB
testcase_35 AC 125 ms
19,992 KB
testcase_36 AC 125 ms
19,784 KB
testcase_37 AC 128 ms
19,788 KB
testcase_38 AC 126 ms
19,880 KB
testcase_39 AC 126 ms
19,884 KB
testcase_40 AC 122 ms
19,744 KB
testcase_41 AC 125 ms
19,856 KB
testcase_42 AC 128 ms
19,732 KB
testcase_43 AC 124 ms
19,736 KB
testcase_44 AC 127 ms
19,784 KB
testcase_45 AC 125 ms
19,856 KB
testcase_46 AC 127 ms
19,716 KB
testcase_47 AC 131 ms
19,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll dp[1005][1005];
bool used[1005][1005]={};
int main(){
  int n,m;
  cin>>n>>m;
  V<V<ll>> a(n,V<ll>(m));
  V<ll> res(n);
  for(int i=0;i<n;i++){
      ll sum=0;
      ll val;
      for(int j=0;j<m;j++){
          cin>>val;
          sum+=val;
      }
      res[i]=sum;
  }
  for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)dp[i][j]=-inf;
  dp[0][0]=0;
  used[0][0]=true;
  for(int i=0;i<n;i++){
      for(int j=n-1;j>=0;j--){
          if(!used[i][j])continue;
           chmax(dp[i+1][j+1],dp[i][j]+res[i]*(j%2==0?1ll:-1ll));
           used[i+1][j+1]=true;
           chmax(dp[i+1][j],dp[i][j]);
           used[i+1][j]=true;
      }
  }
  ll ans=0;
  for(int i=0;i<=n;i++)chmax(ans,dp[n][i]);
  cout<<ans<<"\n";
}
0