Task: | Trade |
Sender: | PILIPOJAT!! |
Submission time: | 2016-09-13 18:03:37 +0300 |
Language: | Java |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.09 s | details |
#2 | ACCEPTED | 0.10 s | details |
#3 | ACCEPTED | 0.09 s | details |
#4 | ACCEPTED | 0.10 s | details |
#5 | ACCEPTED | 0.10 s | details |
#6 | ACCEPTED | 0.10 s | details |
#7 | ACCEPTED | 0.10 s | details |
#8 | ACCEPTED | 0.10 s | details |
#9 | ACCEPTED | 0.09 s | details |
#10 | ACCEPTED | 0.10 s | details |
#11 | ACCEPTED | 0.17 s | details |
#12 | ACCEPTED | 0.14 s | details |
#13 | ACCEPTED | 0.13 s | details |
#14 | ACCEPTED | 0.11 s | details |
#15 | ACCEPTED | 0.12 s | details |
#16 | ACCEPTED | 0.15 s | details |
#17 | ACCEPTED | 0.12 s | details |
#18 | ACCEPTED | 0.14 s | details |
#19 | ACCEPTED | 0.12 s | details |
#20 | ACCEPTED | 0.13 s | details |
#21 | ACCEPTED | 0.18 s | details |
#22 | ACCEPTED | 0.17 s | details |
#23 | ACCEPTED | 0.11 s | details |
#24 | ACCEPTED | 0.14 s | details |
#25 | ACCEPTED | 0.16 s | details |
#26 | ACCEPTED | 0.12 s | details |
#27 | ACCEPTED | 0.17 s | details |
#28 | ACCEPTED | 0.14 s | details |
#29 | ACCEPTED | 0.15 s | details |
#30 | ACCEPTED | 0.14 s | details |
Code
import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { IO io = new IO(); int n = io.nextInt(); int cities[][] = new int[n][n]; int tradeAgreements[] = new int[n]; int tradet=0; for(int i=0; i<n; i++) { tradeAgreements[i] = io.nextInt(); tradet += tradeAgreements[i]; } //hc koodi alkaa just täst int isoimmatKaupungit[]; for(int i=0; i<tradet/2; i++) { isoimmatKaupungit = find2cities(tradeAgreements); if(isoimmatKaupungit[0] != -1) { tradeAgreements[isoimmatKaupungit[0]]--; tradeAgreements[isoimmatKaupungit[1]]--; cities[isoimmatKaupungit[0]][isoimmatKaupungit[1]]++; cities[isoimmatKaupungit[1]][isoimmatKaupungit[0]]++; } } for(int i=0; i<tradeAgreements.length; i++) { if(tradeAgreements[i] > 0) { System.out.println("QAQ"); return; } } //hc koodi loppuu tähän for(int y=0; y<n; y++) { for(int x=0; x<n; x++) { System.out.print(cities[y][x] + (x == n - 1 ? "" : " ")); } System.out.println(); } } public static int[] find2cities(int[] taul) { int a=0; int b=0; int x=0, y=0; for(int i=0; i<taul.length; i++) { if(a < taul[i]) { if(b<a) { b=a; y=x; } a = taul[i]; x=i; } else if(b < taul[i]) { b = taul[i]; y=i; } } //4System.out.println("x=" + x + ", y=" + y); if(a==0 || b==0) return new int[]{-1, -1}; return new int[]{x, y}; } public static 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
Verdict: ACCEPTED
input |
---|
2 78 16 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 2
Verdict: ACCEPTED
input |
---|
2 87 93 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 3
Verdict: ACCEPTED
input |
---|
2 63 29 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 4
Verdict: ACCEPTED
input |
---|
2 64 28 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 5
Verdict: ACCEPTED
input |
---|
1 74 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 6
Verdict: ACCEPTED
input |
---|
3 69 68 31 |
correct output |
---|
0 53 16 53 0 15 16 15 0 |
user output |
---|
0 53 16 53 0 15 16 15 0 |
Test 7
Verdict: ACCEPTED
input |
---|
3 63 24 69 |
correct output |
---|
0 9 54 9 0 15 54 15 0 |
user output |
---|
0 9 54 9 0 15 54 15 0 |
Test 8
Verdict: ACCEPTED
input |
---|
3 3 23 60 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 9
Verdict: ACCEPTED
input |
---|
1 94 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 10
Verdict: ACCEPTED
input |
---|
2 43 30 |
correct output |
---|
QAQ |
user output |
---|
QAQ |
Test 11
Verdict: ACCEPTED
input |
---|
74 22 20 85 38 99 25 16 71 14 27 ... |
correct output |
---|
0 9 2 0 0 0 0 0 0 0 0 0 0 0 0 ... |
user output |
---|
0 9 13 0 0 0 0 0 0 0 0 0 0 0 0... |
Test 12
Verdict: ACCEPTED
input |
---|
66 90 45 20 41 30 32 18 98 72 82 ... |
correct output |
---|
0 20 0 0 0 0 0 16 0 0 0 0 0 0 ... |
user output |
---|
0 20 11 13 0 0 0 16 18 7 0 0 0... |
Test 13
Verdict: ACCEPTED
input |
---|
29 76 8 75 22 59 96 30 38 36 94 1... |
correct output |
---|
0 4 24 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 3 29 8 22 14 0 0 0 0 0 0 0 0... |
Test 14
Verdict: ACCEPTED
input |
---|
18 18 97 25 44 71 84 91 100 73 26... |
correct output |
---|
0 12 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 12 6 0 0 0 0 0 0 0 0 0 0 0 0... |
Test 15
Verdict: ACCEPTED
input |
---|
43 65 98 8 56 5 49 12 23 29 100 4... |
correct output |
---|
0 28 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 27 3 31 0 0 0 0 0 4 0 0 0 0 ... |
Test 16
Verdict: ACCEPTED
input |
---|
69 72 74 32 82 31 34 95 61 64 100... |
correct output |
---|
0 37 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 37 13 22 0 0 0 0 0 0 0 0 0 0... |
Test 17
Verdict: ACCEPTED
input |
---|
31 85 93 73 73 51 26 86 23 100 41... |
correct output |
---|
0 33 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 33 47 0 0 0 5 0 0 0 0 0 0 0 ... |
Test 18
Verdict: ACCEPTED
input |
---|
61 43 80 85 94 6 22 68 5 14 62 55... |
correct output |
---|
0 14 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 13 30 0 0 0 0 0 0 0 0 0 0 0 ... |
Test 19
Verdict: ACCEPTED
input |
---|
37 61 15 22 61 5 29 28 51 49 57 3... |
correct output |
---|
0 6 4 25 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 6 13 28 0 0 0 8 0 3 0 3 0 0 ... |
Test 20
Verdict: ACCEPTED
input |
---|
44 36 78 1 39 72 50 90 68 89 93 9... |
correct output |
---|
0 17 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 17 0 19 0 0 0 0 0 0 0 0 0 0 ... |
Test 21
Verdict: ACCEPTED
input |
---|
87 1 47 27 95 17 53 79 30 47 91 4... |
correct output |
---|
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
user output |
---|
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 ... |
Test 22
Verdict: ACCEPTED
input |
---|
63 83 91 93 92 58 16 22 58 75 92 ... |
correct output |
---|
0 48 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 48 35 0 0 0 0 0 0 0 0 0 0 0 ... |
Test 23
Verdict: ACCEPTED
input |
---|
15 90 69 94 19 6 83 23 83 18 31 9... |
correct output |
---|
0 37 8 0 0 0 0 0 0 0 0 0 0 0 4... |
user output |
---|
0 36 42 0 0 10 0 0 0 0 2 0 0 0... |
Test 24
Verdict: ACCEPTED
input |
---|
54 44 75 15 14 80 78 63 76 89 20 ... |
correct output |
---|
0 23 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 22 6 0 16 0 0 0 0 0 0 0 0 0 ... |
Test 25
Verdict: ACCEPTED
input |
---|
64 78 97 82 66 61 37 56 71 19 12 ... |
correct output |
---|
0 32 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 32 46 0 0 0 0 0 0 0 0 0 0 0 ... |
Test 26
Verdict: ACCEPTED
input |
---|
19 2 4 54 34 8 60 29 7 98 21 85 9... |
correct output |
---|
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
user output |
---|
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 ... |
Test 27
Verdict: ACCEPTED
input |
---|
72 90 60 7 11 17 25 10 40 1 79 10... |
correct output |
---|
0 33 0 0 0 0 0 0 0 12 0 0 2 0 ... |
user output |
---|
0 33 4 2 3 5 0 8 0 16 0 0 11 0... |
Test 28
Verdict: ACCEPTED
input |
---|
64 61 83 12 86 87 86 31 91 84 15 ... |
correct output |
---|
0 32 0 0 0 0 0 0 0 0 0 0 0 0 0... |
user output |
---|
0 31 1 29 0 0 0 0 0 0 0 0 0 0 ... |
Test 29
Verdict: ACCEPTED
input |
---|
67 53 18 42 36 69 99 85 96 77 6 6... |
correct output |
---|
0 9 9 0 8 0 0 0 0 0 0 0 0 0 0 ... |
user output |
---|
0 8 20 13 8 4 0 0 0 0 0 0 0 0 ... |
Test 30
Verdict: ACCEPTED
input |
---|
57 91 42 71 53 66 12 70 18 62 84 ... |
correct output |
---|
0 18 11 0 0 0 0 0 0 5 0 0 0 0 ... |
user output |
---|
0 18 35 7 8 0 3 0 0 4 0 0 0 0 ... |