QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#853810 | #9926. Flipping Paths | ucup-team3691# | WA | 1ms | 3716kb | C++20 | 3.6kb | 2025-01-11 19:25:57 | 2025-01-11 19:25:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
int n, m;
bool solve(vector<vector<int>> v) {
if (v[1][1] != v[n][m]) {
return 0;
}
auto v2 = v;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
v2[i][j] = 0;
}
}
if (v[1][1] == 1) {
v2[1][1] = 1;
}
for (int d = 1; d <= n + m - 1; ++d) {
for (int i = 1; i <= n; ++i) {
int j = d - i + 1;
if (j < 1 || j > n) {
continue;
}
if (v[i][j] % 2 != v2[i][j] % 2) {
return 0;
}
if (v[i][j] > 400) {
return 0;
}
if (j + 1 <= m) {
if (i + 1 <= n) {
if (v[i][j + 1] % 2 != v2[i][j + 1] % 2) {
if (v2[i][j] == 0) {
v2[i][j] += 2;
}
v2[i][j + 1] += 1;
v2[i + 1][j] += v2[i][j] - 1;
} else {
v2[i + 1][j] += v2[i][j];
}
} else {
v2[i][j + 1] += v2[i][j];
}
} else if (i + 1 <= n) {
v2[i + 1][j] += v2[i][j];
}
}
}
cout << "YES\n";
// for (int i = 1; i <= n; ++i) {
// for (int j = 1; j <= m; ++j) {
// cout << v2[i][j] << " ";
// }
// cout << "\n";
// }
cout << v2[n][m] << "\n";
while (v2[n][m] > 0) {
int i = n, j = m;
string s;
while (i > 1 || j > 1) {
--v2[i][j];
if (i - 1 >= 1 && v2[i - 1][j] > 0) {
s.push_back('D');
--i;
} else if (j - 1 >= 1 && v2[i][j - 1] > 0) {
s.push_back('R');
--j;
} else if (i - 1 >= 1) {
v2[i - 1][j] += 2;
s.push_back('D');
--i;
} else {
v2[i][j - 1] += 2;
s.push_back('R');
--j;
}
}
--v2[1][1];
reverse(s.begin(), s.end());
cout << s << "\n";
}
return 1;
}
void solve() {
cin >> n >> m;
vector<vector<int>> v(n + 1, vector<int>(m + 1));
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
for (int j = 1; j <= m; ++j) {
v[i][j] = (s[j - 1] == 'W') ? 0 : 1;
}
}
bool ok = solve(v);
if (ok) {
return;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
v[i][j] ^= 1;
}
}
ok = solve(v);
if (!ok) {
cout << "NO\n";
}
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3716kb
input:
4 3 3 WBB BWB BBW 1 5 WWWWW 2 2 BB BB 4 1 W B B W
output:
YES 2 RRDD DDRR YES 0 YES 0 NO
result:
ok ok (4 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3716kb
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:
YES 1 R NO NO YES 0 YES 1 D NO NO YES 0 YES 0 NO YES 0 NO NO YES 0 NO YES 0 YES 0 NO YES 1 RD NO YES 1 DR NO YES 2 RD DR NO NO YES 2 RD DR NO YES 1 DR NO YES 1 RD NO YES 0 YES 1 DD NO NO NO NO NO NO YES 0 YES 0 NO YES 0 NO YES 0 NO YES 0 NO NO YES 0 NO YES 0 NO YES 0 NO YES 0 YES 0 NO NO NO NO NO YE...
result:
wrong answer cell (1,2) contains different color with (1,1) after all ops. (test case 11)