Submission #978919
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl
template<class T> bool set_min(T &a, const T &b) { return a > b ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }
const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
class Solver {
public:
int H, W;
bool in_field(int y, int x) {
return 0 <= y and y < H and 0 <= x and x < W;
}
bool solve() {
cin >> H >> W;
vector<string> G(H); cin >> G;
int y = 0, x = 0;
int py = -1, px = -1;
while(true) {
int nxts = 0;
int nx, ny;
rep(d, 4) {
int nnx = x + dx[d];
int nny = y + dy[d];
if(in_field(nny, nnx) and (nnx != px or nny != py) and G[nny][nnx] == '#') {
if(d != 1 and d != 2) goto FAIL;
nxts += 1;
nx = nnx;
ny = nny;
}
}
if(nxts > 1) goto FAIL;
if(x == W - 1 and y == H - 1) break;
if(nxts == 0) goto FAIL;
py = y;
px = x;
y = ny;
x = nx;
}
cout << "Possible" << endl;
return 0;
FAIL:
cout << "Impossible" << endl;
return 0;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
Solver s;
s.solve();
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Shik and Stone |
User |
cormoran |
Language |
C++14 (GCC 5.4.1) |
Score |
200 |
Code Size |
2236 Byte |
Status |
AC |
Exec Time |
3 ms |
Memory |
384 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
200 / 200 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt, example2.txt |
All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, example0.txt, example1.txt, example2.txt |
Case Name |
Status |
Exec Time |
Memory |
000.txt |
AC |
3 ms |
256 KB |
001.txt |
AC |
3 ms |
256 KB |
002.txt |
AC |
3 ms |
256 KB |
003.txt |
AC |
3 ms |
256 KB |
004.txt |
AC |
3 ms |
256 KB |
005.txt |
AC |
3 ms |
256 KB |
006.txt |
AC |
3 ms |
384 KB |
007.txt |
AC |
3 ms |
256 KB |
008.txt |
AC |
3 ms |
256 KB |
009.txt |
AC |
3 ms |
256 KB |
010.txt |
AC |
3 ms |
256 KB |
011.txt |
AC |
3 ms |
256 KB |
012.txt |
AC |
3 ms |
256 KB |
013.txt |
AC |
3 ms |
256 KB |
014.txt |
AC |
3 ms |
256 KB |
015.txt |
AC |
3 ms |
256 KB |
016.txt |
AC |
3 ms |
256 KB |
017.txt |
AC |
3 ms |
256 KB |
018.txt |
AC |
3 ms |
256 KB |
example0.txt |
AC |
3 ms |
256 KB |
example1.txt |
AC |
3 ms |
384 KB |
example2.txt |
AC |
3 ms |
256 KB |