結果

問題 No.2150 Site Supporter
ユーザー AsahiAsahi
提出日時 2023-02-26 06:33:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 765 ms / 2,000 ms
コード長 6,500 bytes
コンパイル時間 2,705 ms
コンパイル使用メモリ 89,136 KB
実行使用メモリ 73,448 KB
最終ジャッジ日時 2023-10-11 23:52:15
合計ジャッジ時間 15,340 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,432 KB
testcase_01 AC 121 ms
55,608 KB
testcase_02 AC 124 ms
55,544 KB
testcase_03 AC 119 ms
55,696 KB
testcase_04 AC 120 ms
55,800 KB
testcase_05 AC 120 ms
55,776 KB
testcase_06 AC 120 ms
55,580 KB
testcase_07 AC 119 ms
55,572 KB
testcase_08 AC 312 ms
60,704 KB
testcase_09 AC 653 ms
71,456 KB
testcase_10 AC 511 ms
65,728 KB
testcase_11 AC 634 ms
71,596 KB
testcase_12 AC 485 ms
63,596 KB
testcase_13 AC 349 ms
63,452 KB
testcase_14 AC 123 ms
55,600 KB
testcase_15 AC 120 ms
55,488 KB
testcase_16 AC 119 ms
55,684 KB
testcase_17 AC 765 ms
72,636 KB
testcase_18 AC 479 ms
63,592 KB
testcase_19 AC 275 ms
60,480 KB
testcase_20 AC 629 ms
66,360 KB
testcase_21 AC 240 ms
59,892 KB
testcase_22 AC 679 ms
73,448 KB
testcase_23 AC 120 ms
55,440 KB
testcase_24 AC 119 ms
55,560 KB
testcase_25 AC 121 ms
55,700 KB
testcase_26 AC 124 ms
55,696 KB
testcase_27 AC 545 ms
65,912 KB
testcase_28 AC 573 ms
65,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.Pattern;

class Main{

    static void solve(){

        int n = ni();
        long k = nl(), x = nl();
        long [][] dp = new long[n+1][2];
        long [] A = LongArray(n);
        for(long [] v : dp) Arrays.fill(v,Lnf);
        dp[0][0] = 0;
        dp[0][1] = 0;
        for(int i=0;i<n;i++) {
            for(int j=0;j<2;j++) {
                if(j == 0) {
                    dp[i+1][j] = Math.min(dp[i+1][j],dp[i][j] + A[i]);
                    dp[i+1][j+1] = Math.min(dp[i+1][j+1],dp[i][j] + k + x);
                }
                if(j == 1 && i != 0) {
                    dp[i+1][j] = Math.min(dp[i+1][j],dp[i][j] + k);
                    dp[i+1][j-1] = Math.min(dp[i+1][j-1],dp[i][j] + A[i]);
                }
            }
        }
        output.print(Math.min(dp[n][0],dp[n][1]));
    }

    /* 関数 */



    /* 定数 */

    static PrintWriter output;
    static Scanner sc;
    static int  Inf = 1010101010; 
    static long Lnf = (long)1e18;
    static final long mod = 1000000007;
    static final long MOD = 998244353 ;

    /* 長いやつ  */

    static String cut(String S , int start, int end) { return S.substring(start,end);}
    static char cut(String S , int start) { return S.charAt(start);}
    static String tos(int val) { return Integer.toString(val);}
    static String tos(long val) { return Long.toString(val);}
    static int toi(String S) { return Integer.parseInt(S);}
    static long tol(String S) { return Long.parseLong(S);}

    /* 実装が面倒なやつ */

    public static long factorial(long n){
        return n <= 0 ? 1 : n * factorial(n-1);
    }

    public static int digits(long n) {
        return String.valueOf(n).length();
    }

    static boolean kaibun(String S) {
        StringBuilder s = new StringBuilder();
        s.append(S);
        return s.reverse().toString().equals(S);
    }

    static boolean isNumber(String value) {
        boolean result = false;
        if (value != null) {
            Pattern pattern = Pattern.compile("^[0-9]+$|-[0-9]+$");
            result = pattern.matcher(value).matches();
        }
        return result;
    }

    static Map<Integer,Integer> counter(int [] A) {
        HashMap<Integer,Integer> count = new HashMap<>();
        for(int i=0;i<A.length;i++) {
            if(!count.containsKey(A[i])) count.put(A[i],1);
            else count.put(A[i],count.get(A[i])+1);
        }
        return count;
    }

    static Map<Long,Integer> counter(long [] A) {
        HashMap<Long,Integer> count = new HashMap<>();
        for(int i=0;i<A.length;i++) {
            if(!count.containsKey(A[i])) count.put(A[i],1);
            else count.put(A[i],count.get(A[i])+1);
        }
        return count;
    }

    /*入出力端折るやつ*/

    static int ni(){ return Integer.parseInt(sc.next());}
    static long nl(){ return Long.parseLong(sc.next());}
    static double nd(){ return Double.parseDouble(sc.next());}
    static String ns(){ return sc.next();}
    static BigInteger bi(){ return sc.nextBigInteger();}
    static BigDecimal bd(){ return sc.nextBigDecimal();}
    
    static int [] IntArray(int n) {
        int [] Array = new int[n];
        for(int i=0;i<n;i++) Array[i] = ni();
        return Array;
    }
    static int [][] IntArray(int n , int m) {
        int [][] Array = new int[n][m];
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) Array[i][j] = ni();
        return Array;
    }
    static long [] LongArray(int n) {
        long [] Array = new long[n];
        for(int i=0;i<n;i++) Array[i] = nl();
        return Array;
    }
    static long [][] LongArray(int n , int m) {
        long [][] Array = new long[n][m];
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) Array[i][j] = nl();
        return Array;
    }
    static double [] DoubleArray(int n) {
        double [] Array = new double[n];
        for(int i=0;i<n;i++) Array[i] = nd();
        return Array;
    }
    static double [][] DoubleArray(int n , int m) {
        double [][] Array = new double[n][m];
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) Array[i][j] = nd();
        return Array;
    }
    static String [] StringArray(int n) {
        String [] Array = new String[n];
        for(int i=0;i<n;i++) Array[i] = ns();
        return Array;
    }
    static String [][] StringArray(int n , int m) {
        String [][] Array = new String[n][m];
        for(int i=0;i<n;i++) for(int j=0;j<m;j++) Array[i][j] = ns();
        return Array;
    }
    static char [] CharArray(int n) {
        char [] Array = new char[n];
        String S = ns();
        for(int i=0;i<n;i++) Array[i] = S.charAt(i);
        return Array;
    }
    static char [][] CharArray(int n,int m) {
        char [][] Array = new char[n][m];
        for(int i=0;i<n;i++) {
            String S = ns();
            for(int j=0;j<m;j++) Array[i][j] = S.charAt(j);
        }
        return Array;
    }
    static void PrintArray(int [] A) {
        for(int i=0;i<A.length;i++) output.print(A[i]+" ");
        output.println();
    }
    static void PrintArray(long [] A) {
        for(int i=0;i<A.length;i++) output.print(A[i]+" ");
        output.println();
    }
    static void PrintArray(double [] A) {
        for(int i=0;i<A.length;i++) output.print(A[i]+" ");
        output.println();
    }
    static void PrintArray(boolean [] A) {
        for(int i=0;i<A.length;i++) output.print(A[i]+" ");
        output.println();
    }
    static void PrintArray(int [][] A) {
        for(int i=0;i<A.length;i++) {
            for(int j=0;j<A[i].length;j++) {
                if(A[i][j] == Inf) output.print("X ");
                else output.print(A[i][j]+" ");
            }
            output.println();
        }
    }
    static void PrintArray(long [][] A) {
        for(int i=0;i<A.length;i++) {
            for(int j=0;j<A[i].length;j++) {
                if(A[i][j] == Lnf) output.print("X ");
                else output.print(A[i][j]+" ");
            }
            output.println();
        }
    }
    static void PrintArray(boolean [][] A) {
        for(int i=0;i<A.length;i++) {
            for(int j=0;j<A[i].length;j++) {
                output.print(A[i][j]?"O":"X");
            }
            output.println();
        }
    }
    public static void main(String[] args){
        output = new PrintWriter(System.out);
        sc = new Scanner(System.in);
        solve();
        output.flush();
    }
}

0