結果

問題 No.608 God's Maze
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-08 02:38:46
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 3,310 bytes
コンパイル時間 3,888 ms
コンパイル使用メモリ 77,048 KB
実行使用メモリ 56,856 KB
最終ジャッジ日時 2023-08-19 12:43:52
合計ジャッジ時間 11,755 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 66 ms
50,692 KB
testcase_02 WA -
testcase_03 AC 73 ms
52,376 KB
testcase_04 AC 66 ms
50,788 KB
testcase_05 AC 65 ms
50,852 KB
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 AC 62 ms
50,596 KB
testcase_10 AC 61 ms
51,628 KB
testcase_11 AC 65 ms
50,908 KB
testcase_12 AC 70 ms
53,060 KB
testcase_13 AC 76 ms
53,404 KB
testcase_14 AC 70 ms
52,652 KB
testcase_15 AC 65 ms
50,692 KB
testcase_16 AC 70 ms
52,420 KB
testcase_17 AC 68 ms
52,600 KB
testcase_18 AC 67 ms
50,684 KB
testcase_19 AC 67 ms
52,600 KB
testcase_20 AC 65 ms
50,684 KB
testcase_21 AC 64 ms
50,892 KB
testcase_22 AC 76 ms
53,276 KB
testcase_23 WA -
testcase_24 AC 68 ms
50,852 KB
testcase_25 AC 62 ms
50,844 KB
testcase_26 AC 64 ms
50,672 KB
testcase_27 AC 64 ms
51,964 KB
testcase_28 AC 64 ms
51,048 KB
testcase_29 AC 125 ms
56,516 KB
testcase_30 AC 126 ms
56,652 KB
testcase_31 AC 115 ms
56,140 KB
testcase_32 AC 125 ms
56,496 KB
testcase_33 AC 145 ms
55,112 KB
testcase_34 AC 131 ms
56,668 KB
testcase_35 AC 84 ms
52,692 KB
testcase_36 AC 101 ms
54,584 KB
testcase_37 AC 102 ms
54,072 KB
testcase_38 AC 123 ms
56,236 KB
testcase_39 AC 79 ms
52,668 KB
testcase_40 AC 101 ms
54,104 KB
testcase_41 AC 102 ms
54,344 KB
testcase_42 AC 134 ms
56,856 KB
testcase_43 AC 100 ms
54,848 KB
testcase_44 AC 141 ms
56,252 KB
testcase_45 AC 134 ms
56,404 KB
testcase_46 AC 83 ms
54,400 KB
testcase_47 AC 63 ms
51,992 KB
testcase_48 AC 128 ms
56,064 KB
testcase_49 AC 101 ms
53,832 KB
testcase_50 AC 66 ms
52,652 KB
testcase_51 AC 66 ms
51,076 KB
testcase_52 AC 67 ms
51,228 KB
testcase_53 AC 68 ms
52,168 KB
testcase_54 AC 67 ms
52,588 KB
testcase_55 RE -
testcase_56 AC 69 ms
53,512 KB
testcase_57 AC 68 ms
52,368 KB
testcase_58 WA -
testcase_59 AC 63 ms
50,712 KB
testcase_60 AC 62 ms
51,936 KB
testcase_61 AC 62 ms
50,884 KB
testcase_62 AC 62 ms
50,984 KB
testcase_63 AC 65 ms
51,452 KB
testcase_64 AC 71 ms
52,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    static String s;
    static int[]zero,one;
    static int g(int[]x,int a){
        int ans=0;
        int[]oldx=x.clone();
        int n=x.length;
        if(x[a]==1)
            if(a==n-1)return 0x3fffffff;
            else{
                x[a]=0;
                x[a+1]=1-x[a+1];
                ans+=2;
            }
        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;
        }
    }
}
0