diff --git a/LibreOJ/3500/3500.cpp b/LibreOJ/3500/3500.cpp new file mode 100644 index 00000000..ed16d658 --- /dev/null +++ b/LibreOJ/3500/3500.cpp @@ -0,0 +1,111 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int MAX = 1e6; + +void solve() { + int n, m; + + cin >> n >> m; + + std::vector> + a(n, std::vector(m, 0)), + b(n - 1, std::vector(m - 1, 0)); + std::vector>> + g(n + m, std::vector>()); + + for (auto &i : b) { + for (auto &x : i) { + cin >> x; + } + } + + for (int i = n - 2; i >= 0; i--) { + for (int j = m - 2; j >= 0; j--) { + a[i][j] = b[i][j] - a[i + 1][j] - a[i + 1][j + 1] - a[i][j + 1]; + } + } + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + if ((i + j) & 1) { + g[i].emplace_back(j + n, a[i][j]); + g[j + n].emplace_back(i, MAX - a[i][j]); + } else { + g[j + n].emplace_back(i, a[i][j]); + g[i].emplace_back(j + n, MAX - a[i][j]); + } + } + } + + std::vector dist(n + m); + + auto spfa = [&]() -> bool { + std::queue q; + std::vector vis(n + m, true); + std::vector cnt(n + m); + + for (int i = 0; i < n + m; i++) { + q.emplace(i); + } + + while (!q.empty()) { + int u = q.front(); + q.pop(); + + vis[u] = false; + + for (auto e : g[u]) { + int v = e.first, + w = e.second; + + if (dist[v] > dist[u] + w) { + dist[v] = dist[u] + w; + + if (!vis[v]) { + if (++cnt[v] > n + m) return false; + + vis[v] = true; + q.emplace(v); + } + } + } + } + + return true; + }; + + if (!spfa()) { + cout << "NO" << endl; + + return; + } + + cout << "YES" << endl; + + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + cout << a[i][j] + ((i + j) & 1 ? dist[i] - dist[j + n] : dist[j + n] - dist[i]) << ' '; + } + + cout << endl; + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + + cin >> t; + + while (t--) solve(); + + return 0; +} diff --git a/LibreOJ/3500/data/checker.cpp b/LibreOJ/3500/data/checker.cpp new file mode 100644 index 00000000..7fb7886b --- /dev/null +++ b/LibreOJ/3500/data/checker.cpp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:05069aa46ad6f00947c08017755fb772a6263080bc56c2139ce2e14688ba547a +size 1028 diff --git a/LibreOJ/3500/data/matrix1.ans b/LibreOJ/3500/data/matrix1.ans new file mode 100644 index 00000000..e9a72a0d --- /dev/null +++ b/LibreOJ/3500/data/matrix1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0ef5f4142e16d6cab561ff009f5d71af26695c026ba2692ddc7eff562200d7d3 +size 266 diff --git a/LibreOJ/3500/data/matrix1.in b/LibreOJ/3500/data/matrix1.in new file mode 100644 index 00000000..da19eb12 --- /dev/null +++ b/LibreOJ/3500/data/matrix1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0b26865689a7d18217d0fe4e5fafaaa7b8ad374dec5fd805133d592a8b9c4468 +size 175 diff --git a/LibreOJ/3500/data/matrix10.ans b/LibreOJ/3500/data/matrix10.ans new file mode 100644 index 00000000..ddcf3873 --- /dev/null +++ b/LibreOJ/3500/data/matrix10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aebbbf2716792ae584ed8d076738af414ea1778e594fa507e2077fe5ea0bab0b +size 4994 diff --git a/LibreOJ/3500/data/matrix10.in b/LibreOJ/3500/data/matrix10.in new file mode 100644 index 00000000..7119b15e --- /dev/null +++ b/LibreOJ/3500/data/matrix10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8f43746913f0b24cfa93a127016d7162d344a02a244aa1a56494683e566cfc4 +size 7934 diff --git a/LibreOJ/3500/data/matrix11.ans b/LibreOJ/3500/data/matrix11.ans new file mode 100644 index 00000000..5cad66d7 --- /dev/null +++ b/LibreOJ/3500/data/matrix11.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bea6db93755111476871833f23a8da857692c437d8beb160f7f9f3d7a59af9b0 +size 895535 diff --git a/LibreOJ/3500/data/matrix11.in b/LibreOJ/3500/data/matrix11.in new file mode 100644 index 00000000..4a0d12b0 --- /dev/null +++ b/LibreOJ/3500/data/matrix11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b4f99b2a526d60adc0d76888b0441f39ffbb3f5a48d3098b9ab38ae327b7c6c +size 1779133 diff --git a/LibreOJ/3500/data/matrix12.ans b/LibreOJ/3500/data/matrix12.ans new file mode 100644 index 00000000..0db5e562 --- /dev/null +++ b/LibreOJ/3500/data/matrix12.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:55c7481574bfac57684009b67ae8de7faa77f8976752bc2f5dedf41028873774 +size 880640 diff --git a/LibreOJ/3500/data/matrix12.in b/LibreOJ/3500/data/matrix12.in new file mode 100644 index 00000000..40fa920d --- /dev/null +++ b/LibreOJ/3500/data/matrix12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ccfcfdced7bac7b260e4b530d81730cd8dc35f5fe4aff868743b5e6d8546a16e +size 1749443 diff --git a/LibreOJ/3500/data/matrix13.ans b/LibreOJ/3500/data/matrix13.ans new file mode 100644 index 00000000..799d04ae --- /dev/null +++ b/LibreOJ/3500/data/matrix13.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bebe82e4187c45b083495f7d9295fa9a42c28764f71d92cdac73f50b350413b3 +size 889550 diff --git a/LibreOJ/3500/data/matrix13.in b/LibreOJ/3500/data/matrix13.in new file mode 100644 index 00000000..efa5cea5 --- /dev/null +++ b/LibreOJ/3500/data/matrix13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd5810800f60543c833d9984bfcb8fd04fca738f5dbfa56b1eb73a80524eff23 +size 1767203 diff --git a/LibreOJ/3500/data/matrix14.ans b/LibreOJ/3500/data/matrix14.ans new file mode 100644 index 00000000..abda03b9 --- /dev/null +++ b/LibreOJ/3500/data/matrix14.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:89b78fdd7d9158a2e777fd838d576471610972cf90078e5a95d1694cd69d8d58 +size 892545 diff --git a/LibreOJ/3500/data/matrix14.in b/LibreOJ/3500/data/matrix14.in new file mode 100644 index 00000000..cd148d63 --- /dev/null +++ b/LibreOJ/3500/data/matrix14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c123e24f5b417786fa2360469e61c3f7400c57eafc2b021afbaa5f66a16bafb6 +size 1773173 diff --git a/LibreOJ/3500/data/matrix15.ans b/LibreOJ/3500/data/matrix15.ans new file mode 100644 index 00000000..71a22f3f --- /dev/null +++ b/LibreOJ/3500/data/matrix15.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:715a3685579af693919611205a0ec731d505be612a2d6de0d7f62cb84564d94c +size 883605 diff --git a/LibreOJ/3500/data/matrix15.in b/LibreOJ/3500/data/matrix15.in new file mode 100644 index 00000000..755264c1 --- /dev/null +++ b/LibreOJ/3500/data/matrix15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f26eecc79d19f68c805f214c6e0d5a2777431ed1c56217505a67931bc22ddcc3 +size 1755353 diff --git a/LibreOJ/3500/data/matrix16.ans b/LibreOJ/3500/data/matrix16.ans new file mode 100644 index 00000000..a3e469b2 --- /dev/null +++ b/LibreOJ/3500/data/matrix16.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40e965b02afab8b4d128fe77cffa232c046c86b94e508b53c26a00555796693c +size 3036430 diff --git a/LibreOJ/3500/data/matrix16.in b/LibreOJ/3500/data/matrix16.in new file mode 100644 index 00000000..78f063da --- /dev/null +++ b/LibreOJ/3500/data/matrix16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7b39eb5ef47d3501c405f9785913499ce02347d41ed12d609a6e75368f5ea42 +size 6871901 diff --git a/LibreOJ/3500/data/matrix17.ans b/LibreOJ/3500/data/matrix17.ans new file mode 100644 index 00000000..44b8e2af --- /dev/null +++ b/LibreOJ/3500/data/matrix17.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91a43c47c2b468c5197cc1c5a5bf96dbefbc721d4562ff6101f705f29804d727 +size 3047150 diff --git a/LibreOJ/3500/data/matrix17.in b/LibreOJ/3500/data/matrix17.in new file mode 100644 index 00000000..a47316c5 --- /dev/null +++ b/LibreOJ/3500/data/matrix17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec1246158861960f3144b7a4e4776d06707a33b834ec0cc4b8cb6a17de6e6d9f +size 6895598 diff --git a/LibreOJ/3500/data/matrix18.ans b/LibreOJ/3500/data/matrix18.ans new file mode 100644 index 00000000..33677e14 --- /dev/null +++ b/LibreOJ/3500/data/matrix18.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fec7a565a906999413fbc59c134794372c65b3668878babc52ef38498b7018ee +size 3016291 diff --git a/LibreOJ/3500/data/matrix18.in b/LibreOJ/3500/data/matrix18.in new file mode 100644 index 00000000..e3738b46 --- /dev/null +++ b/LibreOJ/3500/data/matrix18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed359d45553815da49701f8aedcb976103a3845d867e7a14a6a25ecdeec77aa4 +size 6825989 diff --git a/LibreOJ/3500/data/matrix19.ans b/LibreOJ/3500/data/matrix19.ans new file mode 100644 index 00000000..e9e88314 --- /dev/null +++ b/LibreOJ/3500/data/matrix19.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f28a16cad28ec53fe3be945ac236d6ceb4d587aeaafab331427718cb6e9ef38 +size 3037061 diff --git a/LibreOJ/3500/data/matrix19.in b/LibreOJ/3500/data/matrix19.in new file mode 100644 index 00000000..37d5ed5d --- /dev/null +++ b/LibreOJ/3500/data/matrix19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a0f5dcec367ca9485ab82a2946726cff00fd178cf0ba28e0b864a61615e5ae8 +size 6872629 diff --git a/LibreOJ/3500/data/matrix2.ans b/LibreOJ/3500/data/matrix2.ans new file mode 100644 index 00000000..b6ebae08 --- /dev/null +++ b/LibreOJ/3500/data/matrix2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7047aad15806b74719bc7bdfd37744067ef30e19755e64b37dda6b90916008d +size 263 diff --git a/LibreOJ/3500/data/matrix2.in b/LibreOJ/3500/data/matrix2.in new file mode 100644 index 00000000..bf0aff41 --- /dev/null +++ b/LibreOJ/3500/data/matrix2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7339ad1ca34e53257b3d896b7d0db398ea6c260a54dcd2c6208853374f41e88 +size 177 diff --git a/LibreOJ/3500/data/matrix20.ans b/LibreOJ/3500/data/matrix20.ans new file mode 100644 index 00000000..05375b76 --- /dev/null +++ b/LibreOJ/3500/data/matrix20.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7517c89f6db3a7c73f773fb43bc671dcbbc4c6a06871eca9fcb3bbe52c67c3ee +size 3016551 diff --git a/LibreOJ/3500/data/matrix20.in b/LibreOJ/3500/data/matrix20.in new file mode 100644 index 00000000..e4587a9b --- /dev/null +++ b/LibreOJ/3500/data/matrix20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8dfcd7668ab1d903b1bd451199f467be112424545a2ba38f72dc4fde4980c5ba +size 6825766 diff --git a/LibreOJ/3500/data/matrix3.ans b/LibreOJ/3500/data/matrix3.ans new file mode 100644 index 00000000..fe6c23a2 --- /dev/null +++ b/LibreOJ/3500/data/matrix3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:591aab34e31949a481007451e762354a084501060384b23ff8ce022fcf846ef2 +size 266 diff --git a/LibreOJ/3500/data/matrix3.in b/LibreOJ/3500/data/matrix3.in new file mode 100644 index 00000000..d79e9d72 --- /dev/null +++ b/LibreOJ/3500/data/matrix3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1025d049df052ebc4f642eb7b21c641a7fd42bcff1b14db5eef6a505ceb6183b +size 180 diff --git a/LibreOJ/3500/data/matrix4.ans b/LibreOJ/3500/data/matrix4.ans new file mode 100644 index 00000000..e8b47820 --- /dev/null +++ b/LibreOJ/3500/data/matrix4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:550009b13f80f9258e6aebacc5846f829ed8e7398ab7617a9b3256359390f2ab +size 265 diff --git a/LibreOJ/3500/data/matrix4.in b/LibreOJ/3500/data/matrix4.in new file mode 100644 index 00000000..74cdac70 --- /dev/null +++ b/LibreOJ/3500/data/matrix4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7d27862aa4d9414b34e0f65893e9ecca590af5339644c4d74a3cd06440f5e95 +size 175 diff --git a/LibreOJ/3500/data/matrix5.ans b/LibreOJ/3500/data/matrix5.ans new file mode 100644 index 00000000..783d67f9 --- /dev/null +++ b/LibreOJ/3500/data/matrix5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0f5bed21fc87f17cc7e6cb8764dfd095b9ce61ae3dfa642f0b95404e11f9e7c +size 434 diff --git a/LibreOJ/3500/data/matrix5.in b/LibreOJ/3500/data/matrix5.in new file mode 100644 index 00000000..c9d936b1 --- /dev/null +++ b/LibreOJ/3500/data/matrix5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9aa4ff9fc6d604d5a2a2adb125180ecc4a55a0f2351c3416c4dce44decb7c1c +size 587 diff --git a/LibreOJ/3500/data/matrix6.ans b/LibreOJ/3500/data/matrix6.ans new file mode 100644 index 00000000..55fe3024 --- /dev/null +++ b/LibreOJ/3500/data/matrix6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc7a5125eaa2928355acb2168bef68daba013f507ea0a6f54f05616d54f60cf4 +size 501 diff --git a/LibreOJ/3500/data/matrix6.in b/LibreOJ/3500/data/matrix6.in new file mode 100644 index 00000000..4c810378 --- /dev/null +++ b/LibreOJ/3500/data/matrix6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85e7d8766bc6debb5973a7bdd0bc900f9731bcadc17dfab25b6daaadc930add1 +size 590 diff --git a/LibreOJ/3500/data/matrix7.ans b/LibreOJ/3500/data/matrix7.ans new file mode 100644 index 00000000..0aba033b --- /dev/null +++ b/LibreOJ/3500/data/matrix7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e7ed0012b9c94bf610cca977f21935781e84e8819172feb02325495f4e7c59e +size 498 diff --git a/LibreOJ/3500/data/matrix7.in b/LibreOJ/3500/data/matrix7.in new file mode 100644 index 00000000..8c365cf4 --- /dev/null +++ b/LibreOJ/3500/data/matrix7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:df383a0a4fe71729ebaea19d36100fe8ed80af095702272c58425ef320bc7780 +size 593 diff --git a/LibreOJ/3500/data/matrix8.ans b/LibreOJ/3500/data/matrix8.ans new file mode 100644 index 00000000..bfd7ec54 --- /dev/null +++ b/LibreOJ/3500/data/matrix8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5285c2761b0567fe4261d2c6320591ca9d7a2f733722ca7fe40c3d7f86724a4c +size 5164 diff --git a/LibreOJ/3500/data/matrix8.in b/LibreOJ/3500/data/matrix8.in new file mode 100644 index 00000000..9771d4fe --- /dev/null +++ b/LibreOJ/3500/data/matrix8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7348a081532c71880e7096bfc0d406e6a2fccd5ba96bd6485c67ad10142ee637 +size 7935 diff --git a/LibreOJ/3500/data/matrix9.ans b/LibreOJ/3500/data/matrix9.ans new file mode 100644 index 00000000..c5b98357 --- /dev/null +++ b/LibreOJ/3500/data/matrix9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d63a7669e75ed55ba35903b43598b21c39e4c2d469c00c3290619cbdd632d23 +size 5118 diff --git a/LibreOJ/3500/data/matrix9.in b/LibreOJ/3500/data/matrix9.in new file mode 100644 index 00000000..ca2d958c --- /dev/null +++ b/LibreOJ/3500/data/matrix9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2686029bd8b16acda595e2f28c488db9107c5372f54281cdcb539d6186fd36b4 +size 7937