結果

問題 No.2196 Pair Bonus
ユーザー AsahiAsahi
提出日時 2023-10-03 14:20:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 12,137 bytes
コンパイル時間 4,441 ms
コンパイル使用メモリ 93,392 KB
実行使用メモリ 60,444 KB
最終ジャッジ日時 2024-07-26 14:07:40
合計ジャッジ時間 7,505 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
37,100 KB
testcase_01 AC 55 ms
37,108 KB
testcase_02 AC 55 ms
37,060 KB
testcase_03 AC 239 ms
60,444 KB
testcase_04 AC 250 ms
60,324 KB
testcase_05 AC 63 ms
37,604 KB
testcase_06 AC 62 ms
37,836 KB
testcase_07 AC 61 ms
37,764 KB
testcase_08 AC 114 ms
44,464 KB
testcase_09 AC 241 ms
59,596 KB
testcase_10 AC 209 ms
52,224 KB
testcase_11 AC 134 ms
46,108 KB
testcase_12 AC 232 ms
56,816 KB
testcase_13 AC 73 ms
37,772 KB
testcase_14 AC 99 ms
41,924 KB
testcase_15 AC 77 ms
37,976 KB
testcase_16 AC 241 ms
59,484 KB
testcase_17 AC 79 ms
38,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*; 
import java.io.*;

class Main implements Runnable
{ 
    //その時の思考をここに書く
    /*
     *  
     */

    void solve()
    {           
        int N = in.nextInt();
        long [] A = in.LongArray(2 * N);
        long [] B = in.LongArray(2 * N);
        long [] X = in.LongArray(N);
        long [] Y = in.LongArray(N);
        long [][] dp = new long[2 * N + 1][2];
        for(int i = 0 ; i < 2 * N ; i ++ )
        {
            if(i % 2 == 0)
            {
                dp[i + 1][0] = max(dp[i + 1][0] , dp[i][0] + A[i] + X[i / 2]);
                dp[i + 1][1] = max(dp[i + 1][1] , dp[i][1] + B[i] + X[i / 2]);
                dp[i + 1][1] = max(dp[i + 1][1] , dp[i][0] + A[i] + Y[i / 2]);
                dp[i + 1][0] = max(dp[i + 1][0] , dp[i][1] + B[i] + Y[i / 2]);
            }
            else
            {
                dp[i + 1][0] = max(dp[i + 1][0] , dp[i][0] + A[i]);
                dp[i + 1][1] = max(dp[i + 1][1] , dp[i][1] + B[i]);
                dp[i + 1][1] = max(dp[i + 1][1] , dp[i][0] + A[i]);
                dp[i + 1][0] = max(dp[i + 1][0] , dp[i][1] + B[i]);
            }
        }
        long ans = 0 ;
        ans = max(dp[2 * N][0] , dp[2 * N][1]);
        out.print(ans);
    }      
       
    public static void main(String[] args) 
    {
        new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start(); 
    }

    public void run() 
    {   
        solve();
        out.flush();
    }

    record ip(int fi , int se) { public String toString() { return fi +" "+ se ;} }
    record lp(long fi , long se) { public String toString() { return fi +" "+ se ;} }
    public double dist(lp p1 , lp p2) { return Math.sqrt((p1.fi - p2.fi) * (p1.fi - p2.fi) + (p1.se - p2.se) * (p1.se - p2.se)); }
    public int max(int ... a) { int max = -1 ; for(int p : a) max = Math.max(max , p); return max; }
    public int min(int ... a) { int min = Integer.MAX_VALUE ; for(int p : a) min = Math.min(min , p); return min; }
    public long max(long ... a) { long max = -1 ; for(long p : a) max = Math.max(max , p); return max; }
    public long min(long ... a) { long min = Long.MAX_VALUE ; for(long p : a) min = Math.min(min , p); return min; }
    public int sum(int ... a) { int sum = 0 ; for(int p : a) sum += p ; return sum ;}
    public long sum(long ... a) { long sum = 0 ; for(long p : a) sum += p ; return sum ;}
    public int abs(int a , int b) { return (int) Math.abs(a - b) ; }
    public long abs(long a , long b) { return (long) Math.abs(a - b) ; }
    public int pow(int a , int b) { return (int) Math.pow(a , b) ; }
    public long pow(long a , long b) { return (long) Math.pow(a , b) ; }
    public long rec(long a) { return a == 1 ? 1 : a * rec(a - 1); }
    public long [] recmod(int a , long MOD) { long [] recMod = new long[1 << 17] ; recMod[1] = 1 ; for(int i = 2 ; i < (1 << 17) ; i ++ ) recMod[i] = (recMod[i - 1] * i) % MOD9; return recMod; }
    public int [] rev(int [] a) { int [] r = new int[a.length] ; int idx = a.length ; for(int p : a) r[--idx] = p ; return r ; }
    public long [] rev(long [] a) { long [] r = new long[a.length] ; int idx = a.length ; for(long p : a) r[--idx] = p ; return r ; }
    public int gcd(int a, int b) { return b == 0 ? a: gcd(b, a % b); }
    public int lcm(int a, int b) { return a / gcd(a, b) * b; }
    public long gcd(long a, long b) { return b == 0 ? a: gcd(b, a % b); }
    public long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public int gcd(int ... a) { int gcd = 0 ; for(int p : a) gcd = gcd(gcd , p) ; return gcd ; }
    public long gcd(long ... a) { long gcd = 0L ; for(long p : a) gcd = gcd(gcd , p) ; return gcd ; }
    public int lcm(int ... a) { int lcm = 1 ; for(int p : a) lcm = lcm(lcm , p) ; return lcm ; }
    public long lcm(long ... a) { long lcm = 1 ; for(long p : a) lcm = lcm(lcm , p) ; return lcm ; }
    public char upper(char c) { return (char)('A' + (c - 'a')); }
    public char lower(char c) { return (char)('a' + (c - 'A')); }
    public String yn(boolean a) { return a ? yes : no ; }
    public String rev(String a) { return new StringBuilder(a).reverse().toString(); }
    public void fill(int [] a , int v) { Arrays.fill(a , v); }
    public void fill(long [] a , long v) { Arrays.fill(a , v); }
    public void fill(int [][] a , int v) { for(int [] aa : a) fill(aa , v) ; }
    public void fill(long [][] a , long v) { for(long [] aa : a) fill(aa , v) ; }
    public void fill(int [][][] a , int v) { for(int [][] aa : a) fill(aa , v); }
    public void fill(long [][][] a , long v) { for(long [][] aa : a) fill(aa , v); }
    public int [] copy(int [] a) { return Arrays.copyOf(a , a.length); } 
    public long [] copy(long [] a) { return Arrays.copyOf(a , a.length); } 
    public String bin(int a , int len) { String b = Integer.toBinaryString(a); while(b.length() < len) b = "0" + b ; return b ; }
    public void debug(int [] a) { out.println(Arrays.toString(a)); fl();}
    public void debug(long [] a) { out.println(Arrays.toString(a)); fl();}
    public void debug(double [] a) { out.println(Arrays.toString(a)); fl();}
    public void debug(String [] a) { out.println(Arrays.toString(a)); fl();}
    public void debug(char [] a) { out.println(Arrays.toString(a)); fl();}
    public void debug(boolean [] a) { char [] c = conv(a); debug(c); fl();}
    public void debug(int [][] a) { for(int i = 0 ; i < a.length ; i ++ ) out.println(Arrays.toString(a[i])); fl();}
    public void debug(long [][] a) { for(int i = 0 ; i < a.length ; i ++ ) out.println(Arrays.toString(a[i])); fl();}
    public void debug(double [][] a) { for(int i = 0 ; i < a.length ; i ++ ) out.println(Arrays.toString(a[i])); fl();}
    public void debug(String [][] a) { for(int i = 0 ; i < a.length ; i ++ ) out.println(Arrays.toString(a[i])); fl();}
    public void debug(char [][] a) { for(int i = 0 ; i < a.length ; i ++ ) out.println(Arrays.toString(a[i])); fl();}
    public void debug(boolean [][] a) { char [][] c = new char [a.length][a[0].length] ; for(int i = 0 ; i < a.length ; i ++ ) c[i] = conv(a[i]) ; debug(c); fl();}
    private char [] conv(boolean [] a) { char [] c = new char[a.length] ; for(int i = 0 ; i < a.length ; i ++ ) c[i] = a[i] ? 'O' : 'X' ; return c ; }
    private void fl() { out.flush(); }

    PrintWriter out = new PrintWriter(System.out);
    In in = new In();
    static final long MOD7 = 1000000007;
    static final long MOD9 = 998244353;
    static final int  inf = (1  << 30);
    static final long lnf = (1L << 60);
    final String yes = "Yes";
    final String no  = "No" ;
    final char [] dir = {'U','R','D','L'};
    final int [] dy4 = {-1,0,1,0};
    final int [] dx4 = {0,1,0,-1};
    final int [] dy8 = {-1,-1,-1,0,1,1,1,0};
    final int [] dx8 = {-1,0,1,1,1,0,-1,-1};

}

class mint {

    private long value;
    private final long MOD;

    mint(long value, long MOD) 
    {
        this.MOD = MOD;
        this.value = (value % MOD + MOD) % MOD;
    }

    public mint add(mint other) 
    {
        return new mint((this.value + other.value) % MOD, MOD);
    }

    public mint subtract(mint other) 
    {
        return new mint((this.value - other.value + MOD) % MOD, MOD);
    }

    public mint multiply(mint other) 
    {
        return new mint((this.value * other.value) % MOD, MOD);
    }

    public mint inverse() 
    {
        return new mint(pow(this.value, MOD - 2), MOD);
    }

    public mint divide(mint other) 
    {
        return this.multiply(other.inverse());
    }

    private long pow(long a, long b) 
    {
        long res = 1;
        while (b > 0) 
        {
            if ((b & 1) != 0) res = (res * a) % MOD;
            a = (a * a) % MOD;
            b >>= 1;
        }
        return res;
    }

    public long getVal() 
    {
        return value;
    }

    @Override
    public String toString() 
    {
        return String.valueOf(value);
    }
}

class In
{

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { 
        if (hasNextByte()) return buffer[ptr++]; else return -1;
    }

    private static boolean isPrintableChar(int c) { 
        return 33 <= c && c <= 126;
    }

    private  boolean hasNext() { 
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++; 
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { 
        return Double.parseDouble(next());
    }

    public char nextChar() {
        return next().charAt(0);
    }
    
    public int [] IntArray(int n) {
        final int [] Array = new int [n];
        for(int i = 0 ; i < n ; i ++ ) {
            Array[i] = nextInt();
        }
        return Array;
    }
    public int [][] IntArray(int n , int m) {
        final int [][] Array = new int [n][m];
        for(int i = 0 ; i < n ; i ++ ) {
            Array[i] = IntArray(m);
        }
        return Array;
    }   
    public long [] LongArray(int n) {
        final long [] Array = new long [n];
        for(int i = 0 ; i < n ; i ++ ) {
            Array[i] = nextLong();
        }
        return Array;
    }
    public long [][] LongArray(int n , int m) {
        final long [][] Array = new long [n][m];
        for(int i = 0 ; i < n ; i ++ ) {
            Array[i] = LongArray(m);
        }
        return Array;
    }
    public String [] StringArray(int n) {
        final String [] Array = new String [n];
        for(int i = 0 ; i < n ; i ++ ) {
            Array[i] = next();
        }
        return Array;
    }
    public char [] CharArray(int n) {
        final char [] Array = new char[n];
        for(int i = 0 ; i < n ; i ++ ) {
            Array[i] = next().charAt(0);
        }
        return Array;
    }
    public char [][] CharArray(int n , int m) {
        final char [][] Array = new char [n][m];
        for(int i = 0 ; i < n ; i ++ ) {
            Array[i] = next().toCharArray();
        }
        return Array;
    }
    public char [][] CharArray2(int n , int m) {
        final char [][] Array = new char [n][m];
        for(int i = 0 ; i < n ; i ++ ) {
            for(int j = 0 ; j < m ; j ++ ) {
                Array[i][j] = next().charAt(0);
            }
        }
        return Array;
    }
    public List<Integer> [] Graph(int n) {
        @SuppressWarnings("unchecked")
        List<Integer> [] G = new ArrayList[n];
        for(int i = 0 ; i < n ; i ++ ) {
            G[i] = new ArrayList<>();
        }
        return G ;
    }
}
0