結果

問題 No.611 Day of the Mountain
ユーザー mamekin
提出日時 2018-01-14 11:55:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 168 ms / 2,017 ms
コード長 2,757 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 114,056 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 02:31:59
合計ジャッジ時間 2,293 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
const int MOD = 201712111;
const int INF = INT_MAX / 2;
int main()
{
int h, w;
cin >> h >> w;
vector<vector<int> > grid(h, vector<int>(w, -1));
for(int y=0; y<h; ++y){
for(int x=0; x<w; ++x){
char c;
cin >> c;
if(c != '?')
grid[y][x] = c - '0';
}
}
if(h < w){
swap(h, w);
vector<vector<int> > grid2(h, vector<int>(w));
for(int y=0; y<h; ++y){
for(int x=0; x<w; ++x){
grid2[y][x] = grid[x][y];
}
}
grid.swap(grid2);
}
vector<vector<bool> > isUnknown(h, vector<bool>(w, false));
for(int y=0; y<h; ++y){
for(int x=0; x<w; ++x){
if(grid[y][x] == -1){
grid[y][x] = 1;
isUnknown[y][x] = true;
}
}
}
vector<vector<int> > minCost(h, vector<int>(w, INF));
minCost[0][0] = grid[0][0];
for(int y=0; y<h; ++y){
for(int x=0; x<w; ++x){
if(y > 0)
minCost[y][x] = min(minCost[y][x], minCost[y-1][x] + grid[y][x]);
if(x > 0)
minCost[y][x] = min(minCost[y][x], minCost[y][x-1] + grid[y][x]);
}
}
vector<int> dp(1<<w, 0);
dp[1] = 1;
for(int y=0; y<h; ++y){
for(int x=0; x<w; ++x){
if(y == 0 && x == 0)
continue;
vector<int> nextDp(1<<w, 0);
for(int i=0; i<(1<<w); ++i){
bitset<32> bs(i);
bitset<32> bs2 = (bs << 1) & bitset<32>((1 << w) - 1);
if(isUnknown[y][x]){
nextDp[bs2.to_ulong()] += dp[i] * 8;
nextDp[bs2.to_ulong()] %= MOD;
}
if((y > 0 && bs[w-1] && minCost[y-1][x] + grid[y][x] == minCost[y][x]) ||
(x > 0 && bs[0] && minCost[y][x-1] + grid[y][x] == minCost[y][x])){
bs2[0] = true;
}
nextDp[bs2.to_ulong()] += dp[i];
nextDp[bs2.to_ulong()] %= MOD;
}
dp.swap(nextDp);
}
}
int ans = 0;
for(int i=1; i<(1<<w); i+=2){
ans += dp[i];
ans %= MOD;
}
cout << minCost[h-1][w-1] << endl << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0