結果

問題 No.202 1円玉投げ
ユーザー uwiuwi
提出日時 2015-05-03 23:30:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,279 ms / 5,000 ms
コード長 6,002 bytes
コンパイル時間 6,381 ms
コンパイル使用メモリ 81,552 KB
実行使用メモリ 57,444 KB
最終ジャッジ日時 2023-08-23 21:30:24
合計ジャッジ時間 49,354 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,273 ms
56,480 KB
testcase_01 AC 2,273 ms
56,644 KB
testcase_02 AC 44 ms
49,220 KB
testcase_03 AC 45 ms
49,596 KB
testcase_04 AC 44 ms
49,248 KB
testcase_05 AC 291 ms
54,972 KB
testcase_06 AC 1,914 ms
57,040 KB
testcase_07 AC 2,124 ms
55,188 KB
testcase_08 AC 2,110 ms
57,184 KB
testcase_09 AC 1,231 ms
56,932 KB
testcase_10 AC 622 ms
52,992 KB
testcase_11 AC 1,077 ms
56,892 KB
testcase_12 AC 1,103 ms
56,984 KB
testcase_13 AC 682 ms
54,804 KB
testcase_14 AC 336 ms
55,072 KB
testcase_15 AC 1,257 ms
56,904 KB
testcase_16 AC 2,271 ms
55,832 KB
testcase_17 AC 2,264 ms
56,044 KB
testcase_18 AC 2,279 ms
56,096 KB
testcase_19 AC 1,135 ms
56,904 KB
testcase_20 AC 1,708 ms
57,444 KB
testcase_21 AC 1,189 ms
56,856 KB
testcase_22 AC 111 ms
51,844 KB
testcase_23 AC 136 ms
54,016 KB
testcase_24 AC 113 ms
52,912 KB
testcase_25 AC 114 ms
53,636 KB
testcase_26 AC 111 ms
53,748 KB
testcase_27 AC 112 ms
53,508 KB
testcase_28 AC 60 ms
50,300 KB
testcase_29 AC 61 ms
50,204 KB
testcase_30 AC 111 ms
53,228 KB
testcase_31 AC 46 ms
49,296 KB
testcase_32 AC 113 ms
53,392 KB
testcase_33 AC 104 ms
53,516 KB
testcase_34 AC 132 ms
53,992 KB
testcase_35 AC 2,275 ms
56,088 KB
testcase_36 AC 2,270 ms
55,912 KB
testcase_37 AC 2,114 ms
57,064 KB
testcase_38 AC 2,239 ms
55,936 KB
testcase_39 AC 69 ms
50,400 KB
testcase_40 AC 69 ms
51,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package contest;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Q476 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	void solve()
	{
		int n = ni();
		LongHashSet lhs = new LongHashSet();
		int o = 100000;
		int ret = 0;
		outer:
		for(int z = 0;z < n;z++){
			int x = ni(), y = ni();
			for(int i = 0;i <= 20;i++){
				for(int j = 0;i*i+j*j < 400;j++){
					if(lhs.contains((long)x+o+i<<32|y+o+j))continue outer;
					if(lhs.contains((long)x+o-i<<32|y+o+j))continue outer;
					if(lhs.contains((long)x+o+i<<32|y+o-j))continue outer;
					if(lhs.contains((long)x+o-i<<32|y+o-j))continue outer;
				}
			}
			lhs.add((long)x+o<<32|y+o);
			ret++;
		}
		out.println(ret);
	}
	
	public static class LongHashSet {
		public long[] keys;
		public boolean[] allocated;
		private int scale = 1<<2;
		private int rscale = 1<<1;
		private int mask = scale-1;
		public int size = 0;
		
		public LongHashSet(){
			allocated = new boolean[scale];
			keys = new long[scale];
		}
		
		public boolean contains(long x)
		{
			int pos = h(x)&mask;
			while(allocated[pos]){
				if(x == keys[pos])return true;
				pos = pos+1&mask;
			}
			return false;
		}
		
		public boolean add(long x)
		{
			int pos = h(x)&mask;
			while(allocated[pos]){
				if(x == keys[pos])return false;
				pos = pos+1&mask;
			}
			if(size == rscale){
				resizeAndAdd(x);
			}else{
				keys[pos] = x;
				allocated[pos] = true;
			}
			size++;
			return true;
		}
		
		public boolean remove(long x)
		{
			int pos = h(x)&mask;
			while(allocated[pos]){
				if(x == keys[pos]){
					size--;
					// take last and fill rmpos
					int last = pos;
					pos = pos+1&mask;
					while(allocated[pos]){
						int lh = h(keys[pos])&mask;
						// lh <= last < pos
						if(
								lh <= last && last < pos ||
								pos < lh && lh <= last ||
								last < pos && pos < lh
								){
							keys[last] = keys[pos];
							last = pos;
						}
						pos = pos+1&mask;
					}
					keys[last] = 0;
					allocated[last] = false;
					
					return true;
				}
				pos = pos+1&mask;
			}
			return false;
		}
		
		private void resizeAndAdd(long x)
		{
			int nscale = scale<<1;
			int nrscale = rscale<<1;
			int nmask = nscale-1;
			boolean[] nallocated = new boolean[nscale];
			long[] nkeys = new long[nscale];
			for(int i = next(0);i < scale;i = next(i+1)){
				long y = keys[i];
				int pos = h(y)&nmask;
				while(nallocated[pos])pos = pos+1&nmask;
				nkeys[pos] = y;
				nallocated[pos] = true;
			}
			{
				int pos = h(x)&nmask;
				while(nallocated[pos])pos = pos+1&nmask;
				nkeys[pos] = x;
				nallocated[pos] = true;
			}
			allocated = nallocated;
			keys = nkeys;
			scale = nscale;
			rscale = nrscale;
			mask = nmask;
		}
		
		public int next(int itr)
		{
			while(itr < scale && !allocated[itr])itr++;
			return itr;
		}
		
		
//		public int h(int x)
//		{
//			x ^= x>>>16;
//			x *= 0x85ebca6b;
//			x ^= x>>>13;
//			x *= 0xc2b2ae35;
//			x ^= x>>>16;
//			return x;
//		}
		
		private int h(long x)
		{
			x ^= x>>>33;
			x *= 0xff51afd7ed558ccdL;
			x ^= x>>>33;
			x *= 0xc4ceb9fe1a85ec53L;
			x ^= x>>>33;
			return (int)(x^x>>>32);
		}
		
		@Override
		public String toString()
		{
			StringBuilder sb = new StringBuilder();
			for(int i = next(0);i < scale;i = next(i+1)){
				sb.append(",");
				sb.append(keys[i]);
			}
			return sb.length() == 0 ? "" : sb.substring(1);
		}
	}

	
	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void main(String[] args) throws Exception { new Q476().run(); }
	
	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}
0