Submission #599980

#TimeUsernameProblemLanguageResultExecution timeMemory
599980PiokemonDango Maker (JOI18_dango_maker)C++17
33 / 100
1 ms468 KiB
 #include <bits/stdc++.h>
using namespace std;

int d[2][2] = {{1,0},{0,1}};
string plansza[1009];
int i_prze[1009][1009][4];
deque<pair<pair<int,int>,int>> wybierz[4];
int n,m;

bool check(int x, int y, int z){
    if (x<1 || x>n || y<1 || y>m || x+d[z][0]*2<1 || x+d[z][0]*2>n || y+d[z][1]*2<1 || y+d[z][1]*2>m){
        return 0;
    }
    if ((plansza[x][y] == 'R') && (plansza[x + d[z][0]][y + d[z][1]] == 'G') && (plansza[x + d[z][0]*2][y + d[z][1]*2] == 'W')){
        return 1;
    }
    return 0;
}

void aktualizuj(int x, int y, int z, int &p){
    if (check(x,y,z)){
        i_prze[x][y][z] -= 1;
        wybierz[i_prze[x][y][z]].push_back({{x,y},z});
        p = min(p, i_prze[x][y][z]);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int odp = 0,p=0,x,y,z;
    pair<pair<int,int>,int> ter;
    cin >> n >> m;
    for (int x=1;x<=n;x++){
        cin >> plansza[x];
        plansza[x] = '#' + plansza[x];
    }
    for (x=1;x<=n;x++){
        for (y=1;y<=m;y++){
            for (z=0;z<2;z++){
                if (!check(x,y,z)){
                    i_prze[x][y][z] = -1;
                    continue;
                }
                i_prze[x][y][z] = 0;
                if (z==0){
                    if (check(x,y,1)){
                        i_prze[x][y][z] += 1;
                    }
                    if (check(x+1, y-1, 1)){
                        i_prze[x][y][z] += 1;
                    }
                    if (check(x+2, y-2, 1)){
                        i_prze[x][y][z] += 1;
                    }
                }
                else{
                    if (check(x,y,0)){
                        i_prze[x][y][z] += 1;
                    }
                    if (check(x-1, y+1, 0)){
                        i_prze[x][y][z] += 1;
                    }
                    if (check(x-2, y+2, 0)){
                        i_prze[x][y][z] += 1;
                    }
                }
                wybierz[i_prze[x][y][z]].push_back({{x,y},z});
            }
        }
    }
    while(p<4){
        if (wybierz[p].empty()){
            p += 1;
            continue;
        }
        ter = wybierz[p].front();
        wybierz[p].pop_front();
        x = ter.first.first; y = ter.first.second; z = ter.second;
        if (!check(x,y,z) || i_prze[x][y][z] != p){
            continue;
        }
        odp += 1;
        if (check(x,y,!z)){
            aktualizuj(x+1,y-1,z,p);
            aktualizuj(x+2,y-2,z,p);
        }
        if (check(x-1,y+1,!z)){
            aktualizuj(x+1,y-1,z,p);
            aktualizuj(x-1,y+1,z,p);
        }
        if (check(x-2,y+2,!z)){
            aktualizuj(x-1,y+1,z,p);
            aktualizuj(x-2,y+2,z,p);
        }
        plansza[x][y] = 'X';
        plansza[x+d[z][0]][y+d[z][1]] = 'X';
        plansza[x + d[z][0]*2][y + d[z][1]*2] = 'X';
    }
    cout << odp << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...