QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#648810 | #3125. Dango Maker | Dimash | 13 | 40ms | 222876kb | C++17 | 2.1kb | 2024-10-17 20:31:19 | 2024-10-17 20:31:24 |
Judging History
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[N * N];
int s = 0;
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;
++s;
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]) {
s = 0;
auto [x, y] = dfs(i);
res += max(x, y);
assert(s <= 9);
}
}
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: 13
Accepted
Test #1:
score: 13
Accepted
time: 32ms
memory: 220760kb
input:
1 1 G
output:
0
result:
ok single line: '0'
Test #2:
score: 13
Accepted
time: 35ms
memory: 220636kb
input:
1 2 RG
output:
0
result:
ok single line: '0'
Test #3:
score: 13
Accepted
time: 28ms
memory: 220772kb
input:
2 1 W R
output:
0
result:
ok single line: '0'
Test #4:
score: 13
Accepted
time: 24ms
memory: 218640kb
input:
3 2 WW RW WR
output:
0
result:
ok single line: '0'
Test #5:
score: 13
Accepted
time: 31ms
memory: 220828kb
input:
4 4 GRRW GWWR WWWW RGRG
output:
0
result:
ok single line: '0'
Test #6:
score: 13
Accepted
time: 24ms
memory: 222820kb
input:
4 4 RGRR RRRG GRGW RGWW
output:
2
result:
ok single line: '2'
Test #7:
score: 13
Accepted
time: 32ms
memory: 222752kb
input:
4 4 RRGR GRRG WRGW RGWW
output:
3
result:
ok single line: '3'
Test #8:
score: 13
Accepted
time: 40ms
memory: 220756kb
input:
4 4 RGWR GGGW WWGW RWGW
output:
1
result:
ok single line: '1'
Test #9:
score: 13
Accepted
time: 28ms
memory: 220764kb
input:
3 3 RGW GGG WGW
output:
1
result:
ok single line: '1'
Test #10:
score: 13
Accepted
time: 20ms
memory: 220828kb
input:
4 1 W R G W
output:
1
result:
ok single line: '1'
Test #11:
score: 13
Accepted
time: 31ms
memory: 222820kb
input:
4 4 RGWR GWRG WRGW RGWR
output:
3
result:
ok single line: '3'
Test #12:
score: 13
Accepted
time: 28ms
memory: 220780kb
input:
4 4 RWWR GWRG WGGW RGWR
output:
3
result:
ok single line: '3'
Test #13:
score: 13
Accepted
time: 24ms
memory: 222740kb
input:
4 4 RGWR WWRG WRGW RWGR
output:
2
result:
ok single line: '2'
Test #14:
score: 13
Accepted
time: 27ms
memory: 220760kb
input:
4 4 RRRR GGGG WWWW RRRR
output:
4
result:
ok single line: '4'
Test #15:
score: 13
Accepted
time: 28ms
memory: 222876kb
input:
4 4 RRRR GGGR WWWW RRRR
output:
3
result:
ok single line: '3'
Test #16:
score: 13
Accepted
time: 35ms
memory: 222808kb
input:
4 4 RRRR GGGG WWWW RWRR
output:
4
result:
ok single line: '4'
Subtask #2:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Test #17:
score: 20
Accepted
time: 24ms
memory: 222688kb
input:
5 5 RRGRR RGRGW RRWRW RGWGW RWWWW
output:
3
result:
ok single line: '3'
Test #18:
score: 20
Accepted
time: 38ms
memory: 222812kb
input:
6 6 RGWRGW RRRGWR RRWGWR WRRRWG GGGGGW WWWWWW
output:
7
result:
ok single line: '7'
Test #19:
score: 20
Accepted
time: 20ms
memory: 222824kb
input:
7 10 RRRGRGWRGW RGGGWRRGWR RWWWWGRRGG RGWRWWGGGW WWRGWRGWGW RGWWGGRGWW RRGWWWWWWW
output:
14
result:
ok single line: '14'
Test #20:
score: 20
Accepted
time: 32ms
memory: 222824kb
input:
10 8 RGWRRRGW RGWGRRGW WRGWGRGW RGWWRGWW GWRRGWWW WRRGRWRR GRGWGRGG WGWWWRWR RGWRGRGW RRWRGWWW
output:
16
result:
ok single line: '16'
Test #21:
score: 20
Accepted
time: 27ms
memory: 222812kb
input:
10 10 RRRRGWRRGW GRGRGRGGRR RGRGWGRRGR RWWWRRGRGW GRGGGRGWGG WRGWWGGRGW GGGRWWWRRR WWGRGWRRGG WWGWGWGGWW RRGWGRWWWW
output:
16
result:
ok single line: '16'
Test #22:
score: 20
Accepted
time: 19ms
memory: 222812kb
input:
10 10 RRRWRGWRGW GGGGGGRRWG WGWRWWGGGW RRRRRRWRRG GGGGGGRGGR WGWWWWGWGW WRRGWRWRGW RGWGRGWGRW GRWRGWWWGG RGWWGWRGWW
output:
19
result:
ok single line: '19'
Test #23:
score: 20
Accepted
time: 27ms
memory: 222732kb
input:
10 10 WGWGRWWGWR RGGWGRWWGR GWRRRRWWWG RGWRGWRRRG GRRWWGGRGG GGGGRWGRGG RRRGWWWWRW WRRRWRGRGR RGWGRWGRWG WRRWGGGWWW
output:
7
result:
ok single line: '7'
Test #24:
score: 20
Accepted
time: 20ms
memory: 222744kb
input:
10 10 GGRRGRGRWR RRWRGWWRRW WGRWWRRRWG GGWWRWGRGR RGGGRRGWRR WRWWWRWWWW WRWGGGGRRR RWGRGRWGGW GWGWWGWGRR GRWGGGWRWW
output:
2
result:
ok single line: '2'
Test #25:
score: 20
Accepted
time: 24ms
memory: 220696kb
input:
10 1 R G R W G G G R G R
output:
0
result:
ok single line: '0'
Test #26:
score: 20
Accepted
time: 28ms
memory: 220692kb
input:
1 10 GGGRWWGGWW
output:
0
result:
ok single line: '0'
Test #27:
score: 0
Runtime Error
input:
10 10 RGWRGWRGWR GWRGWRGWRG WRGWRGWRGW RGWRGWRGWR GWRGWRGWRG WRGWRGWRGW RGWRRWRGWR GWRGWRGWRG WRGWRGWRGW RGWRGWRGWR
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%