File tree Expand file tree Collapse file tree 1 file changed +75
-0
lines changed
Expand file tree Collapse file tree 1 file changed +75
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ static int n, k;
7+ static int [] str;
8+ static boolean [] robot;
9+
10+ public static void main (String [] args ) throws IOException {
11+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
12+ StringTokenizer st = new StringTokenizer (br. readLine());
13+
14+ n = Integer . parseInt(st. nextToken());
15+ k = Integer . parseInt(st. nextToken());
16+
17+ str = new int [2 * n];
18+ robot = new boolean [n];
19+
20+ st = new StringTokenizer (br. readLine());
21+ for (int i = 0 ; i < 2 * n; i++ ) {
22+ str[i] = Integer . parseInt(st. nextToken());
23+ }
24+
25+ int stage = 0 ;
26+ while (true ) {
27+ stage++ ;
28+
29+ int laststr = str[2 * n - 1 ];
30+ for (int i = 2 * n - 1 ; i > 0 ; i-- ) {
31+ str[i] = str[i - 1 ];
32+ }
33+ str[0 ] = laststr;
34+
35+ for (int i = n - 1 ; i > 0 ; i-- ) {
36+ robot[i] = robot[i - 1 ];
37+ }
38+ robot[0 ] = false ;
39+
40+ if (robot[n - 1 ]) {
41+ robot[n - 1 ] = false ;
42+ }
43+
44+ for (int i = n - 2 ; i >= 0 ; i-- ) {
45+ if (robot[i] && ! robot[i + 1 ] && str[i + 1 ] >= 1 ) {
46+ robot[i] = false ;
47+ robot[i + 1 ] = true ;
48+ str[i + 1 ]-- ;
49+ }
50+ }
51+
52+ if (robot[n - 1 ]) {
53+ robot[n - 1 ] = false ;
54+ }
55+
56+ if (str[0 ] > 0 ) {
57+ robot[0 ] = true ;
58+ str[0 ]-- ;
59+ }
60+
61+ int zerostr = 0 ;
62+ for (int d : str) {
63+ if (d == 0 ) {
64+ zerostr++ ;
65+ }
66+ }
67+ if (zerostr >= k) {
68+ break ;
69+ }
70+ }
71+
72+ System . out. println(stage);
73+ }
74+ }
75+ ```
You can’t perform that action at this time.
0 commit comments