結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> s, t;
  rep(i,N){
    int a;
    cin >> a;
    s.push_back(a);
  }
  rep(i,N){
    int b;
    cin >> b;
    t.push_back(b);
  }
  
  vector<vector<int>> field(N, vector<int>(N, -1));
  rep(i,N){
    if(s[i] == 0){
      rep(j,N) field[i][j] = 0;
    }
    if(s[i] == 2){
      rep(j,N) field[i][j] = 1;
    }
  }
  rep(j,N){
    if(t[j] == 0){
      rep(i,N) field[i][j] = 0;
    }
    if(t[j] == 2){
      rep(i,N) field[i][j] = 1;
    }
  }

  rep(i,N){
    if(s[i] == 1){
      bool check = false;
      rep(j,N) if(field[i][j] == 1) check = true;
      if(check){
        s[i] = -1;
        rep(j,N) if(field[i][j] == -1) field[i][j] = 0;
      }
    }
  }
  rep(j,N){
    if(t[j] == 1){
      bool check = false;
      rep(i,N) if(field[i][j] == 1) check = true;
      if(check){
        t[j] = -1;
        rep(i,N) if(field[i][j] == -1) field[i][j] = 0;
      }
    }
  }

  int ret = 0;
  rep(i,N) rep(j,N) if(field[i][j] == 1) ret++;
  int a = 0, b = 0;
  rep(i,N){
    if(s[i] == 1) a++;
    if(t[i] == 1) b++;
  }
  ret += max(a, b);

  cout << ret << endl;
  
  return 0;
}
0