Submission #575930


Source Code Expand

Copy
import java.util.*;

public class Main
{
    private final static Main main = new Main();

    public static void main(String[] args)
    {
        main.contest();
    }

    private void contest()
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] list = new int[n];
        for(int i=0; i<n; ++i)
        {
            list[i] = sc.nextInt();
        }
        System.out.println(solve(n, list));
    }

    private int solve(int n, int[] list)
    {
        int max = Integer.MIN_VALUE;
        for(int t=0; t<n; ++t)
        {
            int a = aoki(n, list, t);
            int s = Math.min(t, a);
            int e = Math.max(t, a);
            int p = 0;
            for(int i=0; i<=e-s; ++i)
            {
                if(i%2 == 0)
                {
                    p += list[i+s];
                }
            }
            max = Math.max(max, p);
        }
        return max;
    }

    private int aoki(int n, int[] list, int t)
    {
        int a = -1;
        int max = Integer.MIN_VALUE;
        for(int i=n-1; i>=0; --i)
        {
            if(i == t)
            {
                continue;
            }
            int s = Math.min(i, t);
            int e = Math.max(i, t);
            int p = 0;
            for(int j=0; j<=e-s; ++j)
            {
                if(j%2 == 1)
                {
                    p += list[j+s];
                }
            }
            if(max <= p)
            {
                max = p;
                a = i;
            }
        }
        return a;
    }
}

Submission Info

Submission Time
Task C - 数列ゲーム
User poxoq
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 1653 Byte
Status AC
Exec Time 528 ms
Memory 24600 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 20
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt
Case Name Status Exec Time Memory
sample-01.txt AC 528 ms 23944 KB
sample-02.txt AC 403 ms 23940 KB
sample-03.txt AC 391 ms 23944 KB
test-01.txt AC 412 ms 23964 KB
test-02.txt AC 393 ms 23948 KB
test-03.txt AC 387 ms 23928 KB
test-04.txt AC 398 ms 24060 KB
test-05.txt AC 424 ms 24164 KB
test-06.txt AC 422 ms 24212 KB
test-07.txt AC 403 ms 24600 KB
test-08.txt AC 397 ms 24452 KB
test-09.txt AC 415 ms 24432 KB
test-10.txt AC 403 ms 24424 KB
test-11.txt AC 414 ms 24536 KB
test-12.txt AC 416 ms 24464 KB
test-13.txt AC 405 ms 24440 KB
test-14.txt AC 409 ms 24444 KB
test-15.txt AC 417 ms 24452 KB
test-16.txt AC 412 ms 24480 KB
test-17.txt AC 401 ms 24512 KB
test-18.txt AC 389 ms 24212 KB
test-19.txt AC 403 ms 24476 KB
test-20.txt AC 418 ms 24456 KB