QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#663456#2345. Karel the RobotXY_ElevenAC ✓4880ms53512kbC++237.7kb2024-10-21 15:41:382024-10-21 15:41:38

Judging History

This is the latest submission verdict.

  • [2024-10-21 15:41:38]
  • Judged
  • Verdict: AC
  • Time: 4880ms
  • Memory: 53512kb
  • [2024-10-21 15:41:38]
  • Submitted

answer

#include <bits/stdc++.h>
// #include <windows.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int>
#define pli pair<long long,int>
#define vct vector
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{

}
cint D=42,K=26;
int d1,d2,Q1,Q2;
bitset <D> b[D];
string fun[K];
const char ch[]={'n','w','s','e'};
int gt_dir(char c)
{
    For_(i,0,4) if(c==ch[i])
        return i;
    return (-1);
}
cint dx[]={-1,0,1,0},dy[]={0,-1,0,1};
cint L=105;
gp_hash_table <ULL,array<int,3>> mp[D][D][4];
gp_hash_table <ULL,bool> vis[D][D][4];
void chg(int &x,int &y,int &dir,array <int,3> t)
{
    x=t[0],y=t[1],dir=t[2];
}
bool chk(int &x,int &y,int &dir,char c)
{
    if(c!='b') return (dir==gt_dir(c));
    return (b[x+dx[dir]][y+dy[dir]]);
}
ULL xor_shift(ULL x)
{
    x^=x<<35;
    x^=x>>16;
    x^=x<<17;
    x^=x>>13;
    return x;
}
void op(int &x,int &y,int &dir,char c)
{
    if(c=='m')
    {
        int lx=x+dx[dir],ly=y+dy[dir];
        if(!b[lx][ly]) x=lx,y=ly;
    }
    else if(c=='l')
        dir=((dir==3)?0:(dir+1));
    else assert(0);
}
array <int,3> solve(int x,int y,int dir,string s)
{
    if(s.empty()) return {x,y,dir};
    // printf("[%d,%d]:%d\n> ",x,y,dir);
    int len=sz(s);
    // For_(i,0,len) printf("%c",s[i]); printf("\n");
    // assert(dir!=-1);
    ULL hs=0; for(auto i:s) hs=xor_shift(hs+i);
    // printf("hs=%lld\n",hs);
    if(mp[x][y][dir].find(hs)!=mp[x][y][dir].end()) return mp[x][y][dir][hs];
    if(vis[x][y][dir][hs]) return {0,0,-1};
    // printf("> first\n");
    int xx=x,yy=y,dd=dir;
    vis[x][y][dir][hs]=true;
    vct <int> mat; mat.resize(len);
    stack <int> st;
    For_(i,0,len)
    {
        if(s[i]=='(') st.push(i);
        else if(s[i]==')')
        {
            mat[st.top()]=i;
            st.pop();
        }
    }
    for(int l=0,r;l<len;l=r+1)
    {
        r=l;
        if(s[l]>='A'&&s[l]<='Z')
        {
            chg(x,y,dir,solve(x,y,dir,fun[s[l]-'A']));
            // printf("????\n");
        }
        else if(s[l]=='i')
        {
            int t1=l+2,t2=mat[t1];
            int t3=t2+1,t4=mat[t3];
            if(chk(x,y,dir,s[l+1]))
            {
                // printf("to A\n");
                chg(x,y,dir,solve(x,y,dir,s.substr(t1+1,t2-t1-1)));
            }
            else
            {
                // printf("to B\n");
                chg(x,y,dir,solve(x,y,dir,s.substr(t3+1,t4-t3-1)));
            }
            r=t4;
        }
        else if(s[l]=='u')
        {
            int t1=l+2,t2=mat[t1];
            // printf("(%d,%d)\n",t1,t2);
            set <array<int,3>> vis2;
            auto s2=s.substr(t1+1,t2-t1-1);
            while(!chk(x,y,dir,s[l+1]))
            {
                // printf("->\n");
                if(vis2.count({x,y,dir}))
                {
                    vis[xx][yy][dd][hs]=false;
                    return (mp[xx][yy][dd][hs]=(array<int,3>){0,0,-1});
                }
                vis2.insert({x,y,dir});
                chg(x,y,dir,solve(x,y,dir,s2));
                if(!~dir)
                {
                    vis[xx][yy][dd][hs]=false;
                    return (mp[xx][yy][dd][hs]=(array<int,3>){0,0,-1});
                }
            }
            r=t2;
        }
        else
        {
            // printf("???\n");
            op(x,y,dir,s[l]);
            // printf("> %d,%d\n",x,y);
            r=l;
        }
        // printf("> > %d,%d,%d\n",x,y,dir);
        if(!~dir)
        {
            vis[xx][yy][dd][hs]=false;
            return (mp[xx][yy][dd][hs]=(array<int,3>){0,0,-1});
        }
    }
    vis[xx][yy][dd][hs]=false;
    return (mp[xx][yy][dd][hs]={x,y,dir});
}
void main_solve()
{
    cin>>d1>>d2>>Q1>>Q2;
    For(i,1,d1)
    {
        string str;
        cin>>str;
        For(j,1,d2) b[i][j]=(int)(str[j-1]=='#');
    }
    For(j,0,d2+1) b[0][j]=b[d1+1][j]=1;
    For(i,0,d1+1) b[i][0]=b[i][d2+1]=1;
    while(Q1--)
    {
        string str; cin>>str;
        fun[str[0]-'A']=str.substr(2);
    }
    while(Q2--)
    {
        int x,y; string c,str; cin>>x>>y>>c>>str;
        int dir=gt_dir(c[0]);
        auto [lx,ly,ld]=solve(x,y,dir,str);
        if(~ld) printf("%d %d %c\n",lx,ly,ch[ld]);
        else printf("inf\n");
    }
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    // freopen("ex_A3.in","r",stdin);
    // freopen("out.txt","w",stdout);
    // srand(time(NULL));
    main_init();
    // int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*

*/

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 8612kb

Test #2:

score: 0
Accepted
time: 3ms
memory: 8900kb

Test #3:

score: 0
Accepted
time: 3ms
memory: 8608kb

Test #4:

score: 0
Accepted
time: 0ms
memory: 8664kb

Test #5:

score: 0
Accepted
time: 3ms
memory: 8668kb

Test #6:

score: 0
Accepted
time: 12ms
memory: 8744kb

Test #7:

score: 0
Accepted
time: 340ms
memory: 10180kb

Test #8:

score: 0
Accepted
time: 21ms
memory: 17252kb

Test #9:

score: 0
Accepted
time: 4880ms
memory: 30556kb

Test #10:

score: 0
Accepted
time: 0ms
memory: 8892kb

Test #11:

score: 0
Accepted
time: 0ms
memory: 8672kb

Test #12:

score: 0
Accepted
time: 3ms
memory: 8624kb

Test #13:

score: 0
Accepted
time: 0ms
memory: 8604kb

Test #14:

score: 0
Accepted
time: 3ms
memory: 8672kb

Test #15:

score: 0
Accepted
time: 0ms
memory: 9072kb

Test #16:

score: 0
Accepted
time: 6ms
memory: 10236kb

Test #17:

score: 0
Accepted
time: 4649ms
memory: 29928kb

Test #18:

score: 0
Accepted
time: 4846ms
memory: 30380kb

Test #19:

score: 0
Accepted
time: 28ms
memory: 12476kb

Test #20:

score: 0
Accepted
time: 316ms
memory: 53512kb