| Task: | Invert |
| Sender: | michaeljackson123 |
| Submission time: | 2016-09-13 18:42:49 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | TIME LIMIT EXCEEDED | -- | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
| #4 | TIME LIMIT EXCEEDED | -- | details |
| #5 | TIME LIMIT EXCEEDED | -- | details |
| #6 | TIME LIMIT EXCEEDED | -- | details |
| #7 | WRONG ANSWER | 1.73 s | details |
| #8 | TIME LIMIT EXCEEDED | -- | details |
| #9 | TIME LIMIT EXCEEDED | -- | details |
| #10 | TIME LIMIT EXCEEDED | -- | details |
| #11 | TIME LIMIT EXCEEDED | -- | details |
| #12 | TIME LIMIT EXCEEDED | -- | details |
| #13 | TIME LIMIT EXCEEDED | -- | details |
| #14 | TIME LIMIT EXCEEDED | -- | details |
| #15 | TIME LIMIT EXCEEDED | -- | details |
| #16 | TIME LIMIT EXCEEDED | -- | details |
| #17 | TIME LIMIT EXCEEDED | -- | details |
| #18 | TIME LIMIT EXCEEDED | -- | details |
| #19 | TIME LIMIT EXCEEDED | -- | details |
| #20 | TIME LIMIT EXCEEDED | -- | details |
Code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package javaapplication6;
import java.util.ArrayList;
import java.util.Collections;
/**
*
* @author tuukkatu
*/
public class JavaApplication6 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
IO io = new IO();
ArrayList<Integer> list = new ArrayList();
long numOfCommands = io.nextInt();
int i = 0;
boolean previousOperationWasFour = false;
int previousNumberOfInversions = 0;
while(i < numOfCommands) {
int a = io.nextInt();
if (a == 1 || a == 2)
{
int b = io.nextInt();
list = insertNumberInEnd(list, b);
previousOperationWasFour = false;
}
else
{
if (a == 3)
{
list = sortInNondecreasingOrder(list);
previousOperationWasFour = false;
}
if (a == 4)
{
if (previousOperationWasFour)
{
io.println(previousNumberOfInversions);
}
else
{
int numberOfInversions = countInversions(list);
io.println(numberOfInversions);
previousNumberOfInversions = numberOfInversions;
}
previousOperationWasFour = true;
}
}
i++;
}
}
private static ArrayList<Integer> insertNumberInEnd(ArrayList<Integer> list,
int number)
{
list.add(number);
return list;
}
private static ArrayList<Integer> insertNumberInBeginning(ArrayList<Integer> list,
int number)
{
list.add(0, number);
return list;
}
private static ArrayList<Integer> sortInNondecreasingOrder(ArrayList<Integer> list)
{
Collections.sort(list);
Collections.reverse(list);
return list;
}
private static int countInversions(ArrayList<Integer> list)
{
int inversionCounter = 0;
if (list.size() < 2)
{
return 0;
}
for (int i = 0; i < list.size() - 1; i++)
{
for (int j = i + 1; j < list.size(); j++)
{
if (list.get(i) > list.get(j))
{
inversionCounter++;
}
}
}
return inversionCounter;
}
}
Test details
Test 1
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 116682 2 16788 1 18822 1 33396 2 69805 ... |
| correct output |
|---|
| 2718 19980 51212 68871 108108 ... |
| user output |
|---|
| (empty) |
Test 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 2 98355 2 60191 1 725 2 44093 ... |
| correct output |
|---|
| 4591136 513858069 2568146952 3245381276 3834167771 ... |
| user output |
|---|
| (empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 279091 1 1715 2 67456 3 4 ... |
| correct output |
|---|
| 0 7 8 8 10 ... |
| user output |
|---|
| (empty) |
Test 4
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 2 61543 1 60828 1 50355 1 40328 ... |
| correct output |
|---|
| 68875 35642 76306 9043 53444 ... |
| user output |
|---|
| (empty) |
Test 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 401545 1 20583 1 54459 2 5060 2 18660 ... |
| correct output |
|---|
| 7135104 67093970 87978149 240022409 353132099 ... |
| user output |
|---|
| (empty) |
Test 6
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 2 41157 2 37822 2 72091 3 ... |
| correct output |
|---|
| 2 2 2 2 5 ... |
| user output |
|---|
| (empty) |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 10079 2 52135 1 5407 2 94 1 37058 ... |
| correct output |
|---|
| 158419 6571 89379 171235 7854 ... |
| user output |
|---|
| (empty) |
Test 8
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 1 83689 1 70194 1 17167 2 52286 ... |
| correct output |
|---|
| 16433238 99620800 142458990 274873638 411495712 ... |
| user output |
|---|
| (empty) |
Test 9
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 90533 2 34119 4 3 3 ... |
| correct output |
|---|
| 0 0 16 27 0 ... |
| user output |
|---|
| (empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 2 63136 2 11519 1 91986 1 92054 ... |
| correct output |
|---|
| 191 11103 16624 90718 101186 ... |
| user output |
|---|
| (empty) |
Test 11
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 323662 1 18238 1 62832 1 53482 1 43447 ... |
| correct output |
|---|
| 158283253 677654483 1023537391 121975751 144502380 ... |
| user output |
|---|
| (empty) |
Test 12
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 1 11725 4 1 99988 1 88696 ... |
| correct output |
|---|
| 0 21 0 0 0 ... |
| user output |
|---|
| (empty) |
Test 13
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 125498 1 65018 1 41218 2 93534 2 78789 ... |
| correct output |
|---|
| 41 1213 49209 27631 56275 ... |
| user output |
|---|
| (empty) |
Test 14
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 2 22435 2 98738 1 57359 2 77794 ... |
| correct output |
|---|
| 5948069 17495286 58672750 137825207 482842950 ... |
| user output |
|---|
| (empty) |
Test 15
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 343000 1 14035 3 1 36003 2 2676 ... |
| correct output |
|---|
| 0 0 0 0 0 ... |
| user output |
|---|
| (empty) |
Test 16
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 2 67715 2 16062 1 12953 2 43464 ... |
| correct output |
|---|
| 14302 25179 21705 13316 26515 ... |
| user output |
|---|
| (empty) |
Test 17
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 372731 1 16333 1 58828 2 1790 2 56950 ... |
| correct output |
|---|
| 23264093 180691208 58859618 1007439070 357775222 ... |
| user output |
|---|
| (empty) |
Test 18
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 1 24800 1 30022 3 3 ... |
| correct output |
|---|
| 0 0 2 0 7 ... |
| user output |
|---|
| (empty) |
Test 19
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 398012 1 7709 1 12219 1 95709 1 75173 ... |
| correct output |
|---|
| 1733 3398 7720 34986 79727 ... |
| user output |
|---|
| (empty) |
Test 20
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500000 1 97423 2 25928 1 85082 2 35253 ... |
| correct output |
|---|
| 92435834 311688637 486359207 492535988 540678377 ... |
| user output |
|---|
| (empty) |
