QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#835837#9926. Flipping Pathsucup-team055#RE 0ms3624kbC++204.1kb2024-12-28 14:58:402024-12-28 14:58:44

Judging History

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

  • [2024-12-28 14:58:44]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3624kb
  • [2024-12-28 14:58:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}



void solve();
// CITRUS CURIO CITY / FREDERIC
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    int N, M;
    cin >> N >> M;
    vector p(N, vector<int>(M));
    vector A(2, vector<int>(N + M - 1));
    rep(i, 0, N) rep(j, 0, M){
        char c;
        cin >> c;
        if (c == 'B') p[i][j]++;
        A[p[i][j]][i + j] ^= 1;
    }
    // fin is all 0
    int ok = 0;
    rep(i, 0, 2){
        if (vec_min(A[i]) == vec_max(A[i])){
            if (i == 0){
                rep(a, 0, N) rep(j, 0, M) p[a][j] ^= 1;
            }
            ok = 1;
            break;
        }
    }
    if (ok == 0){
        cout << "NO\n";
        return;
    }
    vector<string> ans;
    int x = 0, y = 0;
    string tmp;
    p[x][y] ^= 1;
    auto addx = [&](int a = 1) -> void {
        x++;
        p[x][y] ^= a;
        tmp += 'D';
    };
    auto addy = [&](int a = 1) -> void {
        y++;
        p[x][y] ^= a;
        tmp += 'R';
    };
    auto pus = [&]() -> void {
        ans.push_back(tmp);
        tmp = "";
    };
    string base;
    while (x != N - 1 || y != M - 1){
        if (x == N - 1) addy(0);
        else if (y == M - 1) addx(0);
        else if (x == y) addy(0);
        else addx(0);
    }
    base = tmp;
    tmp = "";
    // diff = x - y
    for (int diff = N - 1; diff > 0; diff--){
        x = 0, y = 0;
        while (x != N - 1 || y != M - 1){
            if (x == N - 1) addy();
            else if (y == M - 1) addx();
            else if (x - y == diff) addy();
            else if (x - y < diff - 1) addx();
            else if (p[x + 1][y] == 1) addx();
            else addy();
        }
        pus();
    }
    for (int diff = 1 - M; diff < -1; diff++){
        x = 0, y = 0;
        while (x != N - 1 || y != M - 1){
            if (x == N - 1) addy();
            else if (y == M - 1) addx();
            else if (x - y == diff) addx();
            else if (x - y > diff + 1) addy();
            else if (p[x + 1][y] == 1) addy();
            else addx();
        }
        pus();
    }
    if (p[0][0]){
        ans.push_back(base);
        x = 0, y = 0;
        p[0][0] ^= 1;
        for (auto c : base){
            if (c == 'D') x++;
            else y++;
            p[x][y] ^= 1;
        }
    }
    cout << "YES\n";
    cout << ans.size() << "\n";
    for (auto z : ans) cout << z << "\n";
    rep(i, 0, N) rep(j, 0, M) assert(p[i][j] == 0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
3 3
WBB
BWB
BBW
1 5
WWWWW
2 2
BB
BB
4 1
W
B
B
W

output:

YES
4
DDRR
RDRD
RRDD
RDRD
YES
3
RRRR
RRRR
RRRR
YES
2
RD
RD
NO

result:

ok ok (4 test cases)

Test #2:

score: -100
Runtime Error

input:

323
1 2
BB
1 2
BW
1 2
WB
1 2
WW
2 1
B
B
2 1
B
W
2 1
W
B
2 1
W
W
1 3
BBB
1 3
BBW
1 3
BWB
1 3
BWW
1 3
WBB
1 3
WBW
1 3
WWB
1 3
WWW
2 2
BB
BB
2 2
BB
BW
2 2
BB
WB
2 2
BB
WW
2 2
BW
BB
2 2
BW
BW
2 2
BW
WB
2 2
BW
WW
2 2
WB
BB
2 2
WB
BW
2 2
WB
WB
2 2
WB
WW
2 2
WW
BB
2 2
WW
BW
2 2
WW
WB
2 2
WW
WW
3 1
B
B
B
3 ...

output:


result: