結果
問題 | No.755 Zero-Sum Rectangle |
ユーザー |
![]() |
提出日時 | 2018-12-03 10:28:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 187 ms / 2,000 ms |
コード長 | 2,220 bytes |
コンパイル時間 | 969 ms |
コンパイル使用メモリ | 112,328 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 05:35:47 |
合計ジャッジ時間 | 2,759 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#include <algorithm>#include <chrono>#include <cstring>#include <iomanip>#include <istream>#include <map>#include <numeric>#include <ostream>#include <random>#include <set>#include <sstream>#include <string>#include <unordered_map>#include <unordered_set>#include <utility>#include <vector>using namespace std;typedef long long ll;class Solution {public:void solve(std::istream& in, std::ostream& out) {int n, m;in >> m >> n;ll mat[n][n];for (int ctr1 = 0; ctr1 < n; ++ctr1)for (int ctr2 = 0; ctr2 < n; ++ctr2)in >> mat[ctr1][ctr2];ll acc[n + 1][n + 1];memset(acc, 0, sizeof(acc));for (int ctr1 = 0; ctr1 < n; ++ctr1)for (int ctr2 = 0; ctr2 < n; ++ctr2)acc[ctr1 + 1][ctr2 + 1] = mat[ctr1][ctr2] + acc[ctr1 + 1][ctr2] +acc[ctr1][ctr2 + 1] - acc[ctr1][ctr2];ll dp[n + 1][n + 1];memset(dp, 0, sizeof(dp));for (int ctr1 = 0; ctr1 < n; ++ctr1)for (int ctr2 = 0; ctr2 < n; ++ctr2)for (int ctr3 = ctr1; ctr3 < n; ++ctr3)for (int ctr4 = ctr2; ctr4 < n; ++ctr4)if (acc[ctr3 + 1][ctr4 + 1] - acc[ctr3 + 1][ctr2] -acc[ctr1][ctr4 + 1] + acc[ctr1][ctr2] == 0) {dp[ctr3 + 1][ctr4 + 1] += 1;dp[ctr3 + 1][ctr2] -= 1;dp[ctr1][ctr4 + 1] -= 1;dp[ctr1][ctr2] += 1;}for (int ctr1 = 0; ctr1 <= n; ++ctr1)for (int ctr2 = 0; ctr2 <= n; ++ctr2) {if (ctr1 > 0)dp[ctr1][ctr2] += dp[ctr1 - 1][ctr2];if (ctr2 > 0)dp[ctr1][ctr2] += dp[ctr1][ctr2 - 1];if (ctr1 > 0 && ctr2 > 0)dp[ctr1][ctr2] -= dp[ctr1 - 1][ctr2 - 1];}int x, y;while (m--) {in >> x >> y;out << dp[x - 1][y - 1] << "\n";}}};void solve(std::istream& in, std::ostream& out){out << std::setprecision(12);Solution solution;solution.solve(in, out);}// Powered by caide (code generator, tester, and library code inliner)#include <fstream>#include <iostream>int main() {ios_base::sync_with_stdio(false);cin.tie(0);istream& in = cin;ostream& out = cout;solve(in, out);return 0;}