結果

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

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
00_sample_01.in AC 84 ms
19,248 KB
00_sample_02.in AC 86 ms
19,248 KB
10_small_01.in AC 86 ms
19,252 KB
10_small_02.in AC 88 ms
19,260 KB
10_small_03.in AC 93 ms
19,260 KB
10_small_04.in AC 94 ms
19,260 KB
10_small_05.in AC 96 ms
19,256 KB
20_small_01.in AC 114 ms
20,012 KB
20_small_02.in AC 103 ms
19,564 KB
20_small_03.in AC 101 ms
19,480 KB
20_small_04.in AC 96 ms
19,440 KB
20_small_05.in AC 100 ms
19,480 KB
30_large_01.in AC 250 ms
35,148 KB
30_large_02.in AC 268 ms
38,484 KB
30_large_03.in AC 249 ms
35,200 KB
30_large_04.in AC 321 ms
47,472 KB
30_large_05.in AC 337 ms
44,592 KB
30_large_06.in AC 151 ms
24,140 KB
30_large_07.in AC 235 ms
35,432 KB
30_large_08.in AC 322 ms
44,456 KB
30_large_09.in AC 274 ms
38,444 KB
30_large_10.in AC 151 ms
24,572 KB
40_corner_01.in AC 347 ms
44,216 KB
40_corner_02.in AC 359 ms
44,496 KB
40_corner_03.in AC 382 ms
44,036 KB
40_corner_04.in AC 87 ms
19,244 KB
40_corner_05.in AC 88 ms
19,248 KB
system_test1.txt AC 339 ms
38,436 KB
system_test2.txt AC 182 ms
30,952 KB
system_test3.txt AC 218 ms
33,704 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