QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#648797 | #3125. Dango Maker | Dimash | 0 | 4ms | 9788kb | C++23 | 2.1kb | 2024-10-17 20:26:52 | 2024-10-17 20:26:52 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3 + 12, MOD = 998244353, M = 3e6 + 12;
char a[N][N];
int n, m, res = 0, res1 = 0, v[N][N], it = 1, h[N][N];
vector<int> g[M];
void add(int x, int y) {
g[x].push_back(y);
g[y].push_back(x);
}
bool vis[N * N];
pair<int, int> dfs(int v){
vis[v] = 1;
int dp1 = 1, dp0 = 0;
for(int to:g[v]) {
if(vis[to]) continue;
auto [d0, d1] = dfs(to);
dp0 += max(d0, d1);
dp1 += d0;
}
return {dp0, dp1};
}
void test() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] == 'G' && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
h[i][j - 1] = it++;
}
if(a[i][j] == 'G' && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
v[i - 1][j] = it++;
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(a[i][j] == 'G' && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
if(v[i][j - 1]) {
add(v[i][j - 1], h[i][j - 1]);
}
if(v[i - 1][j]) {
add(v[i - 1][j], h[i][j - 1]);
}
if(v[i - 2][j + 1]) {
add(v[i - 2][j + 1], h[i][j - 1]);
}
}
}
}
for(int i = 1; i < it; i++) {
sort(g[i].begin(), g[i].end());
g[i].resize(unique(g[i].begin(), g[i].end()) - g[i].begin());
}
for(int i = 1; i < it; i++) {
if(!vis[i]) {
dfs(i);
auto [x, y] = dfs(i);
res += max(x, y);
}
}
cout << res << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 13
Accepted
time: 4ms
memory: 5620kb
input:
1 1 G
output:
0
result:
ok single line: '0'
Test #2:
score: 13
Accepted
time: 4ms
memory: 5720kb
input:
1 2 RG
output:
0
result:
ok single line: '0'
Test #3:
score: 13
Accepted
time: 4ms
memory: 5632kb
input:
2 1 W R
output:
0
result:
ok single line: '0'
Test #4:
score: 13
Accepted
time: 4ms
memory: 5644kb
input:
3 2 WW RW WR
output:
0
result:
ok single line: '0'
Test #5:
score: 13
Accepted
time: 4ms
memory: 5764kb
input:
4 4 GRRW GWWR WWWW RGRG
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Wrong Answer
time: 4ms
memory: 9788kb
input:
4 4 RGRR RRRG GRGW RGWW
output:
1
result:
wrong answer 1st lines differ - expected: '2', found: '1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%