結果

問題 No.2386 Udon Coupon (Easy)
ユーザー yurina256yurina256
提出日時 2023-07-21 21:50:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 7,178 bytes
コンパイル時間 1,795 ms
コンパイル使用メモリ 182,068 KB
実行使用メモリ 4,872 KB
最終ジャッジ日時 2023-10-21 21:48:13
合計ジャッジ時間 3,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 3 ms
4,872 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,872 KB
testcase_14 AC 3 ms
4,608 KB
testcase_15 AC 3 ms
4,872 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,608 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,608 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 2 ms
4,608 KB
testcase_27 AC 3 ms
4,872 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 3 ms
4,872 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 3 ms
4,872 KB
testcase_37 AC 3 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define length size()
#define int long long
#define ll long long
constexpr ll inf = 1001001001001001001ll;
constexpr ll mod = 1000000007;
constexpr double pi = 3.141592653589793;
//小数出力
//cout << std::setprecision(12);
//imos
void to_ruiseki(vector<int> &vec){
    for(int i=1;i<vec.size();i++){
        vec[i] += vec[i-1];
    }
}
void to_2druiseki(vector<vector<int>> &vec){
    rep(i,vec.size()){
        rep(j,vec[0].size()){
            int s = 0;
            if(i!=0) s += vec[i-1][j];
            if(j!=0) s += vec[i][j-1];
            if(i!=0 && j!=0) s -= vec[i-1][j-1];
            s += vec[i][j];
            vec[i][j] = s;
        }
    }
}
//modpow(a,n,mod)
int modpow(int a, int n, int mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//素因数分解
vector<pair<int,int>> p_fact(int N) {
    vector<pair<int,int>> res;
    for (int a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        int ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
//ctoi
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default :  throw runtime_error("hoge");
  }
}
//max
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
//min
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//print
void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}
//join
template<typename T> string join(vector<T> &vec ,const string &sp){
    int si = vec.length;
    if(si==0){
        return "";
    }else{
        stringstream ss;
        rep(i,si-1){
            ss << vec[i] << sp;
        }
        ss << vec[si - 1];
        return ss.str();
    }
}
//木の直径
int tree_diameter(vector<vector<int>> &vec){
    //0-indexed
    queue<pair<int,int>> que;
    vector<bool> is_searched(vec.size(),false);
    que.push(make_pair(0,0));
    int max_d = 0;
    int max_e = 0;
    while(!que.empty()){
        int e = que.front().first;
        int distance = que.front().second;
        is_searched[e] = true;
        if(max_d<distance){
            max_d = distance;
            max_e = e;
        }
        que.pop();
        rep(i,vec[e].size()){
            if(!is_searched[vec[e][i]]){
                que.push( make_pair( vec[e][i], distance + 1 ) );
            }
        }
    }
    fill(is_searched.begin(),is_searched.end(),false);
    que.push(make_pair(max_e,0));
    max_d = 0;
    max_e = 0;
    
    while(!que.empty()){
        int e = que.front().first;
        int distance = que.front().second;
        is_searched[e] = true;
        if(max_d<distance){
            max_d = distance;
            max_e = e;
        }
        que.pop();
        rep(i,vec[e].size()){
            if(!is_searched[vec[e][i]]){
                que.push( make_pair( vec[e][i], distance + 1 ) );
            }
        }
    }
    return max_d;
}
//uf 根:root(x) 判定:issame(x,y) 結合:unite(x,y) 大きさ:size(x)
int getlongpath(vector<vector<int>> &vec,int st){
    queue<pair<int,int>> que;
    vector<bool> is_searched(vec.size(),false);
    is_searched[st] = true;
    que.push(make_pair(st,0));
    int max_d = 0;
    int max_e = 0;
    while(!que.empty()){
        int e = que.front().first;
        int distance = que.front().second;
        if(max_d<distance){
            max_d = distance;
            max_e = e;
        }
        que.pop();
        rep(i,vec[e].size()){
            if(!is_searched[vec[e][i]]){
                que.push( make_pair( vec[e][i], distance + 1 ) );
                is_searched[vec[e][i]] = true;
            }
        }
    }
    fill(is_searched.begin(),is_searched.end(),false);
    que.push(make_pair(max_e,0));
    return max_d;
}
struct UnionFind {
    vector<int> par, rank, siz;

    // 構造体の初期化
    UnionFind(int n) : par(n,-1), rank(n,0), siz(n,1) { }

    // 根を求める
    int root(int x) {
        if (par[x]==-1) return x; // x が根の場合は x を返す
        else return par[x] = root(par[x]); // 経路圧縮
    }

    // x と y が同じグループに属するか (= 根が一致するか)
    bool issame(int x, int y) {
        return root(x)==root(y);
    }

    // x を含むグループと y を含むグループを併合する
    bool unite(int x, int y) {
        int rx = root(x), ry = root(y); // x 側と y 側の根を取得する
        if (rx==ry) return false; // すでに同じグループのときは何もしない
        // union by rank
        if (rank[rx]<rank[ry]) swap(rx, ry); // ry 側の rank が小さくなるようにする
        par[ry] = rx; // ry を rx の子とする
        if (rank[rx]==rank[ry]) rank[rx]++; // rx 側の rank を調整する
        siz[rx] += siz[ry]; // rx 側の siz を調整する
        return true;
    }

    // x を含む根付き木のサイズを求める
    int size(int x) {
        return siz[root(x)];
    }
};
    int is_searched[16][16];
    int is_searched_now[16][16];
    char vec[16][16];
    int max_ans = -1;
    int h,w;
void saiki(int x,int y,int s){
        is_searched_now[x][y] = true;
        // << x << " " << y << " " << s << endl;
        if(x>0){
            if(!is_searched_now[x-1][y] && vec[x-1][y] != '#'){
                saiki(x-1,y,s+1);
            }
            if(vec[x-1][y] == 'g' && s >=2) chmax(max_ans,s+1);
        }
        if(x<h-1){
            if(!is_searched_now[x+1][y] && vec[x+1][y] != '#'){
                saiki(x+1,y,s+1);
            }
            if(vec[x+1][y] == 'g' && s >=2) chmax(max_ans,s+1);
        }
        if(y>0){
            if(!is_searched_now[x][y-1] && vec[x][y-1] != '#'){
                saiki(x,y-1,s+1);
            }
            if(vec[x][y-1] == 'g' && s >=2) chmax(max_ans,s+1);
        }
        if(y<w-1){
            if(!is_searched_now[x][y+1] && vec[x][y+1] != '#'){
                saiki(x,y+1,s+1);
            }
            if(vec[x][y+1] == 'g' && s >=2) chmax(max_ans,s+1);
        }
        //is_searched[x][y] = true;
        is_searched_now[x][y] = false;
    }
signed main(void){
    int n,a,b,c;
    cin >> n >> a >> b >> c;
    vector<int> dp(n+1,0);
    dp[0] = 0;
    for(int i=1;i<=n;i++){
        dp[i] = max(dp[i-1],max((i>=3)?dp[i-3]+a:0,max((i>=5)?dp[i-5]+b:0,(i>=10)?dp[i-10]+c:0)));
    }
    //print(join(dp," "));
    print(dp[n]);
}
0