結果
問題 |
No.1225 I hate I hate Matrix Construction
|
ユーザー |
![]() |
提出日時 | 2020-09-11 22:57:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,924 bytes |
コンパイル時間 | 1,247 ms |
コンパイル使用メモリ | 97,000 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-27 18:46:51 |
合計ジャッジ時間 | 2,567 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 WA * 16 |
ソースコード
#include<iostream> #include<stdio.h> #include<stdlib.h> #include<algorithm> #include<vector> #include<string.h> #include<math.h> #include<map> #include<iomanip> #include<queue> using namespace std; long long gcd(long long a,long long b){ long long x=max(a,b),y=min(a,b); if(x%y==0)return y; else return gcd(y,x%y); } long long lcm(long long a,long long b){ return (a/gcd(a,b))*b; } int main(){ cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(1) << endl; int n; cin >> n; vector<int> s(n); vector<int> t(n); for(int i = 0; i < n; i++)cin >> s[i]; for(int i = 0; i < n; i++)cin >> t[i]; vector<vector<int>> ans(n,vector<int>(n,0)); //s for(int i = 0; i < n; i++){ if(s[i] == 0){ continue; }else if(s[i] == 2){ for(int j = 0; j < n; j++){ ans[i][j] = 1; } }else if(s[i] == 1){ continue; } } //t for(int i = 0; i < n; i++){ if(t[i] == 0){ for(int j = 0; j < n; j++){ ans[j][i] = 0; } }else if(s[i] == 2){ for(int j = 0; j < n;j++){ ans[i][j] = 1; } }else if(s[i] == 1){ continue; } } for(int i = 0; i < n; i++){ if(s[i] == 1){ bool ok = false; for(int j = 0; j < n; j++){ if(ans[i][j] == 1){ ok = true; break; } } if(!ok){ if(t[i] == 1){ ans[i][i] = 1; }else{ ans[i][0] = 1; } } } if(t[i] == 1){ bool ok = false; for(int j = 0; j < n; j++){ if(ans[j][i] == 1){ ok = true; break; } } if(!ok){ if(s[i] == 1){ ans[i][i] = 1; }else{ ans[0][i] = 1; } } } } //cnt int ans_cnt = 0; for(int i = 0; i < n; i++){ int cnt = 0; for(int j = 0; j < n; j++){ if(ans[i][j] == 1)cnt++; } if(cnt == n){ ans_cnt += n; continue; } if(cnt == 0){ continue; } if(cnt == 1){ ans_cnt += 1; continue; } ans_cnt += 1; } cout << ans_cnt << endl; return 0; }