QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350626#4432. Jungle TrailstudentDLWA 282ms11820kbC++143.2kb2024-03-10 22:00:052024-03-10 22:00:05

Judging History

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

  • [2024-03-10 22:00:05]
  • 评测
  • 测评结果:WA
  • 用时:282ms
  • 内存:11820kb
  • [2024-03-10 22:00:05]
  • 提交

answer

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#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;
#define M 2005
int n,m,d,dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};
bool vis[M][M];
char mp[M][M],row[M],col[M],opr[M<<1];
bool check(){
    queue<pii> q;
    vis[1][1]=1,q.push(mk(1,1));
    while(!q.empty()){
        pii u=q.front();q.pop();
        for(int i=0;i<4;i++){
            int nx=u.ft+dx[i],ny=u.se+dy[i];
            if(nx>0&&nx<=n&&nx>0&&ny<=m&&!vis[nx][ny]){
                if(nx==n&&ny==m) return 1;
                vis[nx][ny]=1;q.push(mk(nx,ny));
            }
        }
    }
    return 0;
}
void flipRow(int rr){
    if(row[rr]=='N') row[rr]='T';
    else row[rr]='N';
    for(int i=1;i<=m;i++) mp[rr][i]=mp[rr][i]=='O'?'@':'O';
}
void flipCol(int cc){
    if(col[cc]=='N') col[cc]='T';
    else col[cc]='N';
    for(int i=1;i<=n;i++) mp[i][cc]=mp[i][cc]=='O'?'@':'O';
}
bool dfs(int x,int y){
    if(x==n&&y==m) return 1;
    if(x==n){
        if(mp[x][y+1]=='#') return 0;
        if(mp[x][y+1]=='@') flipCol(y+1);
        opr[++d]='P';
        return dfs(x,y+1);
    }
    if(y==m){
        if(mp[x+1][y]) return 0;
        if(mp[x+1][y]=='@') flipRow(x+1);
        opr[++d]='D';
        return dfs(x+1,y);
    }
    if(mp[x][y+1]!='#'){
        if(mp[x][y+1]=='@') flipCol(y+1);
        opr[++d]='P';
        if(!dfs(x,y+1)) flipCol(y+1),d--;
        else return 1;
    }
    if(mp[x+1][y]=='@') flipRow(x+1);
    opr[++d]='D';
    if(!dfs(x+1,y)){
        flipCol(y+1),d--;
        return 0;
    }
    else return 1;
}
void solve(){
    read(n),read(m),d=0;
    for(int i=1;i<=n;i++) row[i]='N';
    for(int i=1;i<=m;i++) col[i]='N';
    for(int i=1;i<=n;i++){
        scanf("%s",mp[i]+1);
        for(int j=1;j<=m;j++) vis[i][j]=0;
    }
    if(!check()) puts("NIE");
    else{
        puts("TAK");
        dfs(1,1);
        printf("%s\n%s\n%s\n",row+1,col+1,opr+1);
    }
}
int main(){
    int T;read(T);
    while(T--) solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 282ms
memory: 11820kb

input:

486
4 5
..#..
@@O@@
##@#O
..@.@
2 2
OO
OO
2 2
@@
@@
2 2
@@
#@
2 2
@O
#@
2 2
@@
OO
2 2
O#
@O
2 2
@#
#@
2 2
@.
.@
2 2
@#
.O
2 2
OO
.O
10 10
@O@O#O@@@#
OO#@#@@#OO
#@#@#O##O@
OO##@@O#@O
O##@@#@O#@
OO@OO@@@O@
@O#@#@O#@O
@OOOOO@##.
O@OOO##O@@
OO@@OOOO#@
10 10
@@#OOO#O@@
#@@OO@@.O@
#.O@@O#@@O
OO@@#O@#O@
.#...

output:

TAK
NTNN
NNTNT
PDPPDDP
TAK
NNNN
NNTNT
DPPPDDP
TAK
NTNN
NNTNT
DPPPDDP
TAK
NNNN
NTTNT
DPPPDDP
TAK
NNNN
NTTNT
DPPPDDP
TAK
NNNN
NNTNT
DPPPDDP
TAK
NTNN
NTTNT
DPPPDDP
TAK
NNNN
NTTNT
DPPPDDP
TAK
NNNN
NTTNT
DPPPDDP
TAK
NNNN
NNTNT
DPPPDDP
TAK
NNNN
NNTNT
DPPPDDP
TAK
NTTNNTNNNN
NNTNNNNNTT
PPPDPPPPPDDDDDDDDP
TA...

result:

wrong answer you hit a blocked square (test case 1)