QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244279#7699. PearlsSolitaryDreamWA 1ms3512kbC++172.0kb2023-11-08 22:37:072023-11-08 22:37:07

Judging History

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

  • [2023-11-08 22:37:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3512kb
  • [2023-11-08 22:37:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 65;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
string d2ch = "NESW";
vector<int> order = {1, 0, 2, 3};
int k, n, m;
string s;
int sx, sy;

string ans;
int ty[N];
int vis[N][N], px[N], py[N];
inline int GetDir(int x, int y, int u, int v) {
    if (x == u) return v < y ? 1 : 3;
    return u < x ? 0 : 2;
}
inline int Check(int ps) {
    // int d1 = GetDir(px[ps], py[ps], px[(ps + 1) % k], py[(ps + 1) % k]);
    // int d2 = GetDir(px[ps], py[ps], px[(ps - 1 + k) % k], py[(ps - 1 + k) % k]);
    if (s[ps] == '.') return !ty[ps];
    if (s[ps] == 'W') return !ty[ps] && (ty[(ps + 1) % k] || ty[(ps + k - 1) % k]);
    return ty[ps] && !ty[(ps + 1) % k] && !ty[(ps + k - 1) % k];
}
inline void Dfs(int x, int y, int ps) {
    px[ps] = x; py[ps] = y;
    if (ps == k - 1) {
        // cerr << ans << endl;
        // cerr << x << ' ' << y << endl;
        if (abs(x - sx) + abs(y - sy) != 1) return;
        ans[ps] = d2ch[GetDir(x, y, sx, sy)];
        ty[ps] = ((GetDir(x, y, sx, sy) - GetDir(x, y, px[ps - 1], py[ps - 1]) + 4) % 4 & 1);
        ty[0] = ((GetDir(px[0], py[0], px[1], py[1]) - GetDir(px[0], px[0], x, y) + 4) % 4 & 1);
        if (Check(ps) && Check(ps - 1) && Check(0) && Check(1)) {
            cout << ans << endl;
            exit(0);
        }
        return;
    }
    vis[x][y] = 1;
    for (auto d : order) {
        int nx = x + dx[d], ny = y + dy[d];
        if (nx > 0 && ny > 0 && nx <= n && ny <= m && !vis[nx][ny]) {
            ans[ps] = d2ch[d];
            if (ps >= 1) ty[ps] = (d - GetDir(x, y, px[ps - 1], py[ps - 1]) + 4) % 4 & 1;   
            if (ps >= 3 && !Check(ps - 1)) continue;
            Dfs(nx, ny, ps + 1);
        }
    }
    vis[x][y] = 0;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> k >> n >> m;
    cin >> s;
    cin >> sx >> sy;
    ans.resize(k);
    Dfs(sx, sy, 0);
    cout << "impossible\n";
    return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3456kb

input:

16 5 6
B.B.B.BW.WB..WB.
3 1

output:

EENNEESSSSWWWWNN

result:

ok single line: 'EENNEESSSSWWWWNN'

Test #2:

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

input:

6 5 5
W..B.B
3 3

output:

impossible

result:

ok single line: 'impossible'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3476kb

input:

8 5 5
B.B.B.B.
5 5

output:

NNWWSSEW

result:

wrong answer 1st lines differ - expected: 'NNWWSSEE', found: 'NNWWSSEW'