結果

問題 No.1225 I hate I hate Matrix Construction
ユーザー nawawan
提出日時 2020-09-11 22:16:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,156 bytes
コンパイル時間 1,323 ms
コンパイル使用メモリ 76,988 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 15:03:00
合計ジャッジ時間 2,403 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> S(N), T(N);
    for(int i = 0; i < N; i++) cin >> S[i];
    for(int i = 0; i < N; i++) cin >> T[i];
    int ans = 0;
    vector<bool> s(N, false), t(N, false);
    vector<vector<int>> mat(N, vector<int> (N, -1));
    for(int i = 0; i < N; i++){
        if(S[i] == 2){
            for(int j = 0; j < N; j++){
                if(T[j] == 1) {
                    t[j] = true;
                }
                if(mat[i][j] == -1){
                    ans++;
                    mat[i][j] = 1;
                }
            }
        }
        if(T[i] == 2){
            for(int j = 0; j < N; j++){
                if(S[j] == 1) {
                    s[j] = true;
                }
                if(mat[j][i] == -1){
                    ans++;
                    mat[j][i] = 1;
                }
            }
        }
    }
    int cnts = 0, cntt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 1 && !s[i]) cnts++;
        if(T[i] == 1 && !t[i]) cntt++;
    }
    ans += max(cntt, cnts);
    cout << ans << endl;
}
0