結果
問題 | No.1225 I hate I hate Matrix Construction |
ユーザー |
![]() |
提出日時 | 2020-09-11 21:51:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 2,333 bytes |
コンパイル時間 | 1,964 ms |
コンパイル使用メモリ | 198,164 KB |
最終ジャッジ日時 | 2025-01-14 10:21:29 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 35 |
ソースコード
#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; }