QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#447097 | #6979. Awesome Arrowland Adventure | RaduM | 100 ✓ | 11ms | 7652kb | C++20 | 2.4kb | 2024-06-17 22:04:45 | 2024-06-17 22:04:45 |
Judging History
answer
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
int a[505][505];
int t[505][505];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int val[200];
vector < queue < pair <int, int> > > q(4);
string s;
int n,m;
void bfs(int sx, int sy){
for(int e = 0; e < 4; e++){
int x = sx + dx[e], y = sy + dy[e];
if(a[x][y] == -1) continue;
if(t[x][y] > t[sx][sy] + ((4 + e - a[sx][sy]) & 3)){
t[x][y] = t[sx][sy] + ((4 + e - a[sx][sy]) & 3);
q[(4 + e - a[sx][sy]) & 3].push({x,y});
}
}
while(1){
int temp = inf, c;
for(int i = 0; i < 4; i++){
if(q[i].empty()) continue;
if(t[q[i].front().first][q[i].front().second] < temp){
temp = t[q[i].front().first][q[i].front().second];
c = i;
}
}
if(temp == inf) return;
pair <int, int> f = q[c].front();
if(f.first == n && f.second == m) return;
q[c].pop();
for(int e = 0; e < 4; e++){
int x = f.first + dx[e], y = f.second + dy[e];
if(a[x][y] == -1) continue;
if(t[x][y] > t[f.first][f.second] + ((4 + e - a[f.first][f.second]) & 3)){
t[x][y] = t[f.first][f.second] + ((4 + e - a[f.first][f.second]) & 3);
q[(4 + e - a[f.first][f.second]) & 3].push({x,y});
}
}
}
}
int main()
{
int i,j;
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
val['N'] = 0;
val['E'] = 1;
val['S'] = 2;
val['W'] = 3;
val['X'] = -1;
memset(t, 0x3f, sizeof t);
for(i = 0; i <= n + 1; i++) a[i][0] = a[i][m + 1] = -1;
for(i = 0; i <= m + 1; i++) a[0][i] = a[n + 1][i] = -1;
for(i = 1; i <= n; i++){
cin.get();
cin >> s;
for(j = 0; j < m; j++) a[i][j + 1] = val[s[j]];
}
if(a[1][1] == -1){
cout << -1;
return 0;
}
a[n][m] = 0;
t[1][1] = 0;
bfs(1, 1);
// for(i = 1; i <= n; i++){
// for(j = 1; j <= m; j++) cout << a[i][j] << " ";
// cout << "\n";
// }
// cout << "\n\n\n";
// for(i = 1; i <= n; i++){
// for(j = 1; j <= m; j++) cout << t[i][j] << " ";
// cout << "\n";
// }
if(t[n][m] == inf){
cout << -1;
return 0;
}
cout << t[n][m];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 4552kb
input:
1 325 EEEEEEEEEXEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEXEEEXEEEEEXEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEXEEEEEEEEEEEEEEEEEEEXEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEE...
output:
-1
result:
ok single line: '-1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4504kb
input:
1 232 EEEEEEEEEEEEEXEEEEEEEXEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEX
output:
-1
result:
ok single line: '-1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 4792kb
input:
1 275 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEX
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4508kb
input:
1 421 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE...
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 4628kb
input:
1 379 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEE...
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4620kb
input:
1 188 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEX
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 4820kb
input:
1 12 EEXEEEEEEEXX
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4560kb
input:
1 350 EEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE...
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 1ms
memory: 4824kb
input:
1 435 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEXEEEEEXEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE...
output:
-1
result:
ok single line: '-1'
Test #10:
score: 0
Accepted
time: 1ms
memory: 4500kb
input:
1 122 EEEXEXEEEEXEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEXEEEEEEEEEEEEEEEXEEEXEEEEEEXXEEEEEEEEEEEEXEEEEX
output:
-1
result:
ok single line: '-1'
Subtask #2:
score: 12
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 12
Accepted
time: 1ms
memory: 4596kb
input:
1 59 XSSWWWNSXNXSSWWESXSENSNXWWENNWEWSNXXNEEWXXENEENXXSNXSXNWWSX
output:
-1
result:
ok single line: '-1'
Test #12:
score: 0
Accepted
time: 1ms
memory: 4564kb
input:
1 319 SWWWSWNSNSWENENWWSSWEEESESWNWSSENEWSEENNNNNWEEEESENWWNWWSSSNSENSNNNWNWESNSSESWWNSNESNSENWWESNNWWESNWSESNSWNSEEWNNNNEESWEEWWNSNSSWNWSWSEENWSWNWSNSEESSWENEEEEWNNNEESNSSWWNWENSWEESWSNENNSNWWSNSWEESENNEEESEEWWESNWSESNNNSEEEWSSNWWSNNWWSNSNWEWEEESWWSSEESSSENEENEEEESSSEEWESNSSWSENWSSNWWWWNESSNENWEEWW...
output:
474
result:
ok single line: '474'
Test #13:
score: 0
Accepted
time: 1ms
memory: 4624kb
input:
1 485 EESENESSSNENSEEESWNEWNWESENESWNNNEENEEWNWSNESWSWWSSNSEESNSWNSSNSSSENWWEEWWWSSEEEENNNWWNNWNWEWWNSSSWNEESWNSWSEEESWSEWEENWWEEEENEEWNNWEWNSEWESSSSNESWEESEEEEEWWNEWSSENSWSSENSESWESNNSWWSNWNWWWSSENESNENWSNWNSEENEEWWNNSSESSSEESSEWNSWEWSNWWWSWWNWWNWWWNWNWESESNSEWESNSWNSSWSENWNEWWSNESNNENWNNNSSESENNSN...
output:
712
result:
ok single line: '712'
Test #14:
score: 0
Accepted
time: 1ms
memory: 4548kb
input:
1 21 WNSNESNWESEENSEWWWENX
output:
27
result:
ok single line: '27'
Test #15:
score: 0
Accepted
time: 1ms
memory: 4504kb
input:
1 173 ENSSEENSEESESNEWEWNWSSESSNSNSESSNNWSSWESEEWSSNESNNWNWNNESENNNNEWNWNWSNSNEWSWSESWSNEWSWNSWESNWNENSESWSNWSWWSNNWSENWEWNEWWNWWSWWNSWSWWEWNSWSSEENWENSNSNEESSNNSENNWSNENWWNNSSWWX
output:
278
result:
ok single line: '278'
Test #16:
score: 0
Accepted
time: 1ms
memory: 4564kb
input:
1 364 SWSNSSENSWWSEWWWWENSEEENNNSEWNNSWSSESENENNNWSNESWWENWEEWWSWNESNEENNWSSWNNSNWESSESSEESSWSWEEWSWNENNSSSSENWSEWWNSSNSEEWNSWEWENSEEWESSSNWSWESNESNSSWNWESEEWNEENESNSWEWEESNNSNSWSSWENWNWWNSWNSWWNWNSNEWNENWNWSESSWNEWNSNNEEESWEWENSSWEWNWSENENESNEWEWSSNSNNWNSSENNWNWSEENEWNWWWSESWWWSSWWEENSEESWWESEWNNSN...
output:
543
result:
ok single line: '543'
Test #17:
score: 0
Accepted
time: 1ms
memory: 4596kb
input:
1 377 ESWSWWWNNEWSWNNNEENWWESSNWNNEESSWNEWSWESSSNEWNENNSWNEENSWESSNWENSSSSNSENNSNNENENEWSEWSSENWNWNWWWNSEEWNNNEWWNWWNWWENNESWESNWEEWWENESSNSWWSENNNESEEWNSEENWSWSEEWESEWENSWSWNSWNSESENSSWNSNSSESENNSSNNWWWNSNWNSSESWWESWWWWNWNWSSWENNSWSENWNNSNNEWEEENNEWNWNWSESNNEWWWESWNESNSESSENWNNWEEWEWSWNSNEESSNNNNWW...
output:
572
result:
ok single line: '572'
Test #18:
score: 0
Accepted
time: 1ms
memory: 4560kb
input:
1 110 NSWWNNSNESSESSSEWSEWWSSNWNNENWNWSWNWSEENSWNESNNSWSEENENSNWSNEWNEWSNSWSNEEESWESSNWSENWNWWSWEWWEESNWSWWSNWNWEWSX
output:
177
result:
ok single line: '177'
Test #19:
score: 0
Accepted
time: 1ms
memory: 4616kb
input:
1 150 EWESNWSWSSSNEEWSNEWNSWNWENWNWEWSWSNNNNSWNNSWSWENWSEENWSENEWWESSESWNSNWEEWSEEEEWWNEEENWNNNENNNEESNESENNNEEEESSSSSEWWWSWNEENNESWWESNNNWWWESESNWEWENNSWSX
output:
210
result:
ok single line: '210'
Test #20:
score: 0
Accepted
time: 1ms
memory: 4600kb
input:
1 471 WESESENEWENSSESSNNNNSEWSNWSSWESEEWEEENSSESEENNWSWSNWWESWSNNNESNSSSWWNEEWEENESWWSNNNSWNNENNNWEENESSSWNENWWWSNWWNWNSNEEWEWEESSSNWNWSWENWWWNEESENSEEWNWENWNSEENNWWWEWWSWENWWENNSWSEENESSNSSSSWSSSENNESSWWENNENENNWENSWSSWNNNSWESSWSESWSSSNWSSWNNNNEEESWSWWWWSNWWEWESSNEENNWSSSENNWSNWWENNSESSSSEWSSSEWSES...
output:
725
result:
ok single line: '725'
Subtask #3:
score: 12
Accepted
Test #21:
score: 12
Accepted
time: 1ms
memory: 4564kb
input:
3 3 SNX SEE XXX
output:
4
result:
ok single line: '4'
Test #22:
score: 0
Accepted
time: 1ms
memory: 4620kb
input:
3 3 EWE SNN WXX
output:
5
result:
ok single line: '5'
Test #23:
score: 0
Accepted
time: 1ms
memory: 4568kb
input:
3 3 WXE XXN SWX
output:
-1
result:
ok single line: '-1'
Test #24:
score: 0
Accepted
time: 1ms
memory: 4564kb
input:
3 3 XSW SSX WWX
output:
-1
result:
ok single line: '-1'
Subtask #4:
score: 16
Accepted
Test #25:
score: 16
Accepted
time: 1ms
memory: 4532kb
input:
2 496 WSXWWESEEXWXXWXESWNENEEWXEXNENXESEEWSENXSWSSNSWSXESSXEXWNEXWWNEESSNSXSNSESESNWWEXNWXNNEEWWXWXXEWNENXXWEEWWXXEWEWXEEEENSNXNEEEWSEEEWSEWSWXSEXSWXSXESWNWXXXXENNWNEWSWSSWSXNXXEWXEXNESNEWSXSNSEWWSNSSENNXSNNWXSSNXNWXXSNXSNSSXEESEESSWNXNNWSSNSSWSEEEWNXXWSEEEWENSWXNXXSENXWNSENSXXSNEXXWSXXXEEEENNNNEWNX...
output:
-1
result:
ok single line: '-1'
Test #26:
score: 0
Accepted
time: 1ms
memory: 4820kb
input:
2 57 SWEESSSENESWENWESNWWWWESNSWNWWSSSSESNNWNNENENENEESSSENNWN ENNSESEWWNNEWSSWWESNENEEWSENEEWENNESEWNENWNSNEWNNEEESNEEX
output:
42
result:
ok single line: '42'
Test #27:
score: 0
Accepted
time: 1ms
memory: 4640kb
input:
2 219 NESNWSEEEEEWNNNNSNENWSESESNSWSNWWSNNENWWSSESNENENNNENEWSENNSNNESEEESEEEENNNSWSNENSESNNWNSSSWNNNNSSNSEESENWNWNSWSEWNNNNSESESSWNESWENSSWESNWNNWSWENSEWSWSWSWSWEWESNENENENWNWNWWEWEWEWSSNENWSEWNWEWWSSEWWEWWSNSWWEWEWWNNEWESNS SSSSSSSSSSNSNNNSWWSSWEWWSSENNWNNNNNWWNNENEWWNNWSWENSEWSNENWEEEESENNSNWSSWE...
output:
229
result:
ok single line: '229'
Test #28:
score: 0
Accepted
time: 1ms
memory: 4568kb
input:
2 167 WESNSESWWEWWNSEENNSSWEWEEWWNNSSSESSSNENWENEWESSSWWSESENWNWNNWWSSNNSWWNNNEEENNSEWNESNWSSSSWWNWENWSSWNWNSENSSWNEWENSWESWESWNENWWNENNSENWNNEWENENNNSSSNSSNEWESWNNWENNEWWSE WEEEEESWEEWWWSNSNENWEEESWNSNNNWENNSNSSSSSSEESNWENNEWWNSSNWEWESNESSSWWSWSNNSSEEESWSNSWSNWSWSNNNEWEWWEEWSNSNSNWEEEWEEWNESSWSESWW...
output:
189
result:
ok single line: '189'
Test #29:
score: 0
Accepted
time: 1ms
memory: 4800kb
input:
2 423 WNWESNSWSSEENWSNSEESENESNNWNNSNNNEEWSSWWSWSWSSEWWSEESSNEWSSSWENNENEESSSSWWSEWSSWNWNWSSNESSEWSWNSNENNEWWSNENSWNEEENESWWNNENWEWNNSWNEENWSENSEWNESNNEESNENENNWSWNNNSEENWENWEWSSSESEWWSWWWWNWWNWNESSESWEWWSNNWWNNSSNSESENENWNESEENSWNESSESSNNNSNSSWEEWNSNSNSNNSENWNSENESNEWNSESNSESNNSEWESSESEWNNSNWWWESWS...
output:
500
result:
ok single line: '500'
Test #30:
score: 0
Accepted
time: 0ms
memory: 4628kb
input:
2 367 NWSSSWWSSSNWEWSEWNEENSWEEESESSSSEEENNEEWNWNNNWSEWESWNENNEWNSWESSSWNWNWWNWEEESEEWSEWSNEWWSSEENSWESNSWNNWNESSNNWWWNNNWENNSESSWENSNNSSEEWEWEESNEEWEEEWENWNWSWWNSENSWSSENENENWWENNWWNWWSEEENESEEENWNWENEWSWSEENSESEWNEEWWSWSNEWWWSWNWWESSESWNSSWSSSWEWEWEEWEEWENSSEWWNEWNENESNEEWNNNWWEWWENNNSNEEWWWNSNWWW...
output:
426
result:
ok single line: '426'
Test #31:
score: 0
Accepted
time: 1ms
memory: 4876kb
input:
2 175 WENNENSSNNSWENWWSWSWNENWWWNSEWSWEWWNNWNSWWSWNNSWWWSEEESWNEESSWWEESWEENNWSSSWSNNWEESESESSWSNWEWSNEWWNWNSSWWNENWEEENWNWNNWWWWSNNENWSNNENWENNWNWWWWSWNSEWENWWEEWEWSEWENNNESNNWNNSS NEWSSSESWNWESSNSSNSSWESWWENNSEENNSSWSNENWNNSNESENNNEEWEWSEWSWWNSEESSSSSNSEEWSSWSNSENNWWWEWNSESNESNEEEWNNEWNSWNWWEEEWWE...
output:
200
result:
ok single line: '200'
Test #32:
score: 0
Accepted
time: 1ms
memory: 4556kb
input:
2 66 NEWENNWSWEWWESNWEEWWNNNWWENENSESENWWNEWENENSSENSNSEWWWEEWNNSEENEES EEENSNESWEENESSSNWSNWNEWSWSWSSSNEENWSSSESNWNWWWWNENEWWSWSNSNWEWEWX
output:
66
result:
ok single line: '66'
Test #33:
score: 0
Accepted
time: 1ms
memory: 4616kb
input:
2 68 NWSNWNWEEESNSNSNENWENSWWSWSWNNNWWWWENEENNENEENEESSESWSNSNNSSNNSWSWNW WSNNSSSEENESWSEWNSESSEWEEWWENENEENNWWESSEENSWSNNNSENENNSSWEWSNNWNWNX
output:
64
result:
ok single line: '64'
Test #34:
score: 0
Accepted
time: 1ms
memory: 4504kb
input:
2 56 EWWNNEESNWNSWEWSENNWNNSESSNSWWNSNWWENEWNWNSNNNNEWWWSWNEN SSSWWEESNWSEWSNNSESSEEWSWSWEWENNWEWNEEEWWWWWNEEWSWWWEEWX
output:
67
result:
ok single line: '67'
Subtask #5:
score: 50
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #35:
score: 50
Accepted
time: 2ms
memory: 4672kb
input:
56 409 SEXWWWSEWWEESSWNNXNSESSWXXWESSWWSEWEWWXEXWEWWXESNXSXSWSEEXEXSXSWSEWWNSEEWNSWXENEXXSNNXNWXWSXWXNENSWNNSNNEWENENSNESWWWEXSWESNXXEWSENSSWSNSEWNXEXWSNWSXSWEXNEWEWSWWWWWNNWNXSXEENSSEEXEWXNENXWXSSWSXXXESXEXXNSXXXEWNENSSXNEENWNNNNNXWWWSXESXEWENXEXSNNSSXSWSSNWEEWXSNSEXNXSWNNNWESXWEWXXXWEXEWNXXENWEEXE...
output:
-1
result:
ok single line: '-1'
Test #36:
score: 0
Accepted
time: 1ms
memory: 4520kb
input:
7 326 XWESWNENNNNEEESEEXNSXESXSNXWWXXSESNENESEXWNEXNWENSNXWWENXXNWWXXSEXXESESXEEEWXENESNNNEWXWWSXWXXSSESNXXNSNEWEESXXSEXXEEWNXEWXESWSXXWSSSNEWXNEWWWNNNSSWXXNEEWNNEWNXXNSWNNSSWXEENEEXNNWXWNSWNXWWSXSSESEENNESWWSNEEXWEESENWXWNXXSNEXWWNXWNXWWSXWSNSNSXEWXXWEEWSSWNWESXEXSWXNNXEEWSSXWSXSWXXEWSESWSSSXWXNWXN...
output:
-1
result:
ok single line: '-1'
Test #37:
score: 0
Accepted
time: 2ms
memory: 5076kb
input:
105 255 WNESEENEWXNSNEWEEEXENXSSXXNWNWESXSWEESWNSSSENXXNEENSWENXWEXNNSEWWWXSNENWNXXXWEWWESEWSNEEWSWNNNEEESESNSXNXWENNWSSWXEENXWWNSXENNSWSWWXSESWSSENWWSXNWSNSXSSXSWNXXSWEESSSXXNNXSEXNWWNSXNNSWNESXWSNEXNNXENSXSNESXXWEEWWSNNEEXWXXSEESSWNSXNSXEWEWWXEXWESESSNSXESSWSWS EXXXXXWENXSSXSWXNNXWXSXENSWXSSNEWNNN...
output:
260
result:
ok single line: '260'
Test #38:
score: 0
Accepted
time: 1ms
memory: 5148kb
input:
264 156 XSNESSWSWWESEWSEWXXNNNWNWWXEXEWWNEEWXWXXSEWEENEEWWENEXWWESXEXNWNESWNWEXSXXXNENWEWSNNWWSNWEXSWXSNWNEEWEWXWEWWWWEWWSWSXWXSXXWNEWWESENWNSWNXWENXXXNSWEEEENSNNEX XXNSXESNENEEXXXNNWSNXNWWNEWSWXENEEEESSNNEEWXNXWEWXNNSESEWNXWSEXEWSXNENESNWEEXSWEEWNNWXSNESWXSNSWXWWWNXXEXXSXSSEXWWSEXSSWSNSSSEENNSWNWNN...
output:
-1
result:
ok single line: '-1'
Test #39:
score: 0
Accepted
time: 7ms
memory: 5856kb
input:
500 500 NEWXESESNXNWNNWEWWSNEXWNWXEEEXSWNEENSESESNSWXEWXSSXNNSSXSWENWWEENXSSWXSSSWNSSEWSSENNWNSWSWXXSXXWWXENSWNWNWNNNXNNNXSWWNSSXSSSEWNXNSNWWWNEESXSWWENENEXESNEEWSESESXXNWEEEEEXNWWWSNWEWENXWXSENENNWSXWSWSWESNEXXENNWNXENWWNNXEXXWSWNNENNXEXEEWESENEXWNXNEWSSXXSEXWNXSENEWSWWSEXWENSEEWESNXSEENWEEWSENSSSX...
output:
668
result:
ok single line: '668'
Test #40:
score: 0
Accepted
time: 11ms
memory: 5508kb
input:
500 500 SSWEXWESXWSNEXXSSXSNWWNXEWWNNSSWXXEXXSWXWWENENENEXSESWEWXWWWNSWEXSESESEWNNWWNXWEESXSWENWXWNSXNENNNEWSENSXNSWNNNSEWNENNXSNESSENWESWXWEEEEEENXXWXNEXNSSEEWWWWSSWXWEXSXXESWXSSESNNWEXSWWNSXWSEXSEXXNXWNSSWXNXSNNXSESENXSNNSESNESXXXWNWXXENXNNWXWEWWWNEXSNNNXXWEWWSSENSXXNWESXESXNXXXXXXNWXSWESSENWNXWWX...
output:
697
result:
ok single line: '697'
Test #41:
score: 0
Accepted
time: 0ms
memory: 5612kb
input:
500 500 WXNSXXXWEWXEWNSXWNEESSSNSXSXENWWXXNXNSWXWEEWWSSSXXXSXESWSNWSXWSEXENEEWENSXSXXENWNWNSSSNESEENWSEENXNENWSXEEWWXXWWSNSNNXNESSEESESXNEXNENEWSSWENEXEESENNWENWSEWNWWWXWWXXSNSSNESWXNWSXENNXWSENSSEXSNNNXWNNSNENXSNEWEEWXWENNXSENEXESNSENSSNENXWWXWEWNEENNWXNENWEESXEXENSWSEWSESSWSNWSXEENSSXXESENXXENNENW...
output:
-1
result:
ok single line: '-1'
Test #42:
score: 0
Accepted
time: 11ms
memory: 5592kb
input:
500 500 NEXWEXNNWWWXSNXEXEEEXSSSSEWSSSSEWNSNWXWNEWSSSWWEWSNWEENWENENNEWSSXXXXNSESSSEXNNEXXSNNEWNSEXNWXSSXNNXEWXWNSWSXNNSWWSSWXXXSNSSNNEWENWXEXESSXWXSWNSNSSNWEEXSXNNWWSNNXWWSSENXNWSXXENEWEEXXWESSWEWENXWWEEXSWXWWENNESWWSNXESNSEXNNSEWNNWWNSWWWWWXNEEEXNSWEENNNWXEWXWEWWNWEEXWSENXNNNNNWENWXXNNWSSEWEXNNSNS...
output:
700
result:
ok single line: '700'
Test #43:
score: 0
Accepted
time: 8ms
memory: 7652kb
input:
499 499 EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE...
output:
0
result:
ok single line: '0'
Test #44:
score: 0
Accepted
time: 1ms
memory: 5552kb
input:
500 500 XWSXEEXWWSNSWWEENSEXENNNSESSNXXEXSXNSNWXWXXNWNXNSNSEXENXSWXEXWNNWEXEXXEEXNESEESXEWENSSWWWNWWWWXSWXXNSESEWSNENSNSWESEXENXWWSSSSXWXNWEWWWXXWENEXWXWNNSESENNESSNSSXXXEEXSSEEWWXNXNSSXSWSWNENEENNWWWWNSXWNXWNXSSXSNXWWENXWWXXNSSSSWSSWSXSNSSNENSSWNESEWNSWSSWESWEXXWSXNEENSWSEXWWXSWXEWNXWEESNEEXSSXNEEE...
output:
-1
result:
ok single line: '-1'