結果
問題 | No.2509 Beam Shateki |
ユーザー | InTheBloom |
提出日時 | 2023-10-20 23:05:39 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,411 bytes |
コンパイル時間 | 4,254 ms |
コンパイル使用メモリ | 181,248 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-20 21:53:20 |
合計ジャッジ時間 | 3,875 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 3 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
testcase_16 | AC | 4 ms
5,376 KB |
testcase_17 | AC | 3 ms
5,376 KB |
testcase_18 | AC | 3 ms
5,376 KB |
testcase_19 | AC | 3 ms
5,376 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | AC | 3 ms
5,376 KB |
testcase_23 | AC | 3 ms
5,376 KB |
testcase_24 | AC | 4 ms
5,376 KB |
testcase_25 | AC | 3 ms
5,376 KB |
testcase_26 | AC | 3 ms
5,376 KB |
testcase_27 | AC | 4 ms
5,376 KB |
testcase_28 | AC | 3 ms
5,376 KB |
testcase_29 | AC | 3 ms
5,376 KB |
testcase_30 | AC | 3 ms
5,376 KB |
testcase_31 | WA | - |
testcase_32 | AC | 3 ms
5,376 KB |
testcase_33 | AC | 1 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 3 ms
5,376 KB |
testcase_36 | AC | 1 ms
5,376 KB |
testcase_37 | WA | - |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 1 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 3 ms
5,376 KB |
testcase_45 | AC | 1 ms
5,376 KB |
testcase_46 | AC | 1 ms
5,376 KB |
testcase_47 | AC | 3 ms
5,376 KB |
testcase_48 | AC | 2 ms
5,376 KB |
testcase_49 | AC | 2 ms
5,376 KB |
testcase_50 | AC | 3 ms
5,376 KB |
testcase_51 | AC | 1 ms
5,376 KB |
testcase_52 | AC | 2 ms
5,376 KB |
testcase_53 | AC | 1 ms
5,376 KB |
testcase_54 | WA | - |
testcase_55 | AC | 1 ms
5,376 KB |
testcase_56 | AC | 1 ms
5,376 KB |
testcase_57 | AC | 1 ms
5,376 KB |
testcase_58 | AC | 1 ms
5,376 KB |
testcase_59 | AC | 1 ms
5,376 KB |
testcase_60 | AC | 1 ms
5,376 KB |
testcase_61 | AC | 1 ms
5,376 KB |
testcase_62 | AC | 1 ms
5,376 KB |
testcase_63 | AC | 1 ms
5,376 KB |
ソースコード
import std; void main () { int H, W; readln.read(H, W); int[][] A = new int[][](H, W); foreach (i; 0..H) A[i] = readln.split.to!(int[]); solve(H, W, A); } void solve (int H, int W, int[][] A) { /** * vertical horizontally DUR DLR * | -------> _ \ * | /\ _\/ * v / * * 0 1 2 0 0 3 2 1 0 * 1 1 4 * 2 2 5 * 3 4 5 * */ int[] vertical = new int[](W); int[] horizontally = new int[](H); int[] DLR = new int[](H+W-1); int[] DUR = new int[](H+W-1); foreach (j; 0..W) foreach (i; 0..H) vertical[j] += A[i][j]; foreach (i; 0..H) foreach (j; 0..W) horizontally[i] += A[i][j]; bool isInGrid (int y, int x) { return 0 <= y && y < H && 0 <= x && x < W; } { /* DLRの計算 */ int idx = 0; int y = 0, x = W-1; int dy = 1, dx = 1; for (; 0 < x; x--) { int k = 0; while (isInGrid(y+k*dy, x+k*dx)) { DLR[idx] += A[y+k*dy][x+k*dx]; k++; } idx++; } for (; y < H; y++) { int k = 0; while (isInGrid(y+k*dy, x+k*dx)) { DLR[idx] += A[y+k*dy][x+k*dx]; k++; } idx++; } } { /* DURの計算 */ int idx = 0; int y = 0, x = 0; int dy = -1, dx = 1; for (; y < H-1; y++) { int k = 0; while (isInGrid(y+k*dy, x+k*dx)) { DUR[idx] += A[y+k*dy][x+k*dx]; k++; } idx++; } for (; x < W; x++) { int k = 0; while (isInGrid(y+k*dy, x+k*dx)) { DUR[idx] += A[y+k*dy][x+k*dx]; k++; } idx++; } } /* 累積和計算はできた。。 writeln(vertical); writeln(horizontally); writeln(DLR); writeln(DUR); */ long ans = -long.max; /* 同じやつ2つ */ if (1 < vertical.length) ans = max(ans, vertical.dup.sort!"a>b"[0..2].sum); if (1 == vertical.length) ans = max(ans, vertical.fold!max); if (1 < horizontally.length) ans = max(ans, horizontally.dup.sort!"a>b"[0..2].sum); if (1 == horizontally.length) ans = max(ans, horizontally.fold!max); if (1 < DUR.length) ans = max(ans, DUR.dup.sort!"a>b"[0..2].sum); if (1 == DUR.length) ans = max(ans, DUR.fold!max); if (1 < DLR.length) ans = max(ans, DLR.dup.sort!"a>b"[0..2].sum); if (1 == DLR.length) ans = max(ans, DLR.fold!max); /* 違うやつ2つ */ /* 1. vertical and horizontally */ foreach (i; 0..W) foreach (j; 0..H) ans = max(ans, vertical[i]+horizontally[j] - A[j][i]); /* 2. vertical and DUR */ foreach (i; 0..W) foreach (j; 0..H+W-1) { if (isInGrid(i, j-i)) { ans = max(ans, vertical[i]+DUR[j] - A[i][j-i]); } else { ans = max(ans, vertical[i] + DUR[j]); } } /* 3. vertical and DLR */ foreach (i; 0..W) foreach (j; 0..H+W-1) { if (isInGrid(1-W+i+j, i)) { ans = max(ans, vertical[i]+DLR[j] - A[1-W+i+j][i]); } else { ans = max(ans, vertical[i]+DLR[j]); } } /* 4. horizontally + DUR */ foreach (i; 0..H) foreach (j; 0..H+W-1) { if (isInGrid(j-i, i)) { ans = max(ans, horizontally[i]+DUR[j] - A[j-i][i]); } else { ans = max(ans, horizontally[i]+DUR[j]); } } /* 5. horizontally + DLR */ foreach (i; 0..H) foreach (j; 0..H+W-1) { if (isInGrid(i, W-1+i-j)) { ans = max(ans, horizontally[i]+DLR[j] - A[i][W-1+i-j]); } else { ans = max(ans, horizontally[i]+DLR[j]); } } /* 6. DUR and DLR */ foreach (i; 0..H+W-1) foreach (j; 0..H+W-1) { if ((W-1+j-i)%2 == 0 && isInGrid(j-(W-1+j-i)/2, (W-1+j-i)/2)) { ans = max(ans, DLR[i]+DUR[j] - A[j-(W-1+j-i)/2][(W-1+j-i)/2]); } else { ans = max(ans, DLR[i]+DUR[j]); } } writeln(ans); } void read(T...)(string S, ref T args) { auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }