public class cie { public static void main(String[] args) { CieploZimno solver = new CieploZimno(); solver.solve(); } static class CieploZimno { int DIFF = 0; public void solve() { // solRandom(out); soll(); } private void soll() { // init(inputData); int d = cielib.podajD(); int r = cielib.podajR(); int k = cielib.podajK(); DIFF = r; CieploZimno.Range ranges[] = new CieploZimno.Range[d]; for (int i = 0; i < d; i++) { ranges[i] = new CieploZimno.Range(0, r); } while (DIFF > 0) { int TMP = DIFF; DIFF = 0; if (TMP == 1) { for (int i = 0; i < d; i++) { resetCallSpecial(ranges, i, r); int a2 = secondCallSpecial(ranges, i, r); if (ranges[i].lo == 0) { if (a2 == 0) { updateUpper(ranges, i); } else { updateLower(ranges, i); } } else { if (a2 == 0) { updateLower(ranges, i); } else { updateUpper(ranges, i); } } } } else { for (int i = 0; i < d; i++) { if (ranges[i].diff() == 1) continue; if (ranges[i].diff() < TMP) { int a2 = twoSpecialCalls(ranges, i, r); if (ranges[i].lo == 0) { if (a2 == 0) { updateUpper(ranges, i); } else { updateLower(ranges, i); } } else { if (a2 == 0) { updateLower(ranges, i); } else { updateUpper(ranges, i); } } } else { resetCall(ranges, i); int a2 = secondCall(ranges, i); if (a2 == 1) { updateUpper(ranges, i); } else { updateLower(ranges, i); } } DIFF = Math.max(DIFF, ranges[i].diff()); } } } int[] ans = answer(ranges); cielib.znalazlem(ans); } private int twoSpecialCalls(CieploZimno.Range[] ranges, int d, int r) { resetCallSpecial(ranges, d, r); return secondCallSpecial(ranges, d, r); } private int secondCallSpecial(CieploZimno.Range[] ranges, int d, int r) { int[] q = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { q[i] = ranges[i].pointer; } if (ranges[d].lo == 0) { q[d] = ranges[d].lo; } else { q[d] = ranges[d].hi; } return cielib.czyCieplo(q); } private int resetCallSpecial(CieploZimno.Range[] ranges, int d, int r) { reset(ranges); int[] q = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { q[i] = ranges[i].pointer; } if (ranges[d].lo == 0) { q[d] = ranges[d].hi + 1; } else { q[d] = ranges[d].lo - 1; } return cielib.czyCieplo(q); } private int[] answer(CieploZimno.Range[] ranges) { reset(ranges); int[] ans = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { ans[i] = ranges[i].pointer; } return ans; } private void updateLower(CieploZimno.Range[] ranges, int d) { ranges[d].updateToLowerHalf(); } private void updateUpper(CieploZimno.Range[] ranges, int d) { ranges[d].updateToUpperHalf(); } private int secondCall(CieploZimno.Range[] ranges, int d) { int[] q = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { q[i] = ranges[i].pointer; } q[d] = ranges[d].hi; return cielib.czyCieplo(q); } private int resetCall(CieploZimno.Range[] ranges, int d) { reset(ranges); int[] q = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { q[i] = ranges[i].pointer; } q[d] = ranges[d].lo; return cielib.czyCieplo(q); } private void reset(CieploZimno.Range[] ranges) { for (CieploZimno.Range r : ranges) { r.reset(); } } private static class Range { private int lo; private int hi; private int pointer; public Range(int lo, int hi) { this.lo = lo; this.hi = hi; } public void reset() { pointer = (lo + hi + 1) / 2; } public void updateToUpperHalf() { if (this.hi - this.lo == 1) { this.lo = this.hi; } else { this.lo = pointer; } } public void updateToLowerHalf() { if (this.hi - this.lo == 1) { this.hi = this.lo; } else { this.hi = pointer; } } public int diff() { return this.hi - this.lo; } } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | public class cie { public static void main(String[] args) { CieploZimno solver = new CieploZimno(); solver.solve(); } static class CieploZimno { int DIFF = 0; public void solve() { // solRandom(out); soll(); } private void soll() { // init(inputData); int d = cielib.podajD(); int r = cielib.podajR(); int k = cielib.podajK(); DIFF = r; CieploZimno.Range ranges[] = new CieploZimno.Range[d]; for (int i = 0; i < d; i++) { ranges[i] = new CieploZimno.Range(0, r); } while (DIFF > 0) { int TMP = DIFF; DIFF = 0; if (TMP == 1) { for (int i = 0; i < d; i++) { resetCallSpecial(ranges, i, r); int a2 = secondCallSpecial(ranges, i, r); if (ranges[i].lo == 0) { if (a2 == 0) { updateUpper(ranges, i); } else { updateLower(ranges, i); } } else { if (a2 == 0) { updateLower(ranges, i); } else { updateUpper(ranges, i); } } } } else { for (int i = 0; i < d; i++) { if (ranges[i].diff() == 1) continue; if (ranges[i].diff() < TMP) { int a2 = twoSpecialCalls(ranges, i, r); if (ranges[i].lo == 0) { if (a2 == 0) { updateUpper(ranges, i); } else { updateLower(ranges, i); } } else { if (a2 == 0) { updateLower(ranges, i); } else { updateUpper(ranges, i); } } } else { resetCall(ranges, i); int a2 = secondCall(ranges, i); if (a2 == 1) { updateUpper(ranges, i); } else { updateLower(ranges, i); } } DIFF = Math.max(DIFF, ranges[i].diff()); } } } int[] ans = answer(ranges); cielib.znalazlem(ans); } private int twoSpecialCalls(CieploZimno.Range[] ranges, int d, int r) { resetCallSpecial(ranges, d, r); return secondCallSpecial(ranges, d, r); } private int secondCallSpecial(CieploZimno.Range[] ranges, int d, int r) { int[] q = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { q[i] = ranges[i].pointer; } if (ranges[d].lo == 0) { q[d] = ranges[d].lo; } else { q[d] = ranges[d].hi; } return cielib.czyCieplo(q); } private int resetCallSpecial(CieploZimno.Range[] ranges, int d, int r) { reset(ranges); int[] q = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { q[i] = ranges[i].pointer; } if (ranges[d].lo == 0) { q[d] = ranges[d].hi + 1; } else { q[d] = ranges[d].lo - 1; } return cielib.czyCieplo(q); } private int[] answer(CieploZimno.Range[] ranges) { reset(ranges); int[] ans = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { ans[i] = ranges[i].pointer; } return ans; } private void updateLower(CieploZimno.Range[] ranges, int d) { ranges[d].updateToLowerHalf(); } private void updateUpper(CieploZimno.Range[] ranges, int d) { ranges[d].updateToUpperHalf(); } private int secondCall(CieploZimno.Range[] ranges, int d) { int[] q = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { q[i] = ranges[i].pointer; } q[d] = ranges[d].hi; return cielib.czyCieplo(q); } private int resetCall(CieploZimno.Range[] ranges, int d) { reset(ranges); int[] q = new int[ranges.length]; for (int i = 0; i < ranges.length; i++) { q[i] = ranges[i].pointer; } q[d] = ranges[d].lo; return cielib.czyCieplo(q); } private void reset(CieploZimno.Range[] ranges) { for (CieploZimno.Range r : ranges) { r.reset(); } } private static class Range { private int lo; private int hi; private int pointer; public Range(int lo, int hi) { this.lo = lo; this.hi = hi; } public void reset() { pointer = (lo + hi + 1) / 2; } public void updateToUpperHalf() { if (this.hi - this.lo == 1) { this.lo = this.hi; } else { this.lo = pointer; } } public void updateToLowerHalf() { if (this.hi - this.lo == 1) { this.hi = this.lo; } else { this.hi = pointer; } } public int diff() { return this.hi - this.lo; } } } } |