結果
| 問題 | No.611 Day of the Mountain |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-11 01:20:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,901 bytes |
| コンパイル時間 | 1,336 ms |
| コンパイル使用メモリ | 160,396 KB |
| 実行使用メモリ | 13,772 KB |
| 最終ジャッジ日時 | 2024-11-30 11:31:36 |
| 合計ジャッジ時間 | 4,559 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | AC * 2 RE * 7 |
コンパイルメッセージ
main.cpp: In function ‘ll upd(ll&, ll)’:
main.cpp:19:1: warning: no return statement in function returning non-void [-Wreturn-type]
19 | }
| ^
main.cpp: In function ‘int main()’:
main.cpp:42:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=]
42 | printf("%d\n", d[n][m]);
| ~^ ~~~~~~~
| | |
| int ll {aka long long int}
| %lld
main.cpp:22:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:24:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%s", s + 1);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 201712111;
const int MAXN = 2000 + 10;
int n, m;
int a[MAXN][MAXN];
ll d[MAXN][MAXN];
const ll INF = 1ll << 60;
char s[MAXN];
ll f[20][131072];
ll upd(ll &x, ll y){
x = (x + y) % MM;
}
int main(){
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++){
scanf("%s", s + 1);
for (int j = 1; j <= m; j++)
a[i][j] = ((s[j] == '?') ? 0 : (s[j] - '0'));
}
if (m >= 18){
for (int i = 1; i <= m; i++)
for (int j = i + 1; j <= m; j++)
swap(a[i][j], a[j][i]);
swap(n, m);
}
for (int i = 0; i <= n; i++)
for (int j = 0; j <= m; j++)
d[i][j] = INF;
d[1][1] = (a[1][1] == 0) + a[1][1];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (i != 1 || j != 1)
d[i][j] = min(d[i-1][j], d[i][j-1]) + a[i][j] + (a[i][j] == 0);
printf("%d\n", d[n][m]);
if (m == 1){
puts("1");
return 0;
}
int o = 1 << m;
for (int i = 0; i < o; i++)
f[1][i] = 0;
f[1][1] = 1;
int oo = o - 1;
for (int cnt = 2; cnt <= n * m; cnt++){
int x = (cnt - 1) / m + 1;
int y = (cnt - 1) % m + 1;
int py = (y == 1 ? m : y - 1);
for (int i = 0; i < o; i++)
f[y][i] = 0;
if (a[x][y] == 0){
for (int i = 0; i < o; i++) if(f[py][i]){
if ((d[x-1][y]+1==d[x][y] && ((i >> (y - 1)) & 1)) || (d[x][y-1]+1==d[x][y] && ((i >> (y - 2)) & 1)))
upd(f[y][i|(1<<(y-1))], f[py][i]), upd(f[y][i&(oo^(1<<(y-1)))], f[py][i]*8);
else
upd(f[y][i&(oo^(1<<(y-1)))], f[py][i]*9);
}
}
else{
for (int i = 0; i < o; i++) if(f[py][i]){
if ((d[x-1][y]+a[x][y]==d[x][y] && ((i >> (y - 1)) & 1)) || (d[x][y-1]+a[x][y]==d[x][y] && ((i >> (y - 2)) & 1)))
upd(f[y][i|(1<<(y-1))], f[py][i]);
else
upd(f[y][i&(oo^(1<<(y-1)))], f[py][i]);
}
}
}
ll ans = 0;
for (int i = 0; i < o; i++)
if ((i >> (m - 1)))
upd(ans, f[m][i]);
printf("%lld\n", ans);
return 0;
}