結果
問題 | No.608 God's Maze |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2017-12-08 02:35:02 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,515 bytes |
コンパイル時間 | 2,454 ms |
コンパイル使用メモリ | 92,172 KB |
実行使用メモリ | 44,996 KB |
最終ジャッジ日時 | 2024-05-06 19:49:13 |
合計ジャッジ時間 | 9,487 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 63 ms
38,096 KB |
testcase_05 | AC | 75 ms
38,000 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 67 ms
38,028 KB |
testcase_10 | AC | 64 ms
37,880 KB |
testcase_11 | WA | - |
testcase_12 | AC | 63 ms
37,836 KB |
testcase_13 | AC | 73 ms
39,996 KB |
testcase_14 | WA | - |
testcase_15 | AC | 65 ms
38,268 KB |
testcase_16 | AC | 85 ms
40,136 KB |
testcase_17 | AC | 90 ms
39,052 KB |
testcase_18 | AC | 69 ms
38,476 KB |
testcase_19 | AC | 65 ms
37,832 KB |
testcase_20 | AC | 69 ms
38,316 KB |
testcase_21 | AC | 67 ms
37,948 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 68 ms
38,376 KB |
testcase_25 | AC | 69 ms
38,216 KB |
testcase_26 | AC | 73 ms
38,076 KB |
testcase_27 | AC | 88 ms
39,628 KB |
testcase_28 | AC | 77 ms
37,988 KB |
testcase_29 | WA | - |
testcase_30 | AC | 140 ms
43,620 KB |
testcase_31 | AC | 119 ms
42,304 KB |
testcase_32 | AC | 124 ms
43,028 KB |
testcase_33 | AC | 169 ms
44,732 KB |
testcase_34 | AC | 131 ms
43,144 KB |
testcase_35 | AC | 88 ms
40,500 KB |
testcase_36 | AC | 104 ms
41,724 KB |
testcase_37 | AC | 106 ms
41,596 KB |
testcase_38 | AC | 121 ms
43,204 KB |
testcase_39 | AC | 86 ms
40,476 KB |
testcase_40 | AC | 107 ms
41,676 KB |
testcase_41 | AC | 109 ms
41,696 KB |
testcase_42 | AC | 139 ms
44,768 KB |
testcase_43 | AC | 99 ms
40,804 KB |
testcase_44 | AC | 154 ms
43,548 KB |
testcase_45 | AC | 135 ms
43,520 KB |
testcase_46 | AC | 87 ms
40,268 KB |
testcase_47 | AC | 65 ms
38,224 KB |
testcase_48 | AC | 138 ms
43,752 KB |
testcase_49 | AC | 105 ms
41,884 KB |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | AC | 66 ms
37,884 KB |
testcase_54 | WA | - |
testcase_55 | RE | - |
testcase_56 | AC | 78 ms
38,632 KB |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | AC | 65 ms
38,232 KB |
testcase_64 | AC | 75 ms
39,908 KB |
ソースコード
import java.io.*; import java.util.*; class Main { static String s; static int[]zero,one; static int f(int a,int l,int r,int fs,int fe){ System.err.printf("enter f(%d,%d,%d,%d,%d)\n",a,l,r,fs,fe); if(fs>=fe){ fs=-1;fe=-1; } if(fs==-1){ int m=Integer.MAX_VALUE; int i1=Arrays.binarySearch(one,r); if(i1<0)i1=-i1-1; int i2=Arrays.binarySearch(one,l); if(i2<0)i2=-i2-1; if(i1==i2){ return 0; } int x=one[i2],y=one[i1-1]; if(x<a)m=Math.min(m,a-x+f(x,x+1,r,x+1,a)); if(a<y)m=Math.min(m,y-a+f(y,l,y,a+1,y)); System.err.println("f("+a+","+l+","+r+")="+m); return m; } int ans; if(a<l){ int nxt=-1; System.err.println(Arrays.toString(one) + " r = " + r + " fe = " + fe); int i1=Arrays.binarySearch(one,r); if(i1<0)i1=-i1-1; int i2=Arrays.binarySearch(one,fe); if(i2<0)i2=-i2-1; System.err.println("i1="+i1+" i2="+i2); if(i1>i2){ nxt=one[i1-1]; System.err.println("nxt = " + nxt); ans=nxt-a+f(nxt,l,nxt,fe,nxt); }else{ int i3=Arrays.binarySearch(zero,fe); if(i3<0)i3=-i3-1; int i4=Arrays.binarySearch(zero,fs); if(i4<0)i4=-i4-1; if(i3>i4){ nxt=zero[i3-1]; ans=nxt-a+f(nxt,l,nxt,-1,-1); }else ans=0; } }else{ int nxt=-1; int i1=Arrays.binarySearch(one,r); if(i1<0)i1=-i1-1; int i2=Arrays.binarySearch(one,l); if(i2<0)i2=-i2-1; System.err.println("i1="+i1+" i2="+i2); if(i1>i2){ nxt=one[i2]; ans=a-nxt+f(nxt,nxt+1,r,nxt+1,fs); }else{ int i3=Arrays.binarySearch(zero,r); if(i3<0)i3=-i3-1; int i4=Arrays.binarySearch(zero,fs); if(i4<0)i4=-i4-1; if(i3>i4){ nxt=zero[i4]; ans=a-nxt+f(nxt,nxt+1,r,-1,-1); }else ans=0; } } System.err.printf("f(%d,%d,%d,%d,%d)=%d\n",a,l,r,fs,fe,ans); return ans; } static int g(int[]x,int a){ int ans=0; int[]oldx=x.clone(); int n=x.length; int p=a; int last=0; for(int i=0;i<n;++i) if(x[i]==1)last=i; while(true){ int p2=p+1; while(p2<=last&&x[p2]!=0)p2++; if(p2==last+1){ ans+=last-p; break; } x[p2]=1; x[p2+1]=1-x[p2+1]; if(last==p2+1)last=p2; ans+=p2-p+2; p=p2; } //System.err.println("g("+Arrays.toString(oldx)+","+a+")="+ans); return ans; } public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt()-1; s=sc.next(); int l=s.length(); int p=0,q=0; zero=new int[s.length()]; one=new int[s.length()]; for(int i=0;i<s.length();++i) if(s.charAt(i)=='.') zero[p++]=i; else one[q++]=i; zero=Arrays.copyOf(zero,p); one=Arrays.copyOf(one,q); int[]t=new int[l]; for(int i=0;i<l;++i) t[i]=s.charAt(i)=='#'?1:0; int[]u=t.clone(); int x=one[0],y=one[q-1]; System.err.println("x="+x+" y="+y); int m=Integer.MAX_VALUE; if(x<n) for(int i=x;i<n;++i)u[i]=1-u[i]; m=Math.min(m,Math.max(0,n-x)+g(u,x)); u=t.clone(); if(n<y) for(int i=n+1;i<=y;++i)u[i]=1-u[i]; for(int i=0;i<l/2;++i){ int temp=u[i]; u[i]=u[l-1-i]; u[l-1-i]=temp; } m=Math.min(m,Math.max(0,y-n)+g(u,l-1-y)); out.println(m); out.close(); } // http://codeforces.com/blog/entry/7018 //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }