Submission #2387498


Source Code Expand

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Integer[] spots = new Integer[n];
        for (int i = 0; i < n; i++) {
            spots[i] = scanner.nextInt();
        }
        List<Integer> spotsList = Arrays.asList(spots);


        int originMax = max(spotsList);
        int originMin = min(spotsList);
        int result = 0;
        int max = originMax;
        int min = originMin;
        for (int i = 0; i < n; i++) {
            result = 0;
            max = originMax;
            min = originMin;

            List<Integer> subList = new ArrayList<>(spotsList);
            if (subList.get(i) == max) {
                subList.remove(i);
                max = max(subList);
            } else if (subList.get(i) == min) {
                subList.remove(i);
                min = min(subList);
            }
            result += 2 * max + 2 * Math.abs(min);
            System.out.println(result);
        }


    }

    private static int max(List<Integer> list) {
        Optional<Integer> max = list.stream()
                .filter(spot -> spot >= 0)
                .max((o1, o2) -> o1 - o2);
        return max.orElse(0);
    }

    private static int min(List<Integer> list) {
        Optional<Integer> min = list.stream()
                .filter(spot -> spot <= 0)
                .max((o1, o2) -> o2 - o1);
        return min.orElse(0);
    }


}

Submission Info

Submission Time
Task C - Traveling Plan
User HiroHuntExp
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1556 Byte
Status WA
Exec Time 2111 ms
Memory 360932 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 2
WA × 1
AC × 3
WA × 1
TLE × 11
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, sample-01.txt, sample-02.txt, sample-03.txt
Case Name Status Exec Time Memory
01.txt TLE 2110 ms 359248 KB
02.txt TLE 2110 ms 356372 KB
03.txt AC 189 ms 25172 KB
04.txt TLE 2110 ms 360656 KB
05.txt TLE 2110 ms 356036 KB
06.txt TLE 2110 ms 358536 KB
07.txt TLE 2107 ms 360932 KB
08.txt TLE 2111 ms 360524 KB
09.txt TLE 2106 ms 348092 KB
10.txt TLE 2110 ms 359252 KB
11.txt TLE 2106 ms 356828 KB
12.txt TLE 2106 ms 348508 KB
sample-01.txt AC 188 ms 25044 KB
sample-02.txt AC 180 ms 24784 KB
sample-03.txt WA 190 ms 24784 KB