/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int M = 305;
const int mod = 1e9 + 7;
int n, w, h;
char c[505][505];
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//file("pieaters");
cin >> n >> w >> h;
pair < int, int > pos1;
pair < int, int > pos2;
for(int i = 1; i <= h; i++) {
for(int j = 1; j <= w; j++) {
cin >> c[i][j];
if(c[i][j] == '1') pos1 = {i, j};
if(c[i][j] == '2') pos2 = {i, j};
}
}
if(pos1.first != pos2.first && pos1.second != pos2.second) cout << -1;
else if(pos1.first == pos2.first) {
if(pos1.second > pos2.second) swap(pos1.second, pos2.second);
bool ok = 1;
for(int i = pos1.second; i <= pos2.second; i++) {
if(c[pos1.first][i] == 'x') ok = 0;
}
if(ok) cout << pos2.second - pos1.second;
else cout << -1;
} else {
if(pos1.first > pos2.first) swap(pos1.first, pos2.first);
bool ok = 1;
for(int i = pos1.first; i <= pos2.first; i++) {
if(c[i][pos1.second] == 'x') ok = 0;
}
if(ok) cout << pos2.first - pos1.first;
else cout << -1;
}
}
Compilation message
robots.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
30 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |