結果

問題 No.190 Dry Wet Moist
ユーザー threepipes_s
提出日時 2015-04-22 00:40:01
言語 Java8
(openjdk 1.8.0.191)
結果
AC  
実行時間 355 ms
コード長 3,639 Byte
コンパイル時間 1,513 ms
使用メモリ 57,176 KB
最終ジャッジ日時 2019-05-12 17:40:01

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
00_sample_01.in AC 76 ms
31,176 KB
00_sample_02.in AC 75 ms
32,092 KB
10_small_01.in AC 72 ms
32,200 KB
10_small_02.in AC 74 ms
31,272 KB
10_small_03.in AC 73 ms
28,908 KB
10_small_04.in AC 72 ms
30,632 KB
10_small_05.in AC 74 ms
32,060 KB
20_small_01.in AC 93 ms
30,776 KB
20_small_02.in AC 87 ms
32,272 KB
20_small_03.in AC 80 ms
31,584 KB
20_small_04.in AC 80 ms
30,440 KB
20_small_05.in AC 82 ms
31,488 KB
30_large_01.in AC 211 ms
44,852 KB
30_large_02.in AC 239 ms
47,152 KB
30_large_03.in AC 217 ms
45,752 KB
30_large_04.in AC 348 ms
57,176 KB
30_large_05.in AC 313 ms
55,236 KB
30_large_06.in AC 139 ms
33,644 KB
30_large_07.in AC 210 ms
46,632 KB
30_large_08.in AC 300 ms
54,312 KB
30_large_09.in AC 254 ms
47,940 KB
30_large_10.in AC 138 ms
34,172 KB
40_corner_01.in AC 314 ms
54,252 KB
40_corner_02.in AC 328 ms
54,260 KB
40_corner_03.in AC 355 ms
54,324 KB
40_corner_04.in AC 76 ms
29,396 KB
40_corner_05.in AC 75 ms
30,328 KB
system_test1.txt AC 252 ms
48,648 KB
system_test2.txt AC 164 ms
41,116 KB
system_test3.txt AC 190 ms
43,144 KB
テストケース一括ダウンロード

ソースコード

diff #
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
	IOException {
		ContestScanner in = new ContestScanner();
		int n = in.nextInt()*2;
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		Deque<Integer> qu = new LinkedList<Integer>();
		for(int i=0; i<n; i++){
			qu.add(a[i]);
		}
//		List<Integer> list = new LinkedList<Integer>();
		int count = 0;
		while(qu.size()>1){
			if(qu.peekFirst() + qu.peekLast() < 0){
				count++;
				qu.pollFirst();
				qu.pollLast();
			}
			else{
				qu.pollLast();
			}
		}
		System.out.print(count+" ");
		
		qu = new LinkedList<Integer>();
		for(int i=0; i<n; i++){
			qu.add(a[i]);
		}
//		List<Integer> list = new LinkedList<Integer>();
		count = 0;
		while(qu.size()>1){
			if(qu.peekFirst() + qu.peekLast() > 0){
				count++;
				qu.pollFirst();
				qu.pollLast();
			}
			else{
				qu.pollFirst();
			}
		}
		System.out.print(count+" ");
		
		qu = new LinkedList<Integer>();
//		list = new LinkedList<Integer>();
		for(int i=0; i<n; i++){
			qu.add(a[i]);
		}
		count = 0;
		while(qu.size()>1){
			if(qu.peekFirst() + qu.peekLast() == 0){
				count++;
				qu.pollFirst();
				qu.pollLast();
			}else if(qu.peekFirst() + qu.peekLast() < 0){
				qu.pollFirst();
			}else{
				qu.pollLast();
			}
		}
		System.out.println(count);
	}
}

class Node{
	int id;
	HashSet<Node> edge = new HashSet<Node>();
	public Node(int id) {
		this.id = id;
	}
	public void createEdge(Node node) {
		edge.add(node);
	}
}

class MyComp implements Comparator<int[]> {
	final int idx;
	public MyComp(int idx){
		this.idx = idx;
	}
	public int compare(int[] a, int[] b) {
		return a[idx] - b[idx];
	}
}

class Reverse implements Comparator<Integer> {
	public int compare(Integer arg0, Integer arg1) {
		return arg1 - arg0;
	}
}


class ContestWriter {
	private PrintWriter out;

	public ContestWriter(String filename) throws IOException {
		out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
	}

	public ContestWriter() throws IOException {
		out = new PrintWriter(System.out);
	}

	public void println(String str) {
		out.println(str);
	}

	public void print(String str) {
		out.print(str);
	}

	public void close() {
		out.close();
	}
}

class ContestScanner {
	private BufferedReader reader;
	private String[] line;
	private int idx;

	public ContestScanner() throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(System.in));
	}

	public ContestScanner(String filename) throws FileNotFoundException {
		reader = new BufferedReader(new InputStreamReader(new FileInputStream(
				filename)));
	}

	public String nextToken() throws IOException {
		if (line == null || line.length <= idx) {
			line = reader.readLine().trim().split(" ");
			idx = 0;
		}
		return line[idx++];
	}
	
	public String readLine() throws IOException{
		return reader.readLine();
	}

	public long nextLong() throws IOException, NumberFormatException {
		return Long.parseLong(nextToken());
	}

	public int nextInt() throws NumberFormatException, IOException {
		return (int) nextLong();
	}

	public double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}
0