QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#548842#4426. Divided Mechanismarnold518#AC ✓29ms3576kbC++173.6kb2024-09-05 21:28:122024-09-05 21:28:13

Judging History

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

  • [2024-09-05 21:28:13]
  • 评测
  • 测评结果:AC
  • 用时:29ms
  • 内存:3576kb
  • [2024-09-05 21:28:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 30;
const int INF = 1e8;

int N, M, K;
int A[MAXN+10][MAXN+10];
string B;

int main2()
{
    cin >> N >> M >> K;
    for(int i=1; i<=N; i++)
    {
        string S;
        cin >> S;
        S="?"+S;
        for(int j=1; j<=M; j++)
        {
            if(S[j]=='A') A[i+N][j+M]=1;
            if(S[j]=='B') A[i+N][j+M]=2;
        }
    }
    cin >> B;

    for(auto c : B)
    {
        if(c=='N')
        {
            int val=INF;
            for(int j=1; j<=M*3; j++)
            {
                int bef=-INF;
                for(int i=1; i<=N*3; i++)
                {
                    if(A[i][j]==1) bef=i;
                    else if(A[i][j]==2) val=min(val, i-bef-1);
                }
            }
            if(val==INF) return !(cout << "TAK\n");

            for(int j=1; j<=M*3; j++) for(int i=1; i<=N*3; i++)
            {
                if(A[i][j]==2)
                {
                    A[i][j]=0;
                    A[i-val][j]=2;
                }
            }
        }
        else if(c=='W')
        {
            int val=INF;
            for(int i=1; i<=N*3; i++)
            {
                int bef=-INF;
                for(int j=1; j<=M*3; j++)
                {
                    if(A[i][j]==1) bef=j;
                    else if(A[i][j]==2) val=min(val, j-bef-1);
                }
            }
            if(val==INF) return !(cout << "TAK\n");

            for(int i=1; i<=N*3; i++) for(int j=1; j<=M*3; j++)
            {
                if(A[i][j]==2)
                {
                    A[i][j]=0;
                    A[i][j-val]=2;
                }
            }
        }
        else if(c=='S')
        {
            int val=INF;
            for(int j=M*3; j>=1; j--)
            {
                int bef=INF*2;
                for(int i=N*3; i>=1; i--)
                {
                    if(A[i][j]==1) bef=i;
                    else if(A[i][j]==2) val=min(val, bef-i-1);
                }
            }
            if(val==INF) return !(cout << "TAK\n");

            for(int j=M*3; j>=1; j--) for(int i=N*3; i>=1; i--)
            {
                if(A[i][j]==2)
                {
                    A[i][j]=0;
                    A[i+val][j]=2;
                }
            }
        }
        else if(c=='E')
        {
            int val=INF;
            for(int i=N*3; i>=1; i--)
            {
                int bef=INF*2;
                for(int j=M*3; j>=1; j--)
                {
                    if(A[i][j]==1) bef=j;
                    else if(A[i][j]==2) val=min(val, bef-j-1);
                }
            }
            if(val==INF) return !(cout << "TAK\n");

            for(int j=M*3; j>=1; j--) for(int i=N*3; i>=1; i--)
            {
                if(A[i][j]==2)
                {
                    A[i][j]=0;
                    A[i][j+val]=2;
                }
            }
        }

        // for(int i=1; i<=N*3; i++)
        // {
        //     for(int j=1; j<=M*3; j++)
        //     {
        //         if(A[i][j]==1) printf("A");
        //         else if(A[i][j]==2) printf("B");
        //         else printf(" ");
        //     }
        //     printf("\n");
        // }
        // printf("\n");
    }

    cout << "NIE\n";

    return 0;
}

void reset()
{
    for(int i=1; i<=3*N; i++) for(int j=1; j<=3*M; j++) A[i][j]=0;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int TC;
    cin >> TC;
    while(TC--)
    {
        main2();
        reset();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 29ms
memory: 3576kb

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