提出 #24517035
ソースコード 拡げる
// {{{
#include <bits/stdc++.h>
using namespace std;
using LL = unsigned long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#define debug(x...)
#define debug_arr(x...)
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// }}}
inline void add(LL& a, LL b) { a = a + b; }
const int N = 10;
char s[N][N];
int vis[N][N];
int n, k;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
inline bool in(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; }
// vector<pii> pos;
// const LL p1 = 131, p2 = 997, p3 = 171;
set<vector<pii>> st;
set<vector<pii>> inq;
queue<pair<int, vector<pii>>> q;
void bfs()
{
while (!q.empty())
{
auto [step, vec] = q.front();
q.pop();
inq.erase(vec);
if (step == k)
{
st.insert(vec);
continue;
}
set<pii> tmp(all(vec));
for (auto [x, y] : vec)
{
for (int d = 0; d < 4; d++)
{
int xx = x + dx[d];
int yy = y + dy[d];
if (in(xx, yy) && tmp.find({xx, yy}) == tmp.end() && s[xx][yy] == '.')
{
vector<pii> new_vec = vec;
new_vec.push_back({xx, yy});
sort(all(new_vec));
if (inq.find(new_vec) == inq.end())
{
inq.insert(new_vec);
q.push({step + 1, new_vec});
}
}
}
}
}
}
int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
while (~scanf("%d%d", &n, &k))
{
for (int i = 0; i < n; ++i) scanf("%s", s[i]);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (s[i][j] == '.')
{
vector<pii> vec;
vec.push_back({i, j});
inq.insert(vec);
q.push({1, vec});
}
}
}
bfs();
int ans = st.size();
cout << ans << endl;
}
return 0;
}
提出情報
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:89:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
89 | for (int i = 0; i < n; ++i) scanf("%s", s[i]);
| ~~~~~^~~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
500 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
example0.txt, example1.txt, example2.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, example0.txt, example1.txt, example2.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 000.txt |
AC |
8 ms |
3688 KiB |
| 001.txt |
AC |
2 ms |
3680 KiB |
| 002.txt |
AC |
2 ms |
3624 KiB |
| 003.txt |
AC |
2 ms |
3688 KiB |
| 004.txt |
AC |
2 ms |
3532 KiB |
| 005.txt |
AC |
2 ms |
3652 KiB |
| 006.txt |
AC |
2 ms |
3572 KiB |
| 007.txt |
AC |
2 ms |
3716 KiB |
| 008.txt |
AC |
2 ms |
3668 KiB |
| 009.txt |
AC |
1 ms |
3628 KiB |
| 010.txt |
AC |
2 ms |
3664 KiB |
| 011.txt |
AC |
3 ms |
3612 KiB |
| 012.txt |
AC |
130 ms |
11108 KiB |
| 013.txt |
AC |
116 ms |
10536 KiB |
| 014.txt |
AC |
8 ms |
3856 KiB |
| 015.txt |
AC |
12 ms |
3896 KiB |
| 016.txt |
AC |
4 ms |
3648 KiB |
| 017.txt |
AC |
2 ms |
3600 KiB |
| 018.txt |
AC |
158 ms |
13268 KiB |
| 019.txt |
AC |
229 ms |
18036 KiB |
| 020.txt |
AC |
236 ms |
18616 KiB |
| 021.txt |
AC |
189 ms |
15688 KiB |
| 022.txt |
AC |
2 ms |
3684 KiB |
| 023.txt |
AC |
2 ms |
3680 KiB |
| 024.txt |
AC |
2 ms |
3656 KiB |
| 025.txt |
AC |
2 ms |
3540 KiB |
| 026.txt |
AC |
14 ms |
3988 KiB |
| 027.txt |
AC |
2 ms |
3628 KiB |
| 028.txt |
AC |
146 ms |
12360 KiB |
| example0.txt |
AC |
2 ms |
3676 KiB |
| example1.txt |
AC |
2 ms |
3560 KiB |
| example2.txt |
AC |
260 ms |
20044 KiB |