結果
問題 | No.202 1円玉投げ |
ユーザー | uwi |
提出日時 | 2015-05-03 23:30:55 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 2,414 ms / 5,000 ms |
コード長 | 6,002 bytes |
コンパイル時間 | 5,510 ms |
コンパイル使用メモリ | 80,864 KB |
実行使用メモリ | 57,704 KB |
最終ジャッジ日時 | 2024-06-01 18:58:51 |
合計ジャッジ時間 | 48,486 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,414 ms
56,068 KB |
testcase_01 | AC | 2,245 ms
56,040 KB |
testcase_02 | AC | 52 ms
49,928 KB |
testcase_03 | AC | 54 ms
49,988 KB |
testcase_04 | AC | 57 ms
50,128 KB |
testcase_05 | AC | 291 ms
54,812 KB |
testcase_06 | AC | 1,896 ms
57,376 KB |
testcase_07 | AC | 2,125 ms
57,428 KB |
testcase_08 | AC | 2,125 ms
57,704 KB |
testcase_09 | AC | 1,236 ms
57,036 KB |
testcase_10 | AC | 652 ms
54,492 KB |
testcase_11 | AC | 1,113 ms
57,172 KB |
testcase_12 | AC | 1,091 ms
57,092 KB |
testcase_13 | AC | 704 ms
54,868 KB |
testcase_14 | AC | 332 ms
54,888 KB |
testcase_15 | AC | 1,234 ms
57,176 KB |
testcase_16 | AC | 2,231 ms
56,008 KB |
testcase_17 | AC | 2,229 ms
55,884 KB |
testcase_18 | AC | 2,232 ms
56,012 KB |
testcase_19 | AC | 1,144 ms
57,092 KB |
testcase_20 | AC | 1,737 ms
57,312 KB |
testcase_21 | AC | 1,113 ms
56,928 KB |
testcase_22 | AC | 121 ms
53,324 KB |
testcase_23 | AC | 125 ms
53,324 KB |
testcase_24 | AC | 115 ms
53,204 KB |
testcase_25 | AC | 119 ms
53,484 KB |
testcase_26 | AC | 119 ms
53,152 KB |
testcase_27 | AC | 118 ms
53,420 KB |
testcase_28 | AC | 75 ms
51,084 KB |
testcase_29 | AC | 72 ms
51,044 KB |
testcase_30 | AC | 122 ms
53,240 KB |
testcase_31 | AC | 56 ms
49,912 KB |
testcase_32 | AC | 137 ms
53,252 KB |
testcase_33 | AC | 112 ms
53,440 KB |
testcase_34 | AC | 120 ms
53,140 KB |
testcase_35 | AC | 2,269 ms
56,136 KB |
testcase_36 | AC | 2,259 ms
56,060 KB |
testcase_37 | AC | 2,182 ms
57,524 KB |
testcase_38 | AC | 2,224 ms
56,060 KB |
testcase_39 | AC | 82 ms
50,988 KB |
testcase_40 | AC | 78 ms
50,984 KB |
ソースコード
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)); } }