Submission #70063330
Source Code Expand
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<unordered_set>
using namespace std;
int n, m;
vector<vector<char>> map;
unordered_set<string> set;
pair<int, int> d;
int dy[] = { -1, 0, 1, 0 };
int dx[] = { 0, 1, 0, -1 };
int ret = 987654321;
string change1d(vector<vector<char>> v) {
string tmp = "";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
tmp += v[i][j];
}
}
return tmp;
}
bool check(vector<vector<char>> v) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < v[i].size(); j++) {
if (v[i][j] == '#') return false;
}
}
return true;
}
vector<vector<char>> move(vector<vector<char>> v, int dir) {
vector<vector<char>> tmp = v;
if (dir == 0) {
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < m; j++) {
if (v[i + 1][j] == '#') {
tmp[i][j] = v[i + 1][j];
}
}
}
for (int j = 0; j < m; j++) {
tmp[n - 1][j] = '.';
}
}
else if (dir == 2) {
for (int i = n - 1; i > 0; i--) {
for (int j = 0; j < m; j++) {
if (v[i - 1][j] == '#') {
tmp[i][j] = v[i - 1][j];
}
}
}
for (int j = 0; j < m; j++) {
tmp[0][j] = '.';
}
}
else if (dir == 3) {
for (int j = m - 1; j > 0; j--) {
for (int i = 0; i < n; i++) {
if (v[i][j - 1] == '#') {
tmp[i][j] = v[i][j - 1];
}
}
}
for (int i = 0; i < n; i++) {
tmp[i][0] = '.';
}
}
else if (dir == 1) {
for (int j = 0; j < m - 1; j++) {
for (int i = 0; i < n; i++) {
if (v[i][j + 1] == '#') {
tmp[i][j] = v[i][j + 1];
}
}
}
for (int i = 0; i < n; i++) {
tmp[i][m - 1] = '.';
}
}
return tmp;
}
void bfs() {
queue<pair<vector<vector<char>>, int>> q;
q.push({map, 0});
string tmp = change1d(map);
set.insert(tmp);
while (!q.empty()) {
vector<vector<char>> cur = q.front().first;
int cnt = q.front().second;
q.pop();
if (check(cur)) {
ret = cnt;
return;
}
for (int i = 0; i < 4; i++) {
int dir = (i + 2) % 4;
int ny = d.first + dy[dir];
int nx = d.second + dx[dir];
if (ny >= 0 && nx >= 0 && ny < n && nx < m) {
if (cur[ny][nx] == '#') continue;
}
vector<vector<char>> next = move(cur, i);
tmp = change1d(next);
if(!set.count(tmp)) q.push({ next, cnt + 1 });
}
}
ret = -1;
}
int main() {
cin >> n >> m;
map.assign(n, vector<char> (m));
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
map[i][j] = s[j];
if (map[i][j] == 'T') {
d = { i, j };
}
}
}
bfs();
cout << ret;
}
Submission Info
| Submission Time | |
|---|---|
| Task | E - Wind Cleaning |
| User | cocoyi00 |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 2662 Byte |
| Status | WA |
| Exec Time | 2264 ms |
| Memory | 882768 KiB |
Compile Error
Main.cpp: In function ‘bool check(std::vector<std::vector<char> >)’:
Main.cpp:29:35: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
29 | for (int j = 0; j < v[i].size(); j++) {
| ~~^~~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 500 | ||||||||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample00.txt, sample01.txt, sample02.txt |
| All | sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample00.txt | TLE | 2210 ms | 43956 KiB |
| sample01.txt | AC | 1 ms | 3476 KiB |
| sample02.txt | WA | 1 ms | 3440 KiB |
| testcase00.txt | TLE | 2254 ms | 739544 KiB |
| testcase01.txt | TLE | 2264 ms | 871480 KiB |
| testcase02.txt | TLE | 2262 ms | 878280 KiB |
| testcase03.txt | TLE | 2261 ms | 857412 KiB |
| testcase04.txt | WA | 1 ms | 3448 KiB |
| testcase05.txt | WA | 1 ms | 3516 KiB |
| testcase06.txt | AC | 1 ms | 3440 KiB |
| testcase07.txt | WA | 1 ms | 3480 KiB |
| testcase08.txt | TLE | 2207 ms | 3156 KiB |
| testcase09.txt | WA | 1 ms | 3416 KiB |
| testcase10.txt | TLE | 2249 ms | 642116 KiB |
| testcase11.txt | WA | 1 ms | 3428 KiB |
| testcase12.txt | WA | 1 ms | 3576 KiB |
| testcase13.txt | AC | 1 ms | 3416 KiB |
| testcase14.txt | WA | 1 ms | 3404 KiB |
| testcase15.txt | TLE | 2207 ms | 3136 KiB |
| testcase16.txt | WA | 1 ms | 3504 KiB |
| testcase17.txt | TLE | 2249 ms | 644284 KiB |
| testcase18.txt | TLE | 2207 ms | 3236 KiB |
| testcase19.txt | TLE | 2262 ms | 882768 KiB |
| testcase20.txt | TLE | 2255 ms | 689780 KiB |
| testcase21.txt | TLE | 2243 ms | 548852 KiB |
| testcase22.txt | TLE | 2261 ms | 841036 KiB |
| testcase23.txt | TLE | 2249 ms | 644808 KiB |
| testcase24.txt | AC | 1 ms | 3428 KiB |
| testcase25.txt | TLE | 2249 ms | 651920 KiB |
| testcase26.txt | TLE | 2240 ms | 486080 KiB |
| testcase27.txt | WA | 1 ms | 3412 KiB |
| testcase28.txt | TLE | 2214 ms | 103264 KiB |
| testcase29.txt | TLE | 2244 ms | 569924 KiB |
| testcase30.txt | TLE | 2251 ms | 679460 KiB |
| testcase31.txt | TLE | 2253 ms | 640972 KiB |
| testcase32.txt | TLE | 2239 ms | 470796 KiB |
| testcase33.txt | TLE | 2240 ms | 497596 KiB |
| testcase34.txt | AC | 1 ms | 3440 KiB |
| testcase35.txt | TLE | 2251 ms | 673272 KiB |
| testcase36.txt | TLE | 2207 ms | 3308 KiB |
| testcase37.txt | AC | 1 ms | 3540 KiB |
| testcase38.txt | TLE | 2241 ms | 500040 KiB |
| testcase39.txt | TLE | 2251 ms | 644652 KiB |