QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#525086 | #7516. Robot Experiment | mhw# | RE | 0ms | 0kb | C++20 | 1.8kb | 2024-08-20 12:28:37 | 2024-08-20 12:28:37 |
answer
#include<bits/stdc++.h>
#define ll long long
#define pii make_pair
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=b;i>=a;--i)
const ll inf = 1145141919810;
using namespace std;
inline ll read(){
ll x=0,f=1;
char c=getchar();
while (c<'0' || c>'9'){
if (c=='-') f=-1;
c=getchar();
}
while (c>='0' && c<='9'){
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
inline void print(ll x){
if(x < 0) putchar('-'), x = -x;
if(x > 9) print(x / 10);
putchar(x % 10 + '0');
return ;
}
inline void pprint(ll x){print(x); puts("");}
int mp[200][200];
int n;
char s[100];
map<pair<int, int>, int> q;
int add(int x, int y){
mp[x + 50][y + 50] = 1;
}
int del(int x, int y){
mp[x + 50][y + 50] = 0;
}
int vis(int x, int y){
mp[x + 50][y + 50] = 2;
}
int pm(int x, int y){
return mp[x + 50][y + 50];
}
void dfs(int x, int y, int k){
// cout << x << " " << y << endl;
if(k == n + 1){
q[pii(x, y)] = 1;
// puts("END");
return ;
}
int tx, ty;
if(s[k] == 'U'){
tx = x;
ty = y + 1;
}
if(s[k] == 'D'){
tx = x;
ty = y - 1;
}
if(s[k] == 'L'){
tx = x - 1;
ty = y;
}
if(s[k] == 'R'){
tx = x + 1;
ty = y;
}
// cout << tx << " " << ty << endl;
int st = pm(tx, ty);
if(st == 0){
add(tx, ty);
dfs(x, y, k + 1);
del(tx, ty);
vis(tx, ty);
dfs(tx, ty, k + 1);
del(tx, ty);
}else{
if(st == 1){//ǰ��Ź�ʯͷ
dfs(x, y, k + 1);
}else{//ǰ���߹�
dfs(tx, ty, k + 1);
}
}
}
vector<pair<int, int> > v;
int main(){
n = read();
scanf("%s", s + 1);
vis(0, 0);
dfs(0, 0, 1);
for(auto x:q){
v.push_back(x.first);
}
sort(v.begin(), v.end());
pprint(v.size());
for(auto x:v){
printf("%d %d\n", x.first, x.second);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 RU