結果
| 問題 |
No.1225 I hate I hate Matrix Construction
|
| コンテスト | |
| ユーザー |
goto_isyuku
|
| 提出日時 | 2020-09-11 21:51:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,835 bytes |
| コンパイル時間 | 2,219 ms |
| コンパイル使用メモリ | 171,592 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-27 11:26:36 |
| 合計ジャッジ時間 | 3,479 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
#define rep(X, N) for (ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(), (V).end()
#define endl "\n"
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
int main(){
int n;
cin >> n;
vector<int> s(n), t(n);
rep(i, n) cin >> s[i];
rep(i, n) cin >> t[i];
vector<vector<int>> v(n, vector<int>(n, -1));
vector<int> row(n), col(n);
int ans = 0;
int c[3][3] = {{0, 0, 2}, {0, -1, 1}, {2, 1, 1}};
rep(i, n){
rep(j, n){
int tmp = c[s[i]][t[j]];
if(tmp == 0){
}else if(tmp == 1){
ans++;
v[i][j] = 1;
row[i]++;
col[j]++;
}else if(tmp == -1){
}else{
assert(false);
}
}
}
// Si = 1 かつ Tj = 1 かつ row[i] = 0 かつ col[j] = 0のぶぶんをうめる
rep(i, n){
rep(j, n){
if(s[i] == 1 && t[j] == 1 && row[i] == 0 && col[j] == 0){
v[i][j] = 1;
ans++;
row[i]++;
col[j]++;
}
}
}
// 残りの部分を埋める
rep(i, n){
rep(j, n){
if(v[i][j] == -1){
if(s[i] == 1 && row[i] == 0){
v[i][j] = 1;
ans++;
row[i]++;
col[j]++;
}else if(t[j] == 1 && col[j] == 0){
v[i][j] = 1;
ans++;
row[i]++;
col[j]++;
}
}
}
}
cout << ans << endl;
return 0;
}
goto_isyuku