結果
| 問題 | No.1225 I hate I hate Matrix Construction | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-09-11 21:30:16 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 43 ms / 2,000 ms | 
| コード長 | 1,232 bytes | 
| コンパイル時間 | 755 ms | 
| コンパイル使用メモリ | 76,996 KB | 
| 最終ジャッジ日時 | 2025-01-14 10:03:01 | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 35 | 
ソースコード
#include <iostream>
#include <numeric>
#include <vector>
template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
void solve() {
    int n;
    std::cin >> n;
    auto grid = vec(n, vec(n, 0));
    std::vector<int> xs(n);
    for (int i = 0; i < n; ++i) {
        auto& x = xs[i];
        std::cin >> x;
        if (x == 2) {
            for (int j = 0; j < n; ++j) grid[i][j] = 1;
        }
    }
    std::vector<int> ys(n);
    for (int j = 0; j < n; ++j) {
        auto& y = ys[j];
        std::cin >> y;
        if (y == 2) {
            for (int i = 0; i < n; ++i) grid[i][j] = 1;
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (grid[i][j] == 1) {
                xs[i] = 0;
                ys[j] = 0;
            }
        }
    }
    int ans = std::max(std::accumulate(xs.begin(), xs.end(), 0),
                       std::accumulate(ys.begin(), ys.end(), 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ans += grid[i][j];
        }
    }
    std::cout << ans << "\n";
}
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
    return 0;
}
            
            
            
        