結果

問題 No.542 1円玉と5円玉
ユーザー cwwcww
提出日時 2017-08-28 22:56:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,066 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 171,388 KB
実行使用メモリ 394,496 KB
最終ジャッジ日時 2024-04-24 01:58:45
合計ジャッジ時間 6,012 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 279 ms
394,368 KB
testcase_01 AC 280 ms
394,368 KB
testcase_02 AC 283 ms
394,368 KB
testcase_03 AC 275 ms
394,368 KB
testcase_04 AC 278 ms
394,240 KB
testcase_05 AC 286 ms
394,240 KB
testcase_06 AC 278 ms
394,368 KB
testcase_07 AC 277 ms
394,368 KB
testcase_08 AC 281 ms
394,368 KB
testcase_09 AC 283 ms
394,368 KB
testcase_10 AC 284 ms
394,496 KB
testcase_11 AC 290 ms
394,368 KB
testcase_12 AC 287 ms
394,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define SORT(x) sort((x).begin(),(x).end(),greater<int>())
using LL=long long;
using ULL=unsigned long long;
using PII=pair<int,int>;
const int INF = numeric_limits<int>::max();
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
vector<vector<int>> memo( 10000 + 1, vector<int>( 10000 + 1, -1 ) );
int A, B;
vector<int> vc;
set<int> st;
bool dfs( int i, int sum )
{
    if( sum != 0 )
    {
        st.emplace( sum );
    }
    int &res = memo[ i ][ sum ];
    if( res != -1 )
    {
        return res;
    }
    if( i == 0 )
    {
        return 0;
    }
    return ( res = dfs( i - 1, sum ) || dfs( i - 1, sum - vc[ i - 1 ] ) );
}
int main()
{
    cin >> A >> B;
    REP( i, A )
    {
        vc.emplace_back( 1 );
    }
    REP( i, B )
    {
        vc.emplace_back( 5 );
    }
    dfs( A + B, A * 1 + B * 5 );
    for( auto &x : st )
    {
        cout << x << endl;
    }
	return 0;
}
0