QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465748#3125. Dango Makersnpmrnhlol13 1ms5788kbC++142.5kb2024-07-07 07:29:302024-07-07 07:29:30

Judging History

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

  • [2024-07-07 07:29:30]
  • 评测
  • 测评结果:13
  • 用时:1ms
  • 内存:5788kb
  • [2024-07-07 07:29:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 3e3;
char v[N][N];
bool vis[N][N][2];
bool vis2[N][N];
int ans = 0;
int n,m;
bool ok(int x,int y,int id){
    if(id == 0){
        return 0 <= x && x <= n - 1 && 0 <= y && y <= m - 3 && (!vis[x][y][id]) && v[x][y] == 'R' && v[x][y + 1] == 'G' && v[x][y + 2] == 'W';
    }else{
        return 0 <= x && x <= n - 3 && 0 <= y && y <= m - 1 && (!vis[x][y][id]) && v[x][y] == 'R' && v[x + 1][y] == 'G' && v[x + 2][y] == 'W';
    }
}
void dfs(int x,int y,int id){
    int cnt0 = 0,cnt1 = 0,cnt2 = 0;
    //cout<<"iteration:\n";
    auto dfs2 = [&](auto self, int x, int y, int id) -> void{
        vis[x][y][id] = 1;
        if(id == 0){
            for(int j = 0;j < 3;j++){
                if(!vis2[x][y + j]){
                    vis2[x][y + j] = 1;
                    if(v[x][y + j] == 'R'){
                        cnt0++;
                    }else if(v[x][y + j] == 'G'){
                        cnt1++;
                    }else{
                        cnt2++;
                    }
                }
            }
        }else{
            for(int j = 0;j < 3;j++){
                if(!vis2[x + j][y]){
                    vis2[x + j][y] = 1;
                    if(v[x + j][y] == 'R'){
                        cnt0++;
                    }else if(v[x + j][y] == 'G'){
                        cnt1++;
                    }else{
                        cnt2++;
                    }
                }
            }
        }
        if(id == 0){
            if(ok(x,y,id^1))self(self, x, y, id^1);
            if(ok(x - 1,y + 1,id^1))self(self, x - 1, y + 1, id^1);
            if(ok(x - 2,y + 2,id^1))self(self, x - 2, y + 2, id^1);
        }else{
            if(ok(x,y,id^1))self(self, x, y, id^1);
            if(ok(x + 1,y - 1,id^1))self(self, x + 1, y - 1, id^1);
            if(ok(x + 2,y - 2,id^1))self(self, x + 2, y - 2, id^1);
        }
    };
    dfs2(dfs2, x, y, id);
    ans+=min({cnt0,cnt1,cnt2});
}
int main(){
    cin>>n>>m;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            cin>>v[i][j];
        }
    }
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            if(ok(i,j,0)){
                dfs(i,j,0);
            }
            if(ok(i,j,1)){
                dfs(i,j,1);
            }
        }
    }
    cout<<ans;
    return 0;
}
/**
10 10
RGWRGWRGWR
WWRGWRGWRG
WRGWRGWRGW
RGWRGWRGWR
GWRGWWGWRG
WRGWRGWRGW
RGWRGWRGWR
GWRGWRGWRG
WRGWRGWRGW
RGWRGWRGWR

**/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 13
Accepted

Test #1:

score: 13
Accepted
time: 1ms
memory: 5740kb

input:

1 1
G

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5728kb

input:

1 2
RG

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 5668kb

input:

2 1
W
R

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5540kb

input:

3 2
WW
RW
WR

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 5668kb

input:

4 4
GRRW
GWWR
WWWW
RGRG

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 5668kb

input:

4 4
RGRR
RRRG
GRGW
RGWW

output:

2

result:

ok single line: '2'

Test #7:

score: 0
Accepted
time: 1ms
memory: 5692kb

input:

4 4
RRGR
GRRG
WRGW
RGWW

output:

3

result:

ok single line: '3'

Test #8:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

4 4
RGWR
GGGW
WWGW
RWGW

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 1ms
memory: 5548kb

input:

3 3
RGW
GGG
WGW

output:

1

result:

ok single line: '1'

Test #10:

score: 0
Accepted
time: 1ms
memory: 5708kb

input:

4 1
W
R
G
W

output:

1

result:

ok single line: '1'

Test #11:

score: 0
Accepted
time: 1ms
memory: 5668kb

input:

4 4
RGWR
GWRG
WRGW
RGWR

output:

3

result:

ok single line: '3'

Test #12:

score: 0
Accepted
time: 1ms
memory: 5744kb

input:

4 4
RWWR
GWRG
WGGW
RGWR

output:

3

result:

ok single line: '3'

Test #13:

score: 0
Accepted
time: 1ms
memory: 5664kb

input:

4 4
RGWR
WWRG
WRGW
RWGR

output:

2

result:

ok single line: '2'

Test #14:

score: 0
Accepted
time: 1ms
memory: 5552kb

input:

4 4
RRRR
GGGG
WWWW
RRRR

output:

4

result:

ok single line: '4'

Test #15:

score: 0
Accepted
time: 1ms
memory: 5660kb

input:

4 4
RRRR
GGGR
WWWW
RRRR

output:

3

result:

ok single line: '3'

Test #16:

score: 0
Accepted
time: 0ms
memory: 5580kb

input:

4 4
RRRR
GGGG
WWWW
RWRR

output:

4

result:

ok single line: '4'

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #17:

score: 20
Accepted
time: 1ms
memory: 5676kb

input:

5 5
RRGRR
RGRGW
RRWRW
RGWGW
RWWWW

output:

3

result:

ok single line: '3'

Test #18:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

6 6
RGWRGW
RRRGWR
RRWGWR
WRRRWG
GGGGGW
WWWWWW

output:

7

result:

ok single line: '7'

Test #19:

score: 0
Accepted
time: 1ms
memory: 5560kb

input:

7 10
RRRGRGWRGW
RGGGWRRGWR
RWWWWGRRGG
RGWRWWGGGW
WWRGWRGWGW
RGWWGGRGWW
RRGWWWWWWW

output:

14

result:

ok single line: '14'

Test #20:

score: -20
Wrong Answer
time: 0ms
memory: 5788kb

input:

10 8
RGWRRRGW
RGWGRRGW
WRGWGRGW
RGWWRGWW
GWRRGWWW
WRRGRWRR
GRGWGRGG
WGWWWRWR
RGWRGRGW
RRWRGWWW

output:

17

result:

wrong answer 1st lines differ - expected: '16', found: '17'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%