Submission #1200627
Source Code Expand
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#include<unordered_map>
#include<set>
#include<string.h>
#define P pair<int,int>
using namespace std;
struct A {
int x, y, used;
};
int a[500][500][2];
int dx[4] = { -1,0,0,1 }, dy[4] = { 0,-1,1,0 };
string b[500];
signed main() {
memset(a, -1, sizeof(a));
P s, g;
int c, d; scanf("%d%d", &c, &d);
for (int e = 0; e < c; e++) {
cin >> b[e];
for (int f = 0; f < d; f++) {
if (b[e][f] == 'S') {
s = P(e, f);
}
else if (b[e][f] == 'G') {
g = P(e, f);
}
}
}
queue<A>Q;
a[s.first][s.second][0] = 0;
Q.push({ s.first,s.second,0 });
while (Q.size()) {
A i = Q.front(); Q.pop();
for (int j = 0; j < 4; j++) {
int ex = i.x + dx[j], ey = i.y + dy[j];
if (b[ex][ey] == '#')continue;
else if (b[ex][ey] == 'C') {
if (a[ex][ey][1] == -1) {
a[ex][ey][1] = a[i.x][i.y][i.used] + 1;
Q.push({ ex,ey,1 });
}
}
else {
if (a[ex][ey][i.used] == -1) {
a[ex][ey][i.used] = a[i.x][i.y][i.used] + 1;
Q.push({ ex,ey,i.used });
}
}
}
}
printf("%d\n", a[g.first][g.second][1]);
}
Submission Info
Submission Time
2017-04-03 15:56:36+0900
Task
C - 自宅からの脱出
User
naoki2016
Language
C++14 (GCC 5.4.1)
Score
100
Code Size
1268 Byte
Status
AC
Exec Time
25 ms
Memory
2432 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:25:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
int c, d; scanf("%d%d", &c, &d);
^
Judge Result
Set Name
All
Score / Max Score
100 / 100
Status
Set Name
Test Cases
All
input_0.txt, input_1.txt, input_10.txt, input_11.txt, input_12.txt, input_13.txt, input_14.txt, input_15.txt, input_16.txt, input_17.txt, input_18.txt, input_19.txt, input_2.txt, input_20.txt, input_21.txt, input_22.txt, input_23.txt, input_3.txt, input_4.txt, input_5.txt, input_6.txt, input_7.txt, input_8.txt, input_9.txt
Case Name
Status
Exec Time
Memory
input_0.txt
AC
2 ms
2176 KB
input_1.txt
AC
2 ms
2176 KB
input_10.txt
AC
2 ms
2176 KB
input_11.txt
AC
2 ms
2176 KB
input_12.txt
AC
2 ms
2176 KB
input_13.txt
AC
2 ms
2176 KB
input_14.txt
AC
16 ms
2432 KB
input_15.txt
AC
25 ms
2432 KB
input_16.txt
AC
9 ms
2432 KB
input_17.txt
AC
25 ms
2432 KB
input_18.txt
AC
3 ms
2176 KB
input_19.txt
AC
3 ms
2176 KB
input_2.txt
AC
2 ms
2176 KB
input_20.txt
AC
3 ms
2176 KB
input_21.txt
AC
22 ms
2432 KB
input_22.txt
AC
11 ms
2432 KB
input_23.txt
AC
11 ms
2432 KB
input_3.txt
AC
2 ms
2176 KB
input_4.txt
AC
2 ms
2176 KB
input_5.txt
AC
2 ms
2176 KB
input_6.txt
AC
2 ms
2176 KB
input_7.txt
AC
2 ms
2176 KB
input_8.txt
AC
2 ms
2176 KB
input_9.txt
AC
2 ms
2176 KB