結果

問題 No.1225 I hate I hate Matrix Construction
ユーザー poohbearpoohbear
提出日時 2020-09-11 21:51:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,333 bytes
コンパイル時間 2,036 ms
コンパイル使用メモリ 203,580 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-27 13:59:39
合計ジャッジ時間 3,402 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 3 ms
4,504 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

int now[510][510];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //input
    ll n;
    cin >> n;
    vector<int>s(n),t(n);
    rep(i,n)cin>>s[i];
    rep(i,n)cin>>t[i];

    rep(i,n)rep(j,n)now[i][j]=-1;

    vector<bool>tate(n,false),yoko(n,false);//確定したか
    rep(i,n){
        if(s[i]==0){
            tate[i]=true;
            rep(j,n){
                now[i][j]=0;
            }
        }
        if(s[i]==2){
            tate[i]=true;
            rep(j,n){
                now[i][j]=1;
            }
        }
        if(t[i]==0){
            yoko[i]=true;
            rep(j,n){
                now[j][i]=0;
            }
        }
        if(t[i]==2){
            yoko[i]=true;
            rep(j,n){
                now[j][i]=1;
            }
        }
    }

    rep(i,n){
        if(s[i]==1){
            bool flag = false;
            rep(j,n){
                if(now[i][j]==1){
                    flag=true;
                }
            }
            if(flag){
                tate[i]=true;
                rep(j,n){
                    if(now[i][j]==-1){
                        now[i][j]=0;
                    }
                }
            }
        }
        if(t[i]==1){
            bool flag = false;
            rep(j,n){
                if(now[j][i]==1){
                    flag=true;
                }
            }
            if(flag){
                yoko[i]=true;
                rep(j,n){
                    if(now[j][i]==-1){
                        now[j][i]=0;
                    }
                }
            }
        }
    }

    ll cnt_tate = 0;
    ll cnt_yoko = 0;
    rep(i,n){
        if(!tate[i]){
            cnt_tate++;
        }
        if(!yoko[i]){
            cnt_yoko++;
        }
    }
    ll cnt = 0;
    rep(i,n)rep(j,n)if(now[i][j]==1)cnt++;
    cout << cnt + max(cnt_tate,cnt_yoko) << endl;

    return 0;
}
0