結果
問題 | No.348 カゴメカゴメ |
ユーザー | threepipes_s |
提出日時 | 2016-02-27 00:07:23 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,381 bytes |
コンパイル時間 | 3,062 ms |
コンパイル使用メモリ | 100,152 KB |
実行使用メモリ | 97,068 KB |
最終ジャッジ日時 | 2024-09-24 10:41:43 |
合計ジャッジ時間 | 23,302 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 369 ms
57,440 KB |
testcase_03 | AC | 780 ms
64,592 KB |
testcase_04 | AC | 65 ms
50,272 KB |
testcase_05 | AC | 90 ms
51,372 KB |
testcase_06 | AC | 57 ms
50,772 KB |
testcase_07 | AC | 57 ms
50,588 KB |
testcase_08 | AC | 57 ms
50,588 KB |
testcase_09 | AC | 59 ms
50,600 KB |
testcase_10 | AC | 58 ms
50,612 KB |
testcase_11 | AC | 58 ms
50,208 KB |
testcase_12 | WA | - |
testcase_13 | AC | 156 ms
54,432 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 56 ms
50,576 KB |
testcase_17 | AC | 54 ms
50,604 KB |
testcase_18 | AC | 55 ms
50,288 KB |
testcase_19 | AC | 56 ms
50,668 KB |
testcase_20 | WA | - |
testcase_21 | AC | 56 ms
50,696 KB |
testcase_22 | AC | 54 ms
50,616 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | AC | 161 ms
56,688 KB |
testcase_51 | WA | - |
testcase_52 | WA | - |
ソースコード
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.BitSet; import java.util.HashMap; import java.util.List; import java.util.Queue; import java.util.Stack; public class Main { public static void main(String[] args) throws NumberFormatException, IOException {Solve solve = new Solve();solve.solve();} } class Solve{ void dump(int[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");System.out.println();} void dump(int[]a,int n){for(int i=0;i<a.length;i++)System.out.printf("%"+n+"d",a[i]);System.out.println();} void dump(long[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");System.out.println();} void dump(char[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]);System.out.println();} String itob(int a,int l){return String.format("%"+l+"s",Integer.toBinaryString(a)).replace(' ','0');} int n, m; void solve() throws NumberFormatException, IOException{ final ContestScanner in = new ContestScanner(); Writer out = new Writer(); n = in.nextInt(); m = in.nextInt(); BitSet map = new BitSet(n*m); int allx = 0; for(int i=0; i<n; i++){ char[] line = in.nextToken().toCharArray(); for(int j=0; j<m; j++){ if(line[j]=='x'){ map.set(i*m+j); allx++; } } } int sz = n*m; List<Node> node = new ArrayList<>(); final int[] dx = {1, 1, 1, 0, 0, -1, -1, -1}; final int[] dy = {1, 0, -1, 1, -1, 1, -1, 0}; final int[] dx4 = {1,0,-1,0}; final int[] dy4 = {0,1,0,-1}; BitSet used = new BitSet(); Stack<Long> oq = new Stack<>(); Stack<Integer> qu = new Stack<>(); oq.add(0L); int mask = (1<<30)-1; int id = 0; node.add(new Node(0, 0)); while(!oq.isEmpty()){ long ot = oq.pop(); final int p = (int)ot&mask; ot >>= 30; if(used.get(p)) continue; used.set(p); final int y = p/m; final int x = p%m; if(y==2 && x==13){ System.out.println(); } if(!map.get(p)){ for(int i=0; i<4; i++){ final int ny = y+dy4[i]; final int nx = x+dx4[i]; final int np = ny*m+nx; if(out(ny, nx) || used.get(np)) continue; oq.add(np|ot<<30); } }else{ id++; int left = m; int ly = 0; int size = 0; qu.clear(); qu.add(p); while(!qu.isEmpty()){ final int ip = qu.pop(); size++; final int iy = ip/m; final int ix = ip%m; if(ix<left && !map.get(iy*m+ix+1)){ left = ix; ly = iy; } for(int i=0; i<8; i++){ final int ny = iy+dy[i]; final int nx = ix+dx[i]; final int np = ny*m+nx; if(out(ny, nx) || !map.get(np) || used.get(np)) continue; used.set(np); qu.add(np); } } // p <- node if(size>3) oq.add(ly*m+left+1 | (long)id<<30); Node newnode = new Node(id, size); Node parent = node.get((int)ot); node.add(newnode); newnode.append(parent); parent.append(newnode); } } int x1 = dfs(node.get(0), -1, true); System.out.println(Math.max(x1, allx-x1)); } int dfs(Node v, int par, boolean f){ int sum = 0; for(Node nv: v.edge){ if(nv.id == par) continue; sum += dfs(nv, v.id, !f); } return sum + (f?v.size:0); } boolean out(int y, int x){ return y<0||y>=n||x<0||x>=m; } } class Node{ int id; int size; List<Node> edge = new ArrayList<>(); Node(int id, int s){ this.id = id; size = s; } void append(Node v){ edge.add(v); } } class MultiSet<T> extends HashMap<T, Integer>{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} public void sub(T key) {final int v=get(key);if(v==1)remove(key);else put(key,v-1);} } class Timer{ long time; public void set(){time=System.currentTimeMillis();} public long stop(){return time=System.currentTimeMillis()-time;} public void print() {System.out.println("Time: "+(System.currentTimeMillis()-time)+"ms");} @Override public String toString(){return"Time: "+time+"ms";} } class Writer extends PrintWriter{ public Writer(String filename)throws IOException {super(new BufferedWriter(new FileWriter(filename)));} public Writer()throws IOException{super(System.out);} } class ContestScanner { private InputStreamReader in;private int c=-2; public ContestScanner()throws IOException {in=new InputStreamReader(System.in);} public ContestScanner(String filename)throws IOException {in=new InputStreamReader(new FileInputStream(filename));} public String nextToken()throws IOException { StringBuilder sb=new StringBuilder(); while((c=in.read())!=-1&&Character.isWhitespace(c)); while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();} return sb.toString(); } public String readLine()throws IOException{ StringBuilder sb=new StringBuilder();if(c==-2)c=in.read(); while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();} return sb.toString(); } 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());} }