結果
| 問題 |
No.611 Day of the Mountain
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2017-12-11 19:25:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,431 bytes |
| コンパイル時間 | 1,389 ms |
| コンパイル使用メモリ | 160,808 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-30 11:39:46 |
| 合計ジャッジ時間 | 2,723 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
43 | scanf("%d%d",&h,&w);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:44:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
44 | REP(i,h)scanf("%s",mp[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
// mod
const ll MOD = 201712111ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;
int h,w;
char mp[353][353];
int dist[353][353];
bool pass[353][353];
int dp[2][1<<18];
int main(){
scanf("%d%d",&h,&w);
REP(i,h)scanf("%s",mp[i]);
if(h<w){
swap(h,w);
REP(i,353)REP(j,i)swap(mp[i][j], mp[j][i]);
}
assert(w <= 18);
// precalc
dist[0][0] = mp[0][0]=='?' ? 1 : mp[0][0]-'0';
REP(i,h)REP(j,w)if(i!=0 || j!=0){
dist[i][j] = 252521;
int c = mp[i][j]=='?' ? 1 : mp[i][j]-'0';
if(i>0)CHMIN(dist[i][j], dist[i-1][j]+c);
if(j>0)CHMIN(dist[i][j], dist[i][j-1]+c);
}
pass[h-1][w-1] = true;
FORR(i,0,h)FORR(j,0,w)if(i!=h-1 || j!=w-1){
if(i<h-1){
int ni = i+1, nj = j;
int c = mp[ni][nj]=='?' ? 1 : mp[ni][nj]-'0';
if(dist[ni][nj]==dist[i][j]+c && pass[ni][nj])pass[i][j] = true;
}
if(j<w-1){
int ni = i, nj = j+1;
int c = mp[ni][nj]=='?' ? 1 : mp[ni][nj]-'0';
if(dist[ni][nj]==dist[i][j]+c && pass[ni][nj])pass[i][j] = true;
}
}
// bit dp
REP(i,1<<w)dp[0][i] = 0;
dp[0][1] = 1;
REP(y,h)REP(x,w){
REP(i,1<<w)dp[1][i] = 0;
int del = ((1<<w)-1) ^ (1<<x);
int chk = 1<<x | (x>0 ? (1<<(x-1)) : 0);
REP(msk,1<<w){
int nbit = (msk & chk) > 0 && pass[y][x];
int nmsk = (msk & del) ^ (nbit << x);
dp[1][nmsk] = (dp[1][nmsk] + dp[0][msk]) % MOD;
}
if(mp[y][x]=='?'){
REP(msk,1<<w){
dp[1][msk&del] = (dp[1][msk&del] + dp[0][msk]*8 % MOD) % MOD;
}
}
REP(i,1<<w)dp[0][i] = dp[1][i];
}
int ans = 0;
REP(i,1<<w)if((i>>(w-1))&1){
ans = (ans + dp[0][i]) % MOD;
}
printf("%d %d\n",dist[h-1][w-1],ans);
return 0;
}
rickytheta