| Task: | Urkupillit |
| Sender: | MusserO |
| Submission time: | 2015-01-29 13:25:11 +0200 |
| Language: | Java |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | RUNTIME ERROR | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | 1 | details |
| #2 | RUNTIME ERROR | 0.06 s | 1 | details |
| #3 | ACCEPTED | 0.04 s | 1 | details |
| #4 | ACCEPTED | 0.05 s | 1 | details |
| #5 | WRONG ANSWER | 0.02 s | 1 | details |
| #6 | ACCEPTED | 0.04 s | 2 | details |
| #7 | WRONG ANSWER | 0.07 s | 2 | details |
| #8 | WRONG ANSWER | 0.05 s | 2 | details |
| #9 | WRONG ANSWER | 0.04 s | 2 | details |
| #10 | WRONG ANSWER | 0.04 s | 2 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #12 | RUNTIME ERROR | 0.03 s | 3 | details |
| #13 | RUNTIME ERROR | 0.04 s | 3 | details |
| #14 | RUNTIME ERROR | 0.04 s | 3 | details |
| #15 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
import java.io.*;
import java.util.*;
public class Urkupillit {
public static void main(String[] args) {
IO io = new IO();
int n = io.nextInt();
int k = io.nextInt();
int j = 1;
int m = 0;
String v = "";
ArrayList<Integer> l = new ArrayList<Integer>();
for (int i = 1; i <= n; ++i){
if ((n-i)*(n-i+1)/2 > k){
l.add(i);
++j;
} else {
++m;
l.add(n-i+j);
}
}
boolean br = false;
for (int i = 0; i < l.size(); ++i){
if (br){
br =false;
continue;
}
if (i % 2 == 0 && m < k){
v += l.get(i+1) + " ";
v += l.get(i) + " ";
++m;
br = true;
} else {
v+= l.get(i)+" ";
}
}
io.println(v);
io.close();
}
}
class IO extends PrintWriter {
private InputStreamReader r;
private static final int BUFSIZE = 1 << 15;
private char[] buf;
private int bufc;
private int bufi;
private StringBuilder sb;
public IO() {
super(new BufferedOutputStream(System.out));
r = new InputStreamReader(System.in);
buf = new char[BUFSIZE];
bufc = 0;
bufi = 0;
sb = new StringBuilder();
}
private void fillBuf() throws IOException {
bufi = 0;
bufc = 0;
while(bufc == 0) {
bufc = r.read(buf, 0, BUFSIZE);
if(bufc == -1) {
bufc = 0;
return;
}
}
}
private boolean pumpBuf() throws IOException {
if(bufi == bufc) {
fillBuf();
}
return bufc != 0;
}
private boolean isDelimiter(char c) {
return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f';
}
private void eatDelimiters() throws IOException {
while(true) {
if(bufi == bufc) {
fillBuf();
if(bufc == 0) throw new RuntimeException("IO: Out of input.");
}
if(!isDelimiter(buf[bufi])) break;
++bufi;
}
}
public String next() {
try {
sb.setLength(0);
eatDelimiters();
int start = bufi;
while(true) {
if(bufi == bufc) {
sb.append(buf, start, bufi - start);
fillBuf();
start = 0;
if(bufc == 0) break;
}
if(isDelimiter(buf[bufi])) break;
++bufi;
}
sb.append(buf, start, bufi - start);
return sb.toString();
} catch(IOException e) {
throw new RuntimeException("IO.next: Caught IOException.");
}
}
public int nextInt() {
try {
int ret = 0;
eatDelimiters();
boolean positive = true;
if(buf[bufi] == '-') {
++bufi;
if(!pumpBuf()) throw new RuntimeException("IO.nextInt: Invalid int.");
positive = false;
}
boolean first = true;
while(true) {
if(!pumpBuf()) break;
if(isDelimiter(buf[bufi])) {
if(first) throw new RuntimeException("IO.nextInt: Invalid int.");
break;
}
first = false;
if(buf[bufi] >= '0' && buf[bufi] <= '9') {
if(ret < -214748364) throw new RuntimeException("IO.nextInt: Invalid int.");
ret *= 10;
ret -= (int)(buf[bufi] - '0');
if(ret > 0) throw new RuntimeException("IO.nextInt: Invalid int.");
} else {
throw new RuntimeException("IO.nextInt: Invalid int.");
}
++bufi;
}
if(positive) {
if(ret == -2147483648) throw new RuntimeException("IO.nextInt: Invalid int.");
ret = -ret;
}
return ret;
} catch(IOException e) {
throw new RuntimeException("IO.nextInt: Caught IOException.");
}
}
public long nextLong() {
try {
long ret = 0;
eatDelimiters();
boolean positive = true;
if(buf[bufi] == '-') {
++bufi;
if(!pumpBuf()) throw new RuntimeException("IO.nextLong: Invalid long.");
positive = false;
}
boolean first = true;
while(true) {
if(!pumpBuf()) break;
if(isDelimiter(buf[bufi])) {
if(first) throw new RuntimeException("IO.nextLong: Invalid long.");
break;
}
first = false;
if(buf[bufi] >= '0' && buf[bufi] <= '9') {
if(ret < -922337203685477580L) throw new RuntimeException("IO.nextLong: Invalid long.");
ret *= 10;
ret -= (long)(buf[bufi] - '0');
if(ret > 0) throw new RuntimeException("IO.nextLong: Invalid long.");
} else {
throw new RuntimeException("IO.nextLong: Invalid long.");
}
++bufi;
}
if(positive) {
if(ret == -9223372036854775808L) throw new RuntimeException("IO.nextLong: Invalid long.");
ret = -ret;
}
return ret;
} catch(IOException e) {
throw new RuntimeException("IO.nextLong: Caught IOException.");
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
Test details
Test 1
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 5 0 |
| correct output |
|---|
| 1 2 3 4 5 |
| user output |
|---|
| 1 2 3 4 5 |
Test 2
Group: 1
Verdict: RUNTIME ERROR
| input |
|---|
| 5 10 |
| correct output |
|---|
| 5 4 3 2 1 |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 5, Size: 5 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at Urkupillit.main(Urkupillit.java:29)
Test 3
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 5 3 |
| correct output |
|---|
| 4 1 2 3 5 |
| user output |
|---|
| 1 2 5 4 3 |
Test 4
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 5 1 |
| correct output |
|---|
| 2 1 3 4 5 |
| user output |
|---|
| 1 2 3 5 4 |
Test 5
Group: 1
Verdict: WRONG ANSWER
| input |
|---|
| 5 2 |
| correct output |
|---|
| 3 1 2 4 5 |
| user output |
|---|
| 1 2 3 5 4 |
Test 6
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 100 0 |
| correct output |
|---|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| user output |
|---|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
Test 7
Group: 2
Verdict: WRONG ANSWER
| input |
|---|
| 100 4950 |
| correct output |
|---|
| 100 99 98 97 96 95 94 93 92 91... |
| user output |
|---|
| 99 100 97 98 95 96 93 94 91 92... |
Test 8
Group: 2
Verdict: WRONG ANSWER
| input |
|---|
| 100 2279 |
| correct output |
|---|
| 100 99 98 97 96 95 94 93 92 91... |
| user output |
|---|
| 2 1 4 3 6 5 8 7 10 9 12 11 14 ... |
Test 9
Group: 2
Verdict: WRONG ANSWER
| input |
|---|
| 100 2528 |
| correct output |
|---|
| 100 99 98 97 96 95 94 93 92 91... |
| user output |
|---|
| 2 1 4 3 6 5 8 7 10 9 12 11 14 ... |
Test 10
Group: 2
Verdict: WRONG ANSWER
| input |
|---|
| 100 4483 |
| correct output |
|---|
| 100 99 98 97 96 95 94 93 92 91... |
| user output |
|---|
| 2 1 4 3 100 5 98 99 96 97 94 9... |
Test 11
Group: 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 0 |
| correct output |
|---|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
| user output |
|---|
| (empty) |
Test 12
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 4999950000 |
| correct output |
|---|
| 100000 99999 99998 99997 99996... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(Urkupillit.java:147) at Urkupillit.main(Urkupillit.java:8)
Test 13
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 2969035543 |
| correct output |
|---|
| 100000 99999 99998 99997 99996... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(Urkupillit.java:147) at Urkupillit.main(Urkupillit.java:8)
Test 14
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 100000 2495939870 |
| correct output |
|---|
| 100000 99999 99998 99997 99996... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.lang.RuntimeException: IO.nextInt: Invalid int. at IO.nextInt(Urkupillit.java:147) at Urkupillit.main(Urkupillit.java:8)
Test 15
Group: 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100000 1279770330 |
| correct output |
|---|
| 100000 99999 99998 99997 99996... |
| user output |
|---|
| (empty) |
