結果

問題 No.10 +か×か
ユーザー ichyoichyo
提出日時 2015-04-08 00:51:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 1,920 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 145,184 KB
実行使用メモリ 5,120 KB
最終ジャッジ日時 2023-08-21 06:12:06
合計ジャッジ時間 1,943 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,912 KB
testcase_01 AC 2 ms
4,920 KB
testcase_02 AC 3 ms
4,920 KB
testcase_03 AC 20 ms
4,916 KB
testcase_04 AC 11 ms
4,968 KB
testcase_05 AC 5 ms
4,924 KB
testcase_06 AC 23 ms
4,968 KB
testcase_07 AC 11 ms
4,968 KB
testcase_08 AC 8 ms
4,928 KB
testcase_09 AC 8 ms
4,928 KB
testcase_10 AC 3 ms
5,032 KB
testcase_11 AC 3 ms
5,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

class range {
    struct Iterator {
        int val, inc;
        int operator*() {return val;}
        bool operator!=(Iterator& rhs) {return val < rhs.val;}
        void operator++() {val += inc;}
    };
    Iterator i, n;
    public:
    range(int e) : i({0, 1}), n({e, 1}) {}
    range(int b, int e) : i({b, 1}), n({e, 1}) {}
    range(int b, int e, int inc) : i({b, inc}), n({e, inc}) {}
    Iterator& begin() {return i;}
    Iterator& end() {return n;}
};

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

typedef unsigned long long ULL;
int main(){
    iostream_init();

    int N, T;
    while(cin >> N >> T){
        T++;
        ULL dp[100010] = {};
        memset(dp, -1, sizeof(dp));
        N--;

        int INI;
        cin >> INI;
        dp[INI] = 0;

        REP(i, N) {
            int A;
            cin >> A;

            ULL next[100010] = {};
            memset(next, -1, sizeof(next));

            REP(j, T) if(dp[j] != ULLONG_MAX) {
                int nj = j + A;
                if(nj < T) {
                    next[nj] = min(next[nj], dp[j] << 1);
                }
            }
            REP(j, T) if(dp[j] != ULLONG_MAX) {
                int nj = j * A;
                if(nj < T) {
                    next[nj] = min(next[nj], (dp[j] << 1) | 1);
                }
            }
            memcpy(dp, next, sizeof(dp));
        }

        REP(i, N) cout << ((dp[T-1] >> (N-1-i) & 1) ? "*" : "+");
        cout << endl;

    }
    return 0;
}

/* vim:set foldmethod=marker: */
0