結果
| 問題 | No.783 門松計画 | 
| コンテスト | |
| ユーザー |  rickytheta | 
| 提出日時 | 2019-01-11 21:58:19 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 24 ms / 2,000 ms | 
| コード長 | 916 bytes | 
| コンパイル時間 | 1,264 ms | 
| コンパイル使用メモリ | 159,308 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-23 12:16:58 | 
| 合計ジャッジ時間 | 2,175 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |     scanf("%d%d",&n,&c);
      |     ~~~~~^~~~~~~~~~~~~~
main.cpp:13:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |     REP(i,n)scanf("%d",l+i);
      |             ~~~~~^~~~~~~~~~
main.cpp:14:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     REP(i,n)scanf("%d",w+i);
      |             ~~~~~^~~~~~~~~~
            
            ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int n,c;
int l[52], w[52];
int dp[52][4][52][52];
const int INF = 252521;
int main(){
    scanf("%d%d",&n,&c);
    REP(i,n)scanf("%d",l+i);
    REP(i,n)scanf("%d",w+i);
    REP(i,52)REP(f,4)REP(j,52)REP(k,52)dp[i][f][j][k] = -INF;
    dp[0][0][0][51] = dp[0][0][51][0] = 0;
    REP(sw,c)REP(f,4)REP(b2,52)REP(b1,52)if(dp[sw][f][b2][b1]>=0){
        REP(i,n){
            if(b2==b1 || b2==l[i] || b1==l[i])continue;
            if(b2<b1 && b1<l[i])continue;
            if(b2>b1 && b1>l[i])continue;
            int nw = sw + w[i];
            if(nw>c)continue;
            int nf = min(3,f+1);
            dp[nw][nf][b1][l[i]] = max(dp[nw][nf][b1][l[i]], dp[sw][f][b2][b1] + l[i]);
        }
    }
    int ans = 0;
    REP(i,c+1)REP(j,50)REP(k,50)ans = max(ans, dp[i][3][j+1][k+1]);
    printf("%d\n",ans);
    return 0;
}
            
            
            
        