結果
| 問題 | No.3813 Ashwreath |
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2026-11-21 00:01:28 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 53 ms / 1,000 ms |
| + 43µs | |
| コード長 | 4,595 bytes |
| 記録 | |
| コンパイル時間 | 1,956 ms |
| コンパイル使用メモリ | 233,836 KB |
| 実行使用メモリ | 20,608 KB |
| 最終ジャッジ日時 | 2026-11-21 00:01:38 |
| 合計ジャッジ時間 | 3,735 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;
map<int,int> MA[13][13];
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int H,W;cin>>H>>W;
vst S(H);
for(int i=0;i<H;i++){
cin>>S[i];
}
vvi can(H,vi(W,-1));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(S[i][j]=='.'){
int cn=0;
for(int dh=-1;dh<=1;dh++){
for(int dw=-1;dw<=1;dw++){
int h=i+dh,w=j+dw;
if(dh==0&&dw==0) continue;
if(h<0||h>=H||w<0||w>=W) continue;
if(S[h][w]=='#') cn++;
}
}
if(cn>=2) can[i][j]=1;
else can[i][j]=0;
}
//cout<<can[i][j]<<" ";
}
//cout<<endl;
}
MA[0][0][0]=100;
for(int h=0;h<H;h++){
for(int w=0;w<W;w++){
for(auto [T,sc]:MA[h][w]){
if(can[h][w]==-1||can[h][w]==1){
int nsc=sc,nT=T;
if(h&&w&&can[h-1][w-1]==1&&(!(nT&(1<<(W+w-1))))){
int cn=0;
for(int dh=h-2;dh<=h;dh++){
for(int dw=w-2;dw<=w;dw++){
if(dh<0||dw<0) continue;
if(nT&(1<<((dh-(h-2))*W+dw))) cn++;
}
}
if(cn>=2) nsc++;
}
if(w>=2){
if(nT&(1<<(w-2))){
nT^=(1<<(w-2));
}
}
chmax(MA[h][w+1][nT],nsc);
}
if(can[h][w]==0||can[h][w]==1){
int nsc=sc,nT=T;
nT|=(1<<(2*W+w));
if(h&&w&&can[h-1][w-1]==1&&(!(nT&(1<<(W+w-1))))){
int cn=0;
for(int dh=h-2;dh<=h;dh++){
for(int dw=w-2;dw<=w;dw++){
if(dh<0||dw<0) continue;
if(nT&(1<<((dh-(h-2))*W+dw))) cn++;
}
}
if(cn>=2) nsc++;
}
if(w>=2){
if(nT&(1<<(w-2))){
nT^=(1<<(w-2));
}
}
chmax(MA[h][w+1][nT],nsc);
}
}
}
for(auto [T,sc]:MA[h][W]){
int nsc=sc,nT=T;
//cout<<T<<" "<<nsc<<endl;
if(h&&can[h-1][W-1]==1&&(!(nT&(1<<(W+W-1))))){
int cn=0;
for(int dh=h-2;dh<=h;dh++){
for(int dw=W-2;dw<=W-1;dw++){
if(dh<0||dw<0) continue;
if(nT&(1<<((dh-(h-2))*W+dw))) cn++;
}
}
if(cn>=2) nsc++;
}
chmax(MA[h+1][0][nT>>W],nsc);
}
}
int res=0;
for(auto [T,sc]:MA[H][0]){
int nsc=sc-100,nT=T;
for(int w=0;w<W;w++){
if(can[H-1][w]==1&&(!(nT&(1<<(W+w))))){
int cn=0;
for(int dh=H-2;dh<=H-1;dh++){
for(int dw=w-1;dw<=w+1;dw++){
if(dh<0||dw<0||dw>=W) continue;
if(nT&(1<<((dh-(H-2))*W+dw))) cn++;
}
}
if(cn>=2) nsc++;
}
}
chmax(res,nsc);
}
cout<<res<<"\n";
}
Rubikun