답안 #658817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658817 2022-11-15T02:45:19 Z coderInTraining Palembang Bridges (APIO15_bridge) Java 11
22 / 100
1082 ms 27032 KB
import java.util.*;
import java.io.*;

public class bridge {
    public static void main (String[]args) throws IOException {
        Scanner scan = new Scanner (System.in);

        try {
            int allowedBridges = scan.nextInt();
            int citizenNumber = scan.nextInt();

            long previousAdding = 0;

            ArrayList<Integer> locations = new ArrayList<Integer>();

            for (int i = 0; i < citizenNumber; i++) {

                /* 
                String line = scan.next();

                char startZone = line.charAt(0);
                int index = 0;

                for (int j = 1; j < line.length(); j++) {

                    if (line.charAt(j) == 'A' || line.charAt(j) == 'B') {
                        index = j;
                        break;
                    }
                }

                int startLocation = Integer.valueOf(line.substring(1, index));
                char endZone = line.charAt(index);
                int endLocation = Integer.valueOf(line.substring(index + 1));
                */

                char startZone = scan.next().charAt(0);
                int startLocation = scan.nextInt();
                char endZone = scan.next().charAt(0);
                int endLocation = scan.nextInt();

                if (startZone == endZone) {
                    previousAdding += Math.abs(endLocation - startLocation);
                    continue;
                }

                locations.add(startLocation);
                locations.add(endLocation);
            }

            /*
            * If we are only able to build one bridge, we should
            * build it at the median of all start and end locations.
            * After find the median, we can calculate the answer
            * by looping through all values and adding the previously
            * calculated value for locations in the same zone. 
            */
            if (allowedBridges == 1) {

                long answer = 0;

                if (locations.size() != 0) {
                    Collections.sort(locations);

                    int size = locations.size();
                    int median = locations.get(size / 2 - 1);

                    for (int i = 0; i < locations.size(); i++) {
                        answer += Math.abs(locations.get(i) - median);
                    }

                    answer += (locations.size() / 2);
                }

                answer += previousAdding;

                System.out.println(answer);
            }
            else {
                System.out.println(100);
            }
        }
        catch (Exception e) {
            return;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 10500 KB Output is correct
2 Correct 96 ms 10216 KB Output is correct
3 Correct 296 ms 13332 KB Output is correct
4 Correct 295 ms 14820 KB Output is correct
5 Correct 319 ms 14896 KB Output is correct
6 Correct 293 ms 14848 KB Output is correct
7 Correct 300 ms 15128 KB Output is correct
8 Correct 302 ms 14976 KB Output is correct
9 Correct 301 ms 14924 KB Output is correct
10 Correct 320 ms 15016 KB Output is correct
11 Correct 301 ms 14892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 10044 KB Output is correct
2 Correct 94 ms 10112 KB Output is correct
3 Correct 271 ms 13328 KB Output is correct
4 Correct 316 ms 14844 KB Output is correct
5 Correct 335 ms 14988 KB Output is correct
6 Correct 295 ms 15020 KB Output is correct
7 Correct 341 ms 15176 KB Output is correct
8 Correct 299 ms 14924 KB Output is correct
9 Correct 304 ms 14980 KB Output is correct
10 Correct 342 ms 15004 KB Output is correct
11 Correct 300 ms 14964 KB Output is correct
12 Correct 806 ms 21476 KB Output is correct
13 Correct 1082 ms 27032 KB Output is correct
14 Correct 935 ms 25792 KB Output is correct
15 Correct 1002 ms 23408 KB Output is correct
16 Correct 928 ms 23908 KB Output is correct
17 Correct 880 ms 26644 KB Output is correct
18 Correct 937 ms 26432 KB Output is correct
19 Correct 1068 ms 26868 KB Output is correct
20 Correct 975 ms 24992 KB Output is correct
21 Correct 964 ms 26372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 10236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 101 ms 10168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 95 ms 10372 KB Output isn't correct
2 Halted 0 ms 0 KB -