Submission #3588655
Source Code Expand
import java.util.Scanner; public class Main { public static void main(String[] args) { int N; int[] A; int[] sortPattern1; int[] sortPattern2; int sa; int saGoukei1 = 0; int saGoukei2 = 0; Scanner sc = null; try { sc = new Scanner(System.in); N = Integer.valueOf(sc.nextInt()); A = new int[N]; for (int i = 0; i < N; i++) { A[i] = Integer.valueOf(sc.nextInt()); if (i >= 1) { for (int j = i; j > 0; j--) { if (A[j - 1] > A[j]) { int temp = A[j]; A[j] = A[j - 1]; A[j - 1] = temp; } else { break; } } } } int midIdx; if (N % 2 == 0) midIdx = N / 2 - 1; else midIdx = N / 2; sortPattern1 = new int[N]; sortPattern1[0] = A[midIdx]; boolean largeSideFlg = true; int counter1 = 1; int sortCounter = 1; // 差分が最大になるようにソート for (int i = N - counter1; i != midIdx;) { sortPattern1[sortCounter] = A[i]; sa = sortPattern1[sortCounter - 1] - sortPattern1[sortCounter]; if (sa < 0) sa = -sa; saGoukei1 += sa; sortCounter++; if (largeSideFlg) { i = counter1 - 1; largeSideFlg = false; } else { counter1++; largeSideFlg = true; i = N - counter1; } } sortPattern2 = new int[N]; sortPattern2[0] = A[midIdx]; boolean smallSideFlg = true; int counter2 = 0; int sortCounter2 = 1; // 差分が最大になるようにソート for (int i = counter2; sortCounter2 != N;) { sortPattern2[sortCounter2] = A[i]; sa = sortPattern2[sortCounter2 - 1] - sortPattern2[sortCounter2]; if (sa < 0) sa = -sa; saGoukei2 += sa; sortCounter2++; if (smallSideFlg) { smallSideFlg = false; i = N - counter2 - 1; } else { counter2++; i = counter2; smallSideFlg = true; } } if (saGoukei1 > saGoukei2) System.out.println(saGoukei1); else System.out.println(saGoukei2); } catch (Exception e) { System.out.println(e); } finally { if (sc != null) { sc.close(); } } } }
Submission Info
Submission Time | |
---|---|
Task | C - Align |
User | ProgrammerTT |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 2197 Byte |
Status | WA |
Exec Time | 2109 ms |
Memory | 53068 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 400 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt, s3.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, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | TLE | 2105 ms | 49776 KB |
02.txt | TLE | 2109 ms | 48552 KB |
03.txt | TLE | 2109 ms | 47460 KB |
04.txt | TLE | 2109 ms | 49364 KB |
05.txt | TLE | 2109 ms | 51496 KB |
06.txt | TLE | 2109 ms | 48876 KB |
07.txt | TLE | 2109 ms | 49444 KB |
08.txt | TLE | 2109 ms | 47904 KB |
09.txt | TLE | 2109 ms | 48028 KB |
10.txt | TLE | 2109 ms | 49236 KB |
11.txt | TLE | 2109 ms | 50252 KB |
12.txt | TLE | 2109 ms | 46208 KB |
13.txt | TLE | 2109 ms | 49684 KB |
14.txt | TLE | 2109 ms | 50348 KB |
15.txt | TLE | 2105 ms | 48760 KB |
16.txt | TLE | 2109 ms | 50560 KB |
17.txt | TLE | 2109 ms | 48628 KB |
18.txt | TLE | 2109 ms | 52048 KB |
19.txt | TLE | 2109 ms | 53068 KB |
20.txt | TLE | 2109 ms | 47768 KB |
21.txt | TLE | 2105 ms | 47872 KB |
22.txt | TLE | 2109 ms | 47592 KB |
23.txt | TLE | 2109 ms | 45368 KB |
24.txt | TLE | 2109 ms | 47384 KB |
25.txt | TLE | 2109 ms | 47840 KB |
26.txt | TLE | 2109 ms | 48300 KB |
27.txt | TLE | 2109 ms | 46004 KB |
28.txt | TLE | 2109 ms | 48028 KB |
29.txt | AC | 417 ms | 48316 KB |
30.txt | WA | 501 ms | 48744 KB |
31.txt | WA | 436 ms | 49288 KB |
32.txt | WA | 461 ms | 49712 KB |
33.txt | AC | 94 ms | 18900 KB |
34.txt | AC | 92 ms | 20688 KB |
35.txt | AC | 92 ms | 19028 KB |
36.txt | AC | 93 ms | 19284 KB |
37.txt | AC | 96 ms | 19924 KB |
s1.txt | AC | 93 ms | 20688 KB |
s2.txt | AC | 94 ms | 22740 KB |
s3.txt | AC | 94 ms | 20692 KB |