結果
| 問題 | No.3410 Happiest Art |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-12-17 02:40:15 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 4,000 ms |
| コード長 | 1,950 bytes |
| 記録 | |
| コンパイル時間 | 3,443 ms |
| コンパイル使用メモリ | 282,376 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-12-17 02:40:22 |
| 合計ジャッジ時間 | 6,002 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 44 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using T = bitset<10000>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string str;
int N, U, H, W, v;
cin >> N >> U >> H >> W;
vector<int> F(N);
vector<T> tb(N);
for(int i = 0; i < N; i++){
cin >> F[i];
for(int y = 0; y < H; y++){
cin >> str;
for(int x = 0; x < W; x++){
if(str[x] == '#') tb[i][y * W + x] = 1;
}
}
}
int ans = -(N + 1);
T S;
vector<int> change(H * W);
for(int i = 0; i < U; i++){
int cnt = 0;
fill(change.begin(), change.end(), 0);
for(int j = 0; j < N; j++){
auto df = tb[i] ^ tb[j];
int cnt2 = df.count();
cnt += cnt2 <= F[j] ? (j < U ? 1 : -1) : 0;
for(int k = 0; k < H * W; k++){
int cnt3 = cnt2 + (df[k] ? -1 : 1);
change[k] += cnt3 <= F[j] ? (j < U ? 1 : -1) : 0;
}
}
if(cnt > ans){
ans = cnt;
S = tb[i];
}
for(int k = 0; k < H * W; k++){
tb[i].flip(k);
if(change[k] > ans){
ans = change[k];
S = tb[i];
}
tb[i].flip(k);
}
}
if(ans < 0){
int cur = 0, th = 1 << 20;
if(H * W < 20) th = 1 << H * W;
while(cur < th){
T S2(cur);
int cnt = 0;
for(int j = 0; j < N; j++){
cnt += (S2 ^ tb[j]).count() <= F[j] ? (j < U ? 1 : -1) : 0;
}
if(cnt > ans){
ans = cnt;
S = S2;
}
if(ans >= 0) break;
cur++;
}
}
cout << ans << '\n';
for(int y = 0; y < H; y++){
for(int x = 0; x < W; x++){
cout << (S[y * W + x] ? '#' : '.');
}
cout << '\n';
}
}