QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#350478#4426. Divided MechanismstudentDLAC ✓2ms3620kbC++142.5kb2024-03-10 19:20:382024-03-10 19:20:39

Judging History

你现在查看的是最新测评结果

  • [2024-03-10 19:20:39]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3620kb
  • [2024-03-10 19:20:38]
  • 提交

answer

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define pii pair<int,int>
#define mk make_pair
#define ft first
#define se second
#define pb push_back
#define db double
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 1e18
using namespace std;
#define LOCAL
namespace IO{
    #ifndef LOCAL
        #define SIZE 30000
        char in[SIZE],out[SIZE],*p1=in,*p2=in,*p3=out;
        #define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,SIZE,stdin),p1==p2)?EOF:*p1++)
        #define flush() (fwrite(p3=out,1,SIZE,stdout))
        #define putchar(ch) (p3==out+SIZE&&flush(),*p3++=(ch))
        class Flush{public:~Flush(){fwrite(out,1,p3-out,stdout);}}_;
    #endif
    template<typename type>
    inline void read(type &x){
        x=0;bool flag=0;char ch=getchar();
        while(ch<'0'||ch>'9') flag^=ch=='-',ch=getchar();
        while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        flag?x=-x:0;
    }
    template<typename type>
    inline void write(type x,char ch=0){
        x<0?x=-x,putchar('-'):0;static short Stack[50],top=0;
        do Stack[++top]=x%10,x/=10;while(x);
        while(top) putchar(Stack[top--]|48);
        if(ch) putchar(ch);
    }
}
using namespace IO;
int n,m,Q;
int dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
bool done,vis[15][15];
vector<pii> B;
bool occupied(int x,int y){
    return x>0&&x<=n&&y>0&&y<=m&&vis[x][y];
}
void solve(){
    read(n),read(m),read(Q);
    done=0;
    B.clear();
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++){
        char mp[15];
        scanf("%s",mp+1);
        for(int j=1;j<=m;j++){
            if(mp[j]=='A') vis[i][j]=1;
            if(mp[j]=='B') B.pb(mk(i,j));
        }
    }
    char opr[105];
    scanf("%s",opr+1);
    for(int i=1;i<=Q;i++){
        if(done) continue;
        int flag=1,com;
        if(opr[i]=='N') com=0;
        else if(opr[i]=='S') com=1;
        else if(opr[i]=='W') com=2;
        else com=3;
        for(int j=1;j<=20;j++){
            int ff=1;
            for(auto tt:B){
                if(occupied(tt.ft+dx[com],tt.se+dy[com])){ff=0;break;}
            }
            if(!ff){flag=0;break;}
            else{
                for(auto &tt:B){
                    tt.ft+=dx[com],tt.se+=dy[com];
                }
            }
        }
        done=flag;
    }
    puts(done?"TAK":"NIE");
}
int main(){
    int T;read(T);
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3620kb

input:

1000
10 9 4
AA...AAAA
A......AA
A..BBB..A
A...B...A
A...B...A
AA..BBAAA
A..BB...A
A......AA
A...AAAAA
AAAAAAAAA
WSEN
9 10 4
AAAAAAAAAA
A...A....A
A.........
A..B...B..
AA.BBBBB..
AA..B..B.A
AA..A....A
AAA.A...AA
AAAAAAAAAA
ESNE
9 10 7
AAAAAAAAAA
A...A....A
A.........
A..B...B..
AA.BBBBB..
AA..B..B.A...

output:

TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
NIE
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
TAK
...

result:

ok 1000 lines

Extra Test:

score: 0
Extra Test Passed