結果

問題 No.5006 Hidden Maze
ユーザー a9ua1i0n
提出日時 2022-06-12 17:59:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 4,774 bytes
コンパイル時間 2,008 ms
実行使用メモリ 22,844 KB
スコア 13,073
平均クエリ数 761.37
最終ジャッジ日時 2022-06-12 18:00:31
合計ジャッジ時間 10,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void Astar()’ 内:
main.cpp:107:17: 警告: ‘skip_dir’ はこの関数内初期化されずに使用されるかもしれません [-Wmaybe-uninitialized]
  107 |                 if (dir == skip_dir ){
      |                 ^~

ソースコード

diff #
プレゼンテーションモードにする

#if !__INCLUDE_LEVEL__
#include __FILE__
const char DIR[4] = {'D', 'R', 'L', 'U'};
void output(vector<char> &ans){
for( char c : ans){
cout << c;
}
cout << endl;
}
vector<vector<int>> seen;
map<char,pair<int,int>> dir2num;
ll h,w,p;
struct A{
int cost;
vector<char> ans;
int curX;
int curY;
bool operator<( const A& right ) const {
return cost == right.cost ? ans.size() < right.ans.size() : cost < right.cost;
}
bool operator>( const A& right ) const {
return cost == right.cost ? ans.size() > right.ans.size() : cost > right.cost;
}
};
int CalcCost(int X, int Y, vector<char> &ans){
return (abs(19-X)+abs(19-Y))*100;
}
priority_queue<A, vector<A>, greater<A>> que;
void Astar(){
que.push(A{10000000, {'D','D'}, 0,0});
que.push(A{10000000, {'R','R'}, 0,0});
que.push(A{10000000, {'D','R'}, 0,0});
que.push(A{10000000, {'R','D'}, 0,0});
while (!que.empty())
{
A a = que.top();
que.pop();
if (a.ans.size() > 400) {
return;
}
/////////////////////////////////////////
ll score = 0;
int cnt = 0;
do{
output(a.ans);
cin >> score;
if (score == -1) {
exit(0);
}
cnt++;
if(cnt > 400)break;
}while(score < a.ans.size()-2);
if (score == a.ans.size() - 1) {
continue;
}
if (score == a.ans.size() - 2) {
continue;
}
/////////////////////////////////////////
char skip_dir;
if(a.ans.size() > 0){
switch ( a.ans.back()) {
case 'L' :
skip_dir='R';
break;
case 'U' :
skip_dir='D';
break;
case 'R' :
skip_dir='L';
break;
case 'D' :
skip_dir='U';
break;
}
}
else{
skip_dir=' ';
}
for (int i = 0; i < 1; i++){
for (char dir : DIR ){
if (dir == skip_dir ){
continue;
}
int nxtX = dir2num[dir].first+a.curX;
int nxtY = dir2num[dir].second+a.curY;
if(nxtX < 0 || h <= nxtX || nxtY < 0 || w <= nxtY ){
// cerr << "ans1" << "\n";
continue;
}
if(seen[nxtX][nxtY] <= a.ans.size()+1){
// cerr << "ans2" << "\n";
continue;
}
seen[nxtX][nxtY] = a.ans.size()+1;
vector<char> ans2(a.ans);
ans2.push_back(dir);
int cost = CalcCost(nxtX, nxtY, ans2);
que.push(A{cost, ans2, nxtX, nxtY});
for (char dir2 : DIR ){
int nxtX2 = dir2num[dir2].first+nxtX;
int nxtY2 = dir2num[dir2].second+nxtY;
if(nxtX2 < 0 || h <= nxtX2 || nxtY2 < 0 || w <= nxtY2 ){
// cerr << "ans1" << "\n";
continue;
}
if(seen[nxtX2][nxtY2] <= a.ans.size()+1){
// cerr << "ans2" << "\n";
continue;
}
vector<char> ans3(ans2);
ans3.push_back(dir2);
int cost = CalcCost(nxtX2, nxtY2, ans3);
que.push(A{cost, ans3, nxtX2, nxtY2});
}
}
}
}
}
signed main()
{
cin >> h >> w >> p;
vector<vector<ll>> is_wall(h-1, vector<ll>(w-1));
seen.resize(h, vector<int>(w, 10000000));
dir2num['U'] = pair<int,int>(-1, 0);
dir2num['L'] = pair<int,int>( 0,-1);
dir2num['D'] = pair<int,int>(+1, 0);
dir2num['R'] = pair<int,int>( 0,+1);
vector<char> ans;
Astar();
return 0;
}
//====================temp====================
#else
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define REPITR(itr, ARRAY) for (auto itr = (ARRAY).begin(); itr != (ARRAY).end(); ++itr)
#define RREPITR(itr, ARRAY) for (auto itr = (ARRAY).rbegin(); itr != (ARRAY).end(); ++itr)
#define ALL(n) (n).begin(),(n).end()
using ll = long long;
using ull = unsigned long long;
//#define int long long
template <typename T>
struct edge{
int to;
T cost;
edge(){}
edge(int to, T cost):to(to), cost(cost){}
};
#endif
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0