提出 #71689990
ソースコード 拡げる
//#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include <stdlib.h>
#include<string>
#include<math.h>
#include<sstream>
#include<set>
#include<math.h>
#include <algorithm>
#include<map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include<tuple>
#include <bitset>
#include <queue>
#include <iomanip>
#include <stack>
#include<time.h>
#include <unordered_set>
#include <random>
using namespace::std;
#define RANDMAX 100000
#define ll long long
#define lint long long int
#define ldouble long double
#define ALL(a) (a).begin(),(a).end()
using ve = vector<lint>;
vector<vector<int>> map2;
//
using Gra = vector<vector<lint>>;
using sve = vector<string>;
//
//cout << std::fixed << std::setprecision(15)<< ans;//�����_
//
//
//<stack>//�ォ��
// box.push()
// box.pop()
// box.top()
//
// <queue>������
// box.push()
// box.front()
// box.pop()
//
// <set>
// ite=g2.lower_bound(r) set�T��
// distance(ls.begin(), ite);�T��������̈���
// advance() �͋ɗ͎g��Ȃ����ƁI�I�@***************************************
// g2.count() set()���̌�
// lower_bound(a.begin(),a.end(),a[i])
// box.size()
//
// <vector>
// vector<int>
// lower_bound(a.begin(),a.end(),a[i])
// vector<vector<lint>> v(2, vector<lint>(3)) -> v.at(1).at(2);
// next_permutation(aaa.begin(), aaa.end()) �x�N�^�[�̑g�ݍ��킹
//
//<2���T���@�`�蓮�����`>
// int binary_search(int key) {
// int left = 0, right = (int)a.size() - 1; // �z�� a �̍��[�ƉE�[
// while (right >= left) {
// int mid = left + (right - left) / 2; // ��Ԃ̐^��
// if (a[mid] == key) return mid;
// else if (a[mid] > key) right = mid - 1;
// else if (a[mid] < key) left = mid + 1;
// }
// return -1;
// }
//
// <bit�S�T��>
//�@bitset<60> bs(n);
//
//�{��swap����Ƃ��͔��̔ԍ���ς���
/* par=time_check(nh, nm);
nh = par.first; nm = par.second;*/
pair<lint, lint> time_check(int h, int m) {
while (m >= 60) {
h += 1;
m -= 60;
}
while (m < 0) {
h -= 1;
m += 60;
}
return make_pair(h, m);
}
std::random_device seed_gen;
uint32_t get_rand() {
// ����������i�����ɃV�[�h���w��\�j
static std::mt19937 mt32(seed_gen());
// [0, (2^32)-1] �̈�l���z������
return mt32();
}
class ansd {
public:
int p;
int x;
int y;
};
class zahyo {
public:
int x;
int y;
};
int main() {
lint h, w,nh,nw,an,ans=-1;
cin >> h >> w;
vector<string >ma(h);
vector<vector<bool>>ok(h,vector<bool>(w));
vector<set<pair<int, int>>>wap('z' - 'a' + 1);
for (lint i = 0; i < h; i++) {
cin >> ma[i];
for (lint j = 0; j < w; j++) {
if (ma[i][j] >= 'a' && ma[i][j] <= 'z') {
wap[ma[i][j] - 'a'].insert(make_pair(i, j));
}
}
}
queue<tuple<int, int,int>> box;
// h w
tuple<int, int,int> res;
set<char> mozi;
box.push({ 0,0,0 });
while (box.size() != 0) {
res = box.front();
box.pop();
nh = get<0>(res);
nw = get<1>(res);
an = get<2>(res);
if (nh == h - 1 && nw == w - 1) {
ans = an; break;
}
if (ma[nh][nw] >= 'a' && ma[nh][nw] <= 'z') {
if (mozi.find(ma[nh][nw]) == mozi.end()){
for (auto v : wap[ma[nh][nw] - 'a']) {
if (ok[v.first][v.second] == 0) {
box.push({ v.first,v.second,an + 1 });
ok[v.first][v.second] = 1;
}
}
mozi.insert(ma[nh][nw]);
}
}
if (nh != 0) {
if (ok[nh-1][nw] == 0&& ma[nh - 1][nw] !='#') {
box.push({ nh-1,nw,an+1 });
ok[nh-1][nw] = 1;
}
}
if (nh != h-1) {
if (ok[nh + 1][nw] == 0 && ma[nh + 1][nw] != '#') {
box.push({ nh + 1,nw,an+1 });
ok[nh +1][nw] = 1;
}
}
if (nw != 0) {
if (ok[nh][nw-1] == 0 && ma[nh ][nw-1] != '#') {
box.push({ nh,nw-1,an+1 });
ok[nh][nw-1] = 1;
}
}
if (nw != w - 1) {
if (ok[nh][nw+1] == 0 && ma[nh][nw+1] != '#') {
box.push({ nh,nw+1,an+1 });
ok[nh][nw+1] = 1;
}
}
}
cout << ans;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Teleport Maze |
| ユーザ | tbbt95 |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 400 |
| コード長 | 4853 Byte |
| 結果 | AC |
| 実行時間 | 429 ms |
| メモリ | 64356 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3484 KiB |
| 00_sample_01.txt | AC | 1 ms | 3512 KiB |
| 00_sample_02.txt | AC | 1 ms | 3496 KiB |
| 00_sample_03.txt | AC | 1 ms | 3608 KiB |
| 01_random_00.txt | AC | 1 ms | 3608 KiB |
| 01_random_01.txt | AC | 24 ms | 9560 KiB |
| 01_random_02.txt | AC | 23 ms | 5656 KiB |
| 01_random_03.txt | AC | 429 ms | 63880 KiB |
| 01_random_04.txt | AC | 22 ms | 5896 KiB |
| 01_random_05.txt | AC | 46 ms | 13992 KiB |
| 01_random_06.txt | AC | 27 ms | 6976 KiB |
| 01_random_07.txt | AC | 24 ms | 5940 KiB |
| 01_random_08.txt | AC | 1 ms | 3608 KiB |
| 01_random_09.txt | AC | 16 ms | 4276 KiB |
| 01_random_10.txt | AC | 31 ms | 5784 KiB |
| 01_random_11.txt | AC | 359 ms | 52392 KiB |
| 01_random_12.txt | AC | 31 ms | 6424 KiB |
| 01_random_13.txt | AC | 23 ms | 6104 KiB |
| 01_random_14.txt | AC | 39 ms | 6848 KiB |
| 01_random_15.txt | AC | 37 ms | 5928 KiB |
| 01_random_16.txt | AC | 1 ms | 3640 KiB |
| 01_random_17.txt | AC | 6 ms | 4280 KiB |
| 01_random_18.txt | AC | 13 ms | 5640 KiB |
| 01_random_19.txt | AC | 256 ms | 40856 KiB |
| 01_random_20.txt | AC | 112 ms | 22936 KiB |
| 01_random_21.txt | AC | 150 ms | 27112 KiB |
| 01_random_22.txt | AC | 23 ms | 8252 KiB |
| 01_random_23.txt | AC | 64 ms | 16296 KiB |
| 01_random_24.txt | AC | 1 ms | 3496 KiB |
| 01_random_25.txt | AC | 5 ms | 4924 KiB |
| 01_random_26.txt | AC | 13 ms | 5744 KiB |
| 01_random_27.txt | AC | 151 ms | 28872 KiB |
| 01_random_28.txt | AC | 125 ms | 24336 KiB |
| 01_random_29.txt | AC | 75 ms | 17828 KiB |
| 01_random_30.txt | AC | 104 ms | 22316 KiB |
| 01_random_31.txt | AC | 107 ms | 22824 KiB |
| 01_random_32.txt | AC | 1 ms | 3640 KiB |
| 01_random_33.txt | AC | 12 ms | 5940 KiB |
| 01_random_34.txt | AC | 13 ms | 5668 KiB |
| 01_random_35.txt | AC | 73 ms | 17076 KiB |
| 01_random_36.txt | AC | 21 ms | 7832 KiB |
| 01_random_37.txt | AC | 21 ms | 7336 KiB |
| 01_random_38.txt | AC | 51 ms | 13308 KiB |
| 01_random_39.txt | AC | 41 ms | 12352 KiB |
| 02_handmade_00.txt | AC | 22 ms | 5668 KiB |
| 02_handmade_01.txt | AC | 150 ms | 64356 KiB |
| 02_handmade_02.txt | AC | 13 ms | 5672 KiB |
| 02_handmade_03.txt | AC | 13 ms | 5588 KiB |
| 02_handmade_04.txt | AC | 18 ms | 5784 KiB |
| 02_handmade_05.txt | AC | 22 ms | 5656 KiB |
| 02_handmade_06.txt | AC | 205 ms | 52776 KiB |