結果

問題 No.331 CodeRunnerでやれ
ユーザー koyumeishi
提出日時 2015-12-24 23:45:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,013 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 109,852 KB
実行使用メモリ 86,188 KB
最終ジャッジ日時 2024-07-16 22:44:17
合計ジャッジ時間 14,546 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other TLE * 1 -- * 15
権限があれば一括ダウンロードができます

ソースコード

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

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <stack>
#include <random>
using namespace std;
template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
template<class T> istream& operator , (istream& is, T& val){ return is >> val;}
template<class T> ostream& operator << (ostream& os, vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"\n":" "
    );return os;}
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int main(){
char buff[100];
int s = 0;
// 0 ?
// 1 visit
// 2 wall
vector<vector<int>> field(50, vector<int>(50, 0));
int x = 25;
int y = 25;
int dir = 0;
auto update = [&](){
string s(buff);
if(s=="Merry Christmas!") return -1;
if(s=="20151224") return -2;
int d;
sscanf(buff, "%d", &d);
field[x + (d+1)*dx[dir] ][ y + (d+1) * dy[dir] ] = 2;
return d;
};
auto check_foward = [&](){
return field[x + dx[dir] ][y + dy[dir]];
};
auto check_right = [&](){
return field[x + dx[(dir+1)%4]][y + dy[(dir+1)%4]];
};
auto check_left = [&](){
return field[x + dx[(dir+1)%4]][y + dy[(dir+1)%4]];
};
auto go_foward = [&](){
if(field[x + dx[dir]][y + dy[dir]] == 2) return;
puts("F");
x += dx[dir];
y += dy[dir];
gets(buff);
};
auto turn_right = [&](){
puts("R");
dir = (dir+1)%4;
gets(buff);
};
auto turn_left = [&](){
puts("L");
dir = (dir+3)%4;
gets(buff);
};
stack<pair<pair<int,int>,int>> st;
auto move_ = [&](){
vector<vector<pair<int,int>>> last(50, vector<pair<int,int>>(50, {-1,-1}));
queue<pair<int,int>> q;
q.push(st.top().first);
while(q.size()){
auto pos = q.front(); q.pop();
if(pos == st.top().first) break;
//cerr << pos.first << " " << pos.second << " " << dir;
int x_ = pos.first;
int y_ = pos.second;
for(int k__=0; k__<4; k__++){
int new_x = x_+ dx[k__];
int new_y = y_ + dy[k__];
if(field[new_x][new_y] != 1) continue;
//do something
if(last[new_x][new_y] == last[0][0] ){
last[new_x][new_y] = {x_,y_};
q.push({x_,y_});
}
}
}
while(pair<int,int>{x,y} != st.top().first){
auto p = last[x][y];
while(pair<int,int>{x + dx[dir], y + dy[dir]} != p){
turn_right();
}
go_foward();
}
while(pair<pair<int,int>,int>{{x,y},dir} != st.top()){
turn_right();
}
};
gets(buff);
while(true){
int d = update();
if(d==-1) return 0;
if(d==-2){
go_foward();
continue;
}
if(field[x][y] == 0){
field[x][y] = 1;
for(int i=0; i<4; i++){
int z = check_foward();
if(z==0){
st.push({{x,y},dir});
//cerr << x << " " << y << " " << dir;
}
turn_right();
update();
}
}
if(st.top() == pair<pair<int,int>,int>{{x,y}, dir}){
st.pop();
go_foward();
continue;
}else{
move_();
}
//cerr << field << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0