Submission #4969555


Source Code Expand

Copy
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        List<Integer> shiseiList = new ArrayList<>();

        for (int i = 0; i < s.length(); i++){
            int value = Character.getNumericValue(s.charAt(i));
            shiseiList.add(value);
        }

        List<Integer> changePointList = new ArrayList<>();

        for (int i = 0; i < n; i++){
            if (i == 0){
                changePointList.add(i);
            }else {
                if (!shiseiList.get(i).equals(shiseiList.get(i - 1))){
                    changePointList.add(i);
                }
            }
        }
        // end point
        changePointList.add(n);
        int changeSize = changePointList.size();
        List<Integer> answerList = new ArrayList<>();

        for (int i = 0; i < changeSize - 1; i++){
            int shisei = shiseiList.get(changePointList.get(i));
            if (shisei == 1){
                int endIndex = Math.min(i + k * 2 + 1, changeSize - 1);
                answerList.add(changePointList.get(endIndex) - changePointList.get(i));
            }else {
                int endIndex = Math.min(i + 2 * k, changeSize - 1);
                answerList.add(changePointList.get(endIndex) - changePointList.get(i));
            }
        }

        answerList.sort(Comparator.reverseOrder());

        System.out.println(answerList.get(0));

    }

}

Submission Info

Submission Time
Task D - Handstand
User alkwest
Language Java8 (OpenJDK 1.8.0)
Score 400
Code Size 1593 Byte
Status
Exec Time 223 ms
Memory 32880 KB

Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15
Sample 0 / 0 sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 94 ms 21204 KB
sample_02 93 ms 19156 KB
sample_03 92 ms 20820 KB
testcase_01 142 ms 24660 KB
testcase_02 158 ms 23760 KB
testcase_03 216 ms 26248 KB
testcase_04 94 ms 21076 KB
testcase_05 223 ms 30024 KB
testcase_06 220 ms 29480 KB
testcase_07 222 ms 32880 KB
testcase_08 211 ms 32044 KB
testcase_09 203 ms 31216 KB
testcase_10 176 ms 22764 KB
testcase_11 133 ms 24276 KB
testcase_12 142 ms 24148 KB
testcase_13 179 ms 23908 KB
testcase_14 184 ms 26480 KB
testcase_15 95 ms 21332 KB