Submission #3588674
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 | Java7 (OpenJDK 1.7.0) |
Score | 0 |
Code Size | 2197 Byte |
Status | WA |
Exec Time | 2108 ms |
Memory | 50024 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 | 2108 ms | 45872 KB |
02.txt | TLE | 2108 ms | 47732 KB |
03.txt | TLE | 2108 ms | 48100 KB |
04.txt | TLE | 2104 ms | 47216 KB |
05.txt | TLE | 2108 ms | 47288 KB |
06.txt | TLE | 2108 ms | 47848 KB |
07.txt | TLE | 2108 ms | 49556 KB |
08.txt | TLE | 2108 ms | 45872 KB |
09.txt | TLE | 2108 ms | 47812 KB |
10.txt | TLE | 2108 ms | 47944 KB |
11.txt | TLE | 2108 ms | 46584 KB |
12.txt | TLE | 2108 ms | 47596 KB |
13.txt | TLE | 2105 ms | 47988 KB |
14.txt | TLE | 2108 ms | 47040 KB |
15.txt | TLE | 2108 ms | 46948 KB |
16.txt | TLE | 2108 ms | 49772 KB |
17.txt | TLE | 2108 ms | 47968 KB |
18.txt | TLE | 2108 ms | 47268 KB |
19.txt | TLE | 2108 ms | 45052 KB |
20.txt | TLE | 2108 ms | 47716 KB |
21.txt | TLE | 2104 ms | 48112 KB |
22.txt | TLE | 2108 ms | 47312 KB |
23.txt | TLE | 2108 ms | 43936 KB |
24.txt | TLE | 2108 ms | 47772 KB |
25.txt | TLE | 2013 ms | 48016 KB |
26.txt | TLE | 2010 ms | 46072 KB |
27.txt | TLE | 2015 ms | 49972 KB |
28.txt | TLE | 2013 ms | 48008 KB |
29.txt | AC | 418 ms | 50024 KB |
30.txt | WA | 456 ms | 49980 KB |
31.txt | WA | 452 ms | 48436 KB |
32.txt | WA | 456 ms | 48708 KB |
33.txt | AC | 100 ms | 22868 KB |
34.txt | AC | 100 ms | 20948 KB |
35.txt | AC | 100 ms | 20820 KB |
36.txt | AC | 100 ms | 20820 KB |
37.txt | AC | 100 ms | 20820 KB |
s1.txt | AC | 100 ms | 20820 KB |
s2.txt | AC | 99 ms | 20820 KB |
s3.txt | AC | 98 ms | 20820 KB |