結果

問題 No.1199 お菓子配り-2
ユーザー suzuken_wsuzuken_w
提出日時 2020-08-28 23:19:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 1,000 ms
コード長 1,376 bytes
コンパイル時間 2,931 ms
コンパイル使用メモリ 211,480 KB
実行使用メモリ 20,120 KB
最終ジャッジ日時 2024-04-26 15:10:31
合計ジャッジ時間 10,370 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 39 ms
10,216 KB
testcase_04 AC 92 ms
16,168 KB
testcase_05 AC 4 ms
6,944 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 46 ms
10,148 KB
testcase_08 AC 62 ms
11,316 KB
testcase_09 AC 38 ms
9,492 KB
testcase_10 AC 11 ms
6,940 KB
testcase_11 AC 30 ms
8,004 KB
testcase_12 AC 30 ms
7,092 KB
testcase_13 AC 11 ms
6,944 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 9 ms
6,944 KB
testcase_16 AC 59 ms
10,952 KB
testcase_17 AC 30 ms
9,428 KB
testcase_18 AC 64 ms
14,820 KB
testcase_19 AC 18 ms
8,628 KB
testcase_20 AC 112 ms
17,056 KB
testcase_21 AC 71 ms
15,664 KB
testcase_22 AC 40 ms
13,012 KB
testcase_23 AC 54 ms
14,080 KB
testcase_24 AC 71 ms
15,108 KB
testcase_25 AC 11 ms
6,944 KB
testcase_26 AC 78 ms
13,108 KB
testcase_27 AC 63 ms
11,204 KB
testcase_28 AC 145 ms
19,984 KB
testcase_29 AC 146 ms
19,896 KB
testcase_30 AC 144 ms
19,924 KB
testcase_31 AC 145 ms
19,988 KB
testcase_32 AC 144 ms
19,988 KB
testcase_33 AC 144 ms
20,060 KB
testcase_34 AC 143 ms
20,012 KB
testcase_35 AC 145 ms
19,936 KB
testcase_36 AC 145 ms
19,980 KB
testcase_37 AC 144 ms
19,992 KB
testcase_38 AC 143 ms
19,936 KB
testcase_39 AC 144 ms
19,900 KB
testcase_40 AC 145 ms
19,988 KB
testcase_41 AC 144 ms
19,940 KB
testcase_42 AC 142 ms
19,916 KB
testcase_43 AC 143 ms
19,988 KB
testcase_44 AC 144 ms
19,984 KB
testcase_45 AC 147 ms
19,980 KB
testcase_46 AC 144 ms
19,964 KB
testcase_47 AC 147 ms
20,120 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