QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135189#4426. Divided MechanismSommohito#AC ✓56ms3476kbC++203.0kb2023-08-05 12:38:222023-08-05 12:38:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 12:38:25]
  • 评测
  • 测评结果:AC
  • 用时:56ms
  • 内存:3476kb
  • [2023-08-05 12:38:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#ifdef APURBA
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
#define ALL(x) x.begin(),x.end()

int n,m,q;
string s[30];
string Q;
bool split;
int g[30][30];

int get(int i,int j)
{
    if(i<0||i>=30||j<0||j>=30) return 1e9;
    else
        return g[i][j];
}

void process(char c)
{
//    for(int i=0;i<30;i++)
//        cout<<s[i]<<"\n";
//    cout<<"\n";
    memset(g,0,sizeof g);
    if(c=='N')
    {
        for(int i=0;i<30;i++) {
            for(int j=0;j<30;j++) {
                if(s[i][j]=='A') g[i][j]=0;
                else g[i][j]=1+get(i-1,j);
            }
        }
    }
    if(c=='S')
    {
        for(int i=29;i>=0;i--) {
            for(int j=0;j<30;j++) {
                if(s[i][j]=='A') g[i][j]=0;
                else g[i][j]=1+get(i+1,j);
            }
        }
    }
    if(c=='E')
    {
        for(int i=0;i<30;i++) {
            for(int j=29;j>=0;j--) {
                if(s[i][j]=='A') g[i][j]=0;
                else g[i][j]=1+get(i,j+1);
            }
        }
    }
    if(c=='W')
    {
        for(int i=0;i<30;i++) {
            for(int j=0;j<30;j++) {
                if(s[i][j]=='A') g[i][j]=0;
                else g[i][j]=1+get(i,j-1);
            }
        }
    }
    int mn=1e9;
    for(int i=0;i<30;i++)
    {
        for(int j=0;j<30;j++)
        {
            if(s[i][j]=='B')
            {
                mn=min(mn,g[i][j]);
            }
        }
    }
//    debug(c,mn);
    mn--;
    if(mn>=1e8)
    {
        split=true;
        return;
    }
    string t[30];
    for(int i=0;i<30;i++)
    {
        t[i].resize(30,'.');
    }

    for(int i=0;i<30;i++)
    {
        for(int j=0;j<30;j++)
        {
            int a=i,b=j;
            if(c=='N') a-=mn;
            else if(c=='S') a+=mn;
            else if(c=='E') b+=mn;
            else b-=mn;



            if(s[i][j]=='B') t[a][b]='B',assert(a>=0&&a<30&&b>=0&&b<30);
            else if(s[i][j]=='A') t[i][j]='A';

        }
    }
    for(int i=0;i<30;i++)
        swap(s[i],t[i]);

}

void TEST_CASES()
{
    split=false;
    cin>>n>>m>>q;
    for(int i=0;i<30;i++)
    {
        s[i].resize(30);
        for(int j=0;j<30;j++)
        {
            s[i][j]='.';
        }
    }
    for(int i=0;i<n;i++)
    {
        string temp; cin>>temp;
        for(int j=0;j<m;j++)
        {
            s[i+10][j+10]=temp[j];
        }
//        debug(i+10,s[i+10]);
    }
    cin>>Q;
    for(int i=0;i<q;i++)
    {
        process(Q[i]);
        if(split)
        {
            cout<<"TAK\n";
            return;
        }
    }
    cout<<"NIE\n";
}


/*
*/

int32_t main()
{
//#ifndef APURBA
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//#endif
    //freopen("input.txt","r",stdin);
    //freopen("out1.txt","w",stdout);
    int t=1;
    cin>>t;
    while(t--)
    {
        TEST_CASES();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 56ms
memory: 3476kb

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