Submission #844725


Source Code Expand

Copy
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            int[] b = a.clone();
            Arrays.sort(b);
            int res = 0;
            for (int i = 0; i < n; ++i) {
                if (Math.abs(i - Arrays.binarySearch(b, a[i])) % 2 != 0) ++res;
            }
            out.println(res / 2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Submission Info

Submission Time
Task C - BBuBBBlesort!
User Petr
Language Java8 (OpenJDK 1.8.0)
Score 600
Code Size 2092 Byte
Status AC
Exec Time 403 ms
Memory 20604 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 24
Set Name Test Cases
Sample s1.txt, s2.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, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt AC 346 ms 20056 KB
02.txt AC 350 ms 20060 KB
03.txt AC 342 ms 20048 KB
04.txt AC 378 ms 19860 KB
05.txt AC 337 ms 19852 KB
06.txt AC 334 ms 20236 KB
07.txt AC 403 ms 20140 KB
08.txt AC 314 ms 19576 KB
09.txt AC 314 ms 19988 KB
10.txt AC 330 ms 20248 KB
11.txt AC 310 ms 19632 KB
12.txt AC 318 ms 19788 KB
13.txt AC 334 ms 20176 KB
14.txt AC 378 ms 20604 KB
15.txt AC 322 ms 19812 KB
16.txt AC 346 ms 20168 KB
17.txt AC 326 ms 19792 KB
18.txt AC 168 ms 8276 KB
19.txt AC 162 ms 8276 KB
20.txt AC 158 ms 8272 KB
21.txt AC 158 ms 8148 KB
22.txt AC 194 ms 8148 KB
s1.txt AC 162 ms 8272 KB
s2.txt AC 158 ms 8268 KB