Submission #18341403
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'
#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)), __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=2005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
char a[N][N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// memset(dis, -1, sizeof dis);
int n, m;
cin >> n >> m;
pii start, end;
// vi port(26,INT_MAX);
vector<vector<int>> dis(n + 1, vector<int> (m + 1, INT_MAX));
vector<pii> port[26];
forn(i,n)forn(j,m){
cin >> a[i][j];
if(a[i][j] == 'S')start = {i,j};
if(a[i][j] == 'G')end = {i,j};
if(a[i][j] >= 'a' && a[i][j] <='z')
port[a[i][j] - 'a'].pb({i,j});
}
queue<array<int,3>> q;
q.push({start.fi, start.se, 0});
dis[start.fi][start.se] = 0;
while(!q.empty()){
auto to = q.front();
q.pop();
int x = to[0];
int y = to[1];
int d = to[2];
forn(k,4){
int xx = x + dx[k];
int yy = y + dy[k];
if(xx >= n || yy >= m || xx < 0 || yy < 0 || a[xx][yy] == '#')continue;
if(dis[xx][yy] <= d + 1)continue;
dis[xx][yy] = d + 1;
q.push({xx, yy, d + 1});
}
if(a[x][y] >= 'a' && a[x][y] <='z'){
int ch = a[x][y] - 'a';
for(auto pp : port[ch]){
if(dis[pp.fi][pp.se] <= d + 1){
continue;
}
dis[pp.fi][pp.se] = d + 1;
q.push({pp.fi, pp.se, d + 1});
}
}
}
// forn(i,n){
// forn(j,m)
// cout << dis[i][j] << " ";
// cout << "\n";
// }
int ans = dis[end.fi][end.se];
if(ans == INT_MAX)ans = -1;
cout << ans;
}
Submission Info
Submission Time
2020-11-22 22:34:07+0900
Task
E - Third Avenue
User
shadow883
Language
C++ (GCC 9.2.1)
Score
0
Code Size
4304 Byte
Status
TLE
Exec Time
3308 ms
Memory
28460 KiB
Compile Error
./Main.cpp: In function ‘long long int powb(long long int, long long int)’:
./Main.cpp:30:30: warning: statement has no effect [-Wunused-value]
30 | ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
| ^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
0 / 500
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt, sample_03.txt
All
hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name
Status
Exec Time
Memory
hand_01.txt
AC
5 ms
3504 KiB
random_01.txt
AC
4 ms
3664 KiB
random_02.txt
AC
2 ms
3520 KiB
random_03.txt
AC
4 ms
3644 KiB
random_04.txt
AC
2 ms
3596 KiB
random_05.txt
AC
2 ms
3524 KiB
random_06.txt
AC
3 ms
3576 KiB
random_07.txt
AC
2 ms
3544 KiB
random_08.txt
AC
3 ms
3664 KiB
random_09.txt
AC
2 ms
3540 KiB
random_10.txt
AC
3 ms
3564 KiB
random_11.txt
AC
2 ms
3640 KiB
random_12.txt
AC
2 ms
3516 KiB
random_13.txt
AC
3 ms
3460 KiB
random_14.txt
AC
4 ms
3700 KiB
random_15.txt
AC
2 ms
3536 KiB
random_16.txt
AC
21 ms
6128 KiB
random_17.txt
AC
169 ms
15188 KiB
random_18.txt
AC
111 ms
9820 KiB
random_19.txt
AC
24 ms
6168 KiB
random_20.txt
AC
145 ms
14996 KiB
random_21.txt
AC
6 ms
4176 KiB
random_22.txt
AC
12 ms
4408 KiB
random_23.txt
TLE
3308 ms
12104 KiB
random_24.txt
TLE
3308 ms
11524 KiB
random_25.txt
AC
30 ms
6480 KiB
random_26.txt
AC
5 ms
3816 KiB
random_27.txt
AC
75 ms
11876 KiB
random_28.txt
AC
9 ms
4604 KiB
random_29.txt
AC
3 ms
3548 KiB
random_30.txt
TLE
3308 ms
13508 KiB
random_31.txt
AC
683 ms
26108 KiB
random_32.txt
AC
2127 ms
28460 KiB
random_33.txt
AC
178 ms
23228 KiB
random_34.txt
AC
90 ms
22524 KiB
sample_01.txt
AC
3 ms
3560 KiB
sample_02.txt
AC
2 ms
3596 KiB
sample_03.txt
AC
3 ms
3592 KiB