結果
問題 | No.5002 stick xor |
ユーザー | 37zigen |
提出日時 | 2018-05-25 23:50:09 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,879 bytes |
コンパイル時間 | 6,347 ms |
実行使用メモリ | 22,964 KB |
スコア | 0 |
最終ジャッジ日時 | 2018-05-25 23:50:18 |
ジャッジサーバーID (参考情報) |
judge7 / |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
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 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
ソースコード
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { int N; int[][] curMap; int[][] A; void run() { Scanner sc = new Scanner(System.in); N = sc.nextInt(); int K = sc.nextInt(); int[] L = new int[K]; curMap = new int[N][N]; for (int i = 0; i < K; ++i) L[i] = sc.nextInt(); A = new int[N][N]; for (int i = 0; i < N; ++i) { char[] cs = sc.next().toCharArray(); for (int j = 0; j < N; ++j) { A[i][j] = (int) (cs[j] - '0'); } curMap[i] = Arrays.copyOf(A[i], A[i].length); } long[] list = new long[K]; for (int i = 0; i < K; ++i) { long op = rnd(L[i]); list[i] = op; act(curMap, op, L[i]); } for (int t = 0; t < 1000000; ++t) { int i = (int) (Math.random() * K); int j = (int) (Math.random() * K); if (i == j) continue; long opi = rnd(L[i]); long opj = rnd(L[j]); if (act(curMap, list[i], L[i]) + act(curMap, list[j], L[j]) + act(curMap, opi, L[i]) + act(curMap, opj, L[j]) > 0) { list[i] = opi; list[j] = opj; } else { act(curMap, list[i], L[i]); act(curMap, list[j], L[j]); act(curMap, opi, L[i]); act(curMap, opj, L[j]); } } for (int i = 0; i < K; ++i) { out(list[i], L[i]); } } int act(int[][] map, long op, int L) { int ret = 0; int sign = (int) (op / Math.abs(op)); op = Math.abs(op); int px = (int) op; int py = (int) (op >> 32); if (sign == 1) { for (int i = px; i <= px + L - 1; ++i) { for (int j = py; j <= py; ++j) { if (curMap[i - 1][j - 1] == 1) ++ret; else --ret; curMap[i - 1][j - 1] ^= 1; } } } else { for (int i = px; i <= px; ++i) { for (int j = py; j <= py + L - 1; ++j) { if (curMap[i - 1][j - 1] == 1) ++ret; else --ret; curMap[i - 1][j - 1] ^= 1; } } } return ret; } long rnd(int L) { while (true) { long px = (long) (Math.random() * N) + 1; long py = (long) (Math.random() * N) + 1; if (px + L <= N + 1) { return (px | (py << 32)); } else if (py + L <= N + 1) { return (-(px | py << 32)); } else { continue; } } } int getPt() { int ret = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (A[i][j] == 0) --ret; } } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { if (curMap[i][j] == 0) ++ret; } } return ret; } void out(long a, int L) { int sign = (int) (a / Math.abs(a)); a = Math.abs(a); int px = (int) a; int py = (int) (a >> 32); if (sign == 1) { System.out.println(px + " " + py + " " + (px + L - 1) + " " + py); } else { System.out.println(px + " " + py + " " + px + " " + (py + L - 1)); } } public static void main(String[] args) { new Main().run(); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }