QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#542031#8935. Puzzle: Easy as Scrabbleucup-team4435#WA 2ms11636kbC++203.7kb2024-08-31 22:11:082024-08-31 22:11:09

Judging History

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

  • [2024-08-31 22:11:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11636kb
  • [2024-08-31 22:11:08]
  • 提交

answer

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define each(x, a) for (auto &x : a)
#define ar array
#define vec vector
#define range(i, n) rep(i, n)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;

int Bit(int mask, int b) { return (mask >> b) & 1; }

template<class T>
bool ckmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool ckmax(T &a, const T &b) {
    if (b > a) {
        a = b;
        return true;
    }
    return false;
}

// [l, r)
template<typename T, typename F>
T FindFirstTrue(T l, T r, const F &predicat) {
    --l;
    while (r - l > 1) {
        T mid = l + (r - l) / 2;
        if (predicat(mid)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    return r;
}


template<typename T, typename F>
T FindLastFalse(T l, T r, const F &predicat) {
    return FindFirstTrue(l, r, predicat) - 1;
}

const ll INF = 2e18;
const int INFi = 1e9;

const int LG = 49;
const int N = 1e3 + 5;

struct State {
    int direction;
    char value;

    State(int d = -1, char val = '.') : direction(d), value(val) {}
};

State a[N][N];
// RDLU
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int n, m;

bool ok = true;

void Go(int i, int j, State who) {
    if (i > n || j > m || i <= 0 || j <= 0) {
        ok = false;
        return;
    }
    if (a[i][j].direction == -1) {
        a[i][j] = who;
        return;
    }
    State emp;
    if (a[i][j].direction != -2) {
        swap(a[i][j], emp);
        a[i][j].direction = -2;
    }
    Go(i + dx[who.direction], j + dy[who.direction], who);
    if (emp.direction >= 0) Go(i + dx[emp.direction], j + dy[emp.direction], emp);
}

void solve() {
    cin >> n >> m;
    string s;
    cin >> s;
    for (int i = 1; i <= m; ++i) {
        if (s[i] != '.') {
            Go(1, i, State(1, s[i]));
        }
    }
    for(int row = 1; row <= n; ++row) {
        cin >> s;
        if (s[0] != '.') {
            Go(row, 1, State(0, s[0]));
        }
        if (s[m+1] != '.') {
            Go(row, m, State(2, s[m+1]));
        }
        for(int i = 1; i <= m; ++i) {
            if (s[i] == 'x' && a[row][i].direction != -2) {
                if (a[row][i].direction == -1) {
                    a[row][i].direction = -2;
                } else {
                    State who(-2);
                    swap(who, a[row][i]);
                    Go(row + dx[who.direction], i + dy[who.direction], who);
                }
            }
        }
    }

    cin >> s;
    for (int i = 1; i <= m; ++i) {
        if (s[i] != '.') {
            Go(n, i, State(3, s[i]));
        }
    }
    if (!ok) {
        cout << "NO\n";
        return;
    }
    cout << "YES\n";
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            cout << a[i][j].value;
        }
        cout << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(12) << fixed;
    int t = 1;
//    cin >> t;
    rep(i, t) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11436kb

input:

5 5
.CBA...
....x..
..x...C
A.....B
B..x..A
C......
.......

output:

YES
CBA..
....C
A...B
B...A
C....

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 2ms
memory: 11636kb

input:

1 2
....
Nx..
..O.

output:

NO

result:

ok Correct.

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 11500kb

input:

5 5
.U.N.X.
U....xX
Ox....X
M...xxN
Vx....S
Ix.x..X
..IBHX.

output:

NO

result:

wrong answer Jury has answer but participant has not.