Submission #37925
ソースコード
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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | import java.io.*; import java.util.*; import java.lang.*; import java.math.*; import java.text.*; class Main{ static final Scanner in = new Scanner(System.in); static final PrintWriter out = new PrintWriter(System.out); public static void main(String args[]){ int [][] map = new int [1010][1010]; final int h = fgetInt(); final int w = fgetInt(); int i, j; for ( i = 0; i < h; i++ ) { for ( j = 0; j < w; j++ ) { map[i][j] = fgetInt(); if ( i == 0 && j == 0 ); else if ( i == 0 ){ map[0][j] += map[0][j-1]; } else if ( j == 0 ) { map[i][0] += map[i-1][0]; } else { map[i][j] += Math.max(map[i-1][j], map[i][j-1]); } } } iprint(map[h-1][w-1]); ifin(); } static String fgetStr(){ return FastScanner.next(); } static String fgetLine(){ return FastScanner.nextLine(); } static char fgetChar(){ return fgetStr().charAt(0); } static int fgetInt(){ return FastScanner.nextInt(); } static long fgetLong(){ return FastScanner.nextLong(); } static double fgetDouble(){ return FastScanner.nextDouble(); } static BigInteger getBig(){ return in.nextBigInteger(); } static String reverseStr(String str){ StringBuffer sb = new StringBuffer(str); return sb.reverse().toString(); } static void iprint(Object a){ out.println(a); } static void iprintf(Object a){ out.print(a); } static void ifin(){ out.flush(); } static int upperBound( int [] a, int n, int val){ int low = 0; int hi = n; while ( low < hi ) { int mid = (low+hi) / 2; if ( a[mid] <= val ) low = mid + 1; else hi = mid; } return low; } static int lowerBound( int [] a, int n, int val){ int low = 0; int hi = n; while ( low < hi ) { int mid = (low+hi) / 2; if ( a[mid] < val ) low = mid + 1; else hi = mid; } return low; } /* static void hanoiNoTou(int n, String start, String temp, String target) { if ( 0 < n ) { hanoiNoTou(n - 1, start, target, temp); iprint(n + " : " + start + " -> " + target); hanoiNoTou(n - 1, temp, start, target); } } */ /* @Deprecated static String getStr(){ return in.next(); } @Deprecated static String getLine(){ return in.nextLine(); } @Deprecated static int getInt(){ return Integer.parseInt(getStr()); } @Deprecated static long getLong(){ return Long.parseLong(getStr()); } @Deprecated static double getDouble(){ return Double.parseDouble(getStr()); } @Deprecated static void print(Object a){ System.out.println(a); } @Deprecated static void printf(Object a){ System.out.print(a); }*/ } class FastScanner { private static final InputStream in = System.in; private static final byte[] buffer = new byte[1024]; private static int ptr = 0; private static int buflen = 0; private static boolean hasNextByte() { if (ptr < buflen) { return true ; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false ; } } return true ; } private static int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar( int c) { return 33 <= c && c <= 126;} public static boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public static String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public static String nextLine() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b) || b == 32) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public static long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false ; int b = readByte(); if (b == '-' ) { minus = true ; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while ( true ){ if ( '0' <= b && b <= '9' ) { n *= 10; n += b - '0' ; } else if (b == -1 || !isPrintableChar(b)){ return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public static int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return ( int ) nl; } public static double nextDouble() { return Double.parseDouble(next());} } /* class Bunsuu { private static boolean doAutoYakubun = false; private int bunshi; private int bunbo; public Bunsuu(int bunshi, int bunbo){ this.bunshi = bunshi; this.bunbo = bunbo ; } public Bunsuu yakubun(Bunsuu b){ int targetBunbo = b.bunbo; int targetBunshi = b.bunshi; int i = 2; int n = Math.max(targetBunshi, targetBunbo); while ( i <= n ) { while ( targetBunbo%i == 0 && targetBunshi%i == 0 ) { targetBunbo /= i; targetBunshi /= i; } i++; n = Math.max(targetBunshi, targetBunbo); } return new Bunsuu(targetBunshi, targetBunbo); } public Bunsuu yakubun(int bunshi, int bunbo){ int targetBunbo = bunbo; int targetBunshi = bunshi; int i = 2; int n = Math.max(targetBunshi, targetBunbo); while ( i <= n ) { while ( targetBunbo%i == 0 && targetBunshi%i == 0 ) { targetBunbo /= i; targetBunshi /= i; } i++; n = Math.max(targetBunshi, targetBunbo); } if ( targetBunbo < 0 ) { targetBunbo *= -1; targetBunshi *= -1; } return new Bunsuu(targetBunshi, targetBunbo); } public Bunsuu tashizan(Object o) { if ( o instanceof Bunsuu ) { Bunsuu b = (Bunsuu)o; return yakubun((b.bunshi * bunbo) + (bunshi * b.bunbo), b.bunbo * bunbo); } else if ( o instanceof Integer) { int a = (int)o; return yakubun(bunshi + a*bunbo, bunbo); } else { throw new NumberFormatException(); } } public Bunsuu hikizan(Object o) { if ( o instanceof Bunsuu ) { Bunsuu b = (Bunsuu)o; return this.tashizan(b.kakezan(-1)); } else if ( o instanceof Integer) { int a = (int)o; return this.tashizan(a*-1); } else { throw new NumberFormatException(); } } public Bunsuu kakezan(Object o) { if ( o instanceof Bunsuu ) { Bunsuu b = (Bunsuu)o; return yakubun(b.bunshi * bunshi, b.bunbo * bunbo); } else if ( o instanceof Integer) { int a = (int)o; return yakubun(bunshi * a, bunbo); } else { throw new NumberFormatException(); } } public Bunsuu warizan(Object o) { if ( o instanceof Bunsuu ) { Bunsuu b = (Bunsuu)o; return this.kakezan(new Bunsuu(b.bunbo, b.bunshi)); } else if ( o instanceof Integer) { int a = (int)o; return this.kakezan(new Bunsuu(1, a)); } else { throw new NumberFormatException(); } } public Bunsuu ruijou(int shisuu) { if ( shisuu == 0 ) { return new Bunsuu(1, 1); } if ( shisuu < 0 ) { Bunsuu temp = new Bunsuu(bunbo, bunshi); return temp.ruijou(-1*shisuu); } Bunsuu temp = this; for ( int i = 1; i < shisuu; i++ ) { temp = temp.kakezan(this); } return temp; } public String getBunsuu(){ if ( bunbo == 1 ) return bunshi + ""; return bunshi + "/" + bunbo; } public double getKinjichi(){ return (double)bunshi/bunbo; } }*/ /* class UnionFind { private int[] parent; private int[] rank; public UnionFind(int n) { parent = new int[n]; rank = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; rank[i] = 0; } } public void union(int x, int y) { int rootX = find(x); int rootY = find(y); if (rank[rootX] > rank[rootY]) { parent[rootY] = rootX; } else if(rank[rootX] < rank[rootY]) { parent[rootX] = rootY; } else if (rootX != rootY){ parent[rootY] = rootX; rank[rootX]++; } } public int find(int i) { if (i != parent[i]) { parent[i] = find(parent[i]); } return parent[i]; } public boolean isSame(int x, int y) { return find(x) == find(y); } } */ |
ステータス
項目 | データ |
---|---|
問題 | 0910 - 百円以下の拾得物 |
ユーザー名 | r1825 |
投稿日時 | 2018-06-27 16:33:14 |
言語 | Java |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 10615 Byte |
最大実行時間 | 269 ms |
最大メモリ使用量 | 39120 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 112 ms | 17324 KB |
1
|
in02.txt | AC | 114 ms | 17860 KB |
1
|
in03.txt | AC | 101 ms | 17680 KB |
1
|
in04.txt | AC | 90 ms | 18652 KB |
1
|
in05.txt | AC | 123 ms | 17752 KB |
1
|
in06.txt | AC | 157 ms | 21216 KB |
1
|
in07.txt | AC | 173 ms | 25740 KB |
1
|
in08.txt | AC | 233 ms | 29672 KB |
1
|
in09.txt | AC | 269 ms | 35464 KB |
1
|
in10.txt | AC | 122 ms | 35168 KB |
1
|
in11.txt | AC | 136 ms | 39120 KB |
1
|
sample_in_1.txt | AC | 103 ms | 39120 KB |
1
|
sample_in_2.txt | AC | 91 ms | 38116 KB |
1
|