提出 #44961393
ソースコード 拡げる
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
template <class T>
std::ostream &operator<<(std::ostream &out, const std::vector<std::vector<T>> &r){
if(r.size() == 0){
out << "||";
return out;
}
for(const auto&v : r) out << v << endl;
out << endl;
return out;
}
template <class T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &r){
if(r.size() == 0){
out << "[]";
return out;
}
out << "[";
for(int i{}; i < (int)r.size() - 1; ++i) out << r[i] << ",";
out << r.back() << "]";
return out;
}
template <class T>
std::ostream &operator<<(std::ostream &out, const std::set<T> &r){
if(r.size() == 0){
out << "{}";
return out;
}
out << "{";
auto e = r.end(); --e;
for(auto it = r.begin(); it != e; ++it) out << *it << ",";
out << *e << "}";
return out;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &out, const std::map<T, U> &r){
if(r.size() == 0){
out << "{}";
return out;
}
out << "{";
auto e = r.end(); --e;
for(auto it = r.begin(); it != e; ++it) out << it -> first << ":" << it -> second << ",";
out << e -> first << ":" << e -> second << "}";
return out;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &out, const std::pair<T, U> &r){
out << "(" << r.first << "," << r.second << ")";
return out;
}
void solve(){
int h, w;
cin >> h >> w;
vector<string> a(h);
for(auto&i: a) cin >> i;
int sx = -1, sy = -1, gx = -1, gy = -1;
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
if(a[i][j] == 'S') sx = i, sy = j;
if(a[i][j] == 'G') gx = i, gy = j;
if(a[i][j] == '>')
{
for (int jj = j+1; jj < w; jj++)
{
if(a[i][jj] == '.' or a[i][jj] == 'x')
{
a[i][jj] = 'x';
continue;
}
break;
}
}
if(a[i][j] == 'v')
{
for (int ii = i+1; ii < h; ii++)
{
if(a[ii][j] == '.' or a[ii][j] == 'x')
{
a[ii][j] = 'x';
continue;
}
break;
}
}
if(a[i][j] == '<')
{
for (int jj = j-1; jj >= 0; jj--)
{
if(a[i][jj] == '.' or a[i][jj] == 'x')
{
a[i][jj] = 'x';
continue;
}
break;
}
}
if(a[i][j] == '^')
{
for (int ii = i-1; ii >= 0; ii--)
{
if(a[ii][j] == '.' or a[ii][j] == 'x')
{
a[ii][j] = 'x';
continue;
}
break;
}
}
}
}
constexpr int inf = 1e9;
vector<vector<int>> d(h, vector<int>(w, inf));
d[sx][sy] = 0;
queue<pair<int, int>> q;
q.emplace(sx, sy);
int dx[]= {1, 0, -1, 0}, dy[]= {0, 1, 0, -1};
auto ok = [&](int x, int y){
return 0 <= x and x < h and 0 <= y and y < w;
};
while(not q.empty())
{
auto[x, y] = q.front();
q.pop();
for (int i = 0; i < 4; i++)
{
int nx = x+dx[i], ny = y+dy[i];
if(not ok(nx, ny)) continue;
if(a[nx][ny] == 'G')
{
cout << d[x][y]+1 << endl;
return;
}
if(a[nx][ny] == '.')
{
if(d[nx][ny] == inf)
{
d[nx][ny] = d[x][y] + 1;
q.emplace(nx, ny);
}
}
}
}
cout << - 1 << endl;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
}
提出情報
コンパイルエラー
Main.cpp: In function ‘void solve()’:
Main.cpp:69:27: warning: variable ‘gx’ set but not used [-Wunused-but-set-variable]
69 | int sx = -1, sy = -1, gx = -1, gy = -1;
| ^~
Main.cpp:69:36: warning: variable ‘gy’ set but not used [-Wunused-but-set-variable]
69 | int sx = -1, sy = -1, gx = -1, gy = -1;
| ^~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
425 / 425 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_large_answer_00.txt, 02_large_answer_01.txt, 02_large_answer_02.txt, 02_large_answer_03.txt, 03_all_free_00.txt, 03_all_free_01.txt, 03_all_free_02.txt, 03_all_free_03.txt, 04_corner_00.txt, 04_corner_01.txt, 04_corner_02.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
1 ms |
3520 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3520 KiB |
| 01_random_00.txt |
AC |
10 ms |
15100 KiB |
| 01_random_01.txt |
AC |
44 ms |
23140 KiB |
| 01_random_02.txt |
AC |
16 ms |
23092 KiB |
| 01_random_03.txt |
AC |
15 ms |
23164 KiB |
| 01_random_04.txt |
AC |
7 ms |
10076 KiB |
| 01_random_05.txt |
AC |
27 ms |
23164 KiB |
| 01_random_06.txt |
AC |
15 ms |
23084 KiB |
| 01_random_07.txt |
AC |
54 ms |
23176 KiB |
| 01_random_08.txt |
AC |
13 ms |
12080 KiB |
| 01_random_09.txt |
AC |
15 ms |
23172 KiB |
| 01_random_10.txt |
AC |
18 ms |
23140 KiB |
| 01_random_11.txt |
AC |
33 ms |
23144 KiB |
| 01_random_12.txt |
AC |
7 ms |
11004 KiB |
| 01_random_13.txt |
AC |
25 ms |
23160 KiB |
| 01_random_14.txt |
AC |
52 ms |
23156 KiB |
| 02_large_answer_00.txt |
AC |
1 ms |
3764 KiB |
| 02_large_answer_01.txt |
AC |
3 ms |
4428 KiB |
| 02_large_answer_02.txt |
AC |
12 ms |
8040 KiB |
| 02_large_answer_03.txt |
AC |
45 ms |
23216 KiB |
| 03_all_free_00.txt |
AC |
71 ms |
23176 KiB |
| 03_all_free_01.txt |
AC |
71 ms |
23436 KiB |
| 03_all_free_02.txt |
AC |
32 ms |
23216 KiB |
| 03_all_free_03.txt |
AC |
52 ms |
23456 KiB |
| 04_corner_00.txt |
AC |
45 ms |
23072 KiB |
| 04_corner_01.txt |
AC |
29 ms |
23164 KiB |
| 04_corner_02.txt |
AC |
29 ms |
23108 KiB |