結果
問題 |
No.1948 足し算するだけのパズルゲーム(1)
|
ユーザー |
![]() |
提出日時 | 2022-05-06 01:30:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 36 ms / 2,000 ms |
コード長 | 1,842 bytes |
コンパイル時間 | 3,772 ms |
コンパイル使用メモリ | 232,172 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-07-05 02:51:50 |
合計ジャッジ時間 | 6,360 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 27 |
ソースコード
//g++ 2.cpp -std=c++14 -O2 -I . #include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; using vvld = vector<vld>; using vst = vector<string>; using vvst = vector<vst>; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue<T,vector<T>,less<T>> #define pq_small(T) priority_queue<T,vector<T>,greater<T>> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int h,w; cin>>h>>w; vvll a(h,vll(w,0)),dp1(h,vll(w,0)),dp2(h,vll(w,0)); rep(i,0,h){ rep(j,0,w){ cin>>a[i][j]; } } dp1[0][0]=a[0][0]; rep(i,0,h){ rep(j,0,w){ if(i<h-1){ int ni=i+1,nj=j; if(dp1[i][j]>a[ni][nj]){ dp1[ni][nj]=max(dp1[ni][nj],dp1[i][j]+a[ni][nj]); } else if(ni+nj!=h+w-2){ dp2[ni][nj]=max(dp2[ni][nj],dp1[i][j]); } if(dp2[i][j]>a[ni][nj]){ dp2[ni][nj]=max(dp2[ni][nj],dp2[i][j]+a[ni][nj]); } } if(j<w-1){ int ni=i,nj=j+1; if(dp1[i][j]>a[ni][nj]){ dp1[ni][nj]=max(dp1[ni][nj],dp1[i][j]+a[ni][nj]); } else if(ni+nj!=h+w-2){ dp2[ni][nj]=max(dp2[ni][nj],dp1[i][j]); } if(dp2[i][j]>a[ni][nj]){ dp2[ni][nj]=max(dp2[ni][nj],dp2[i][j]+a[ni][nj]); } } } } if(dp1[h-1][w-1]==0&&dp2[h-1][w-1]==0){ cout<<"No\n"; } else{ cout<<"Yes\n"; } }