Submission #254598

# Submission time Handle Problem Language Result Execution time Memory
254598 2020-07-30T10:11:12 Z Atill83 Dango Maker (JOI18_dango_maker) C++14
0 / 100
4 ms 768 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e3+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, m;
char gr[MAXN][MAXN];

vector<int> adj[MAXN];
int name[MAXN][MAXN][2];
int ad = 0;
int col[MAXN];
int c[2];
void dfs(int v){
    for(int j: adj[v]){
        assert(col[j] == col[v]);
        if(col[j] == 0){
            col[j] = 3 - col[v];
            c[col[j] - 1]++;
            dfs(j);
        }
    }
}




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>n>>m;

    for(int i = 0; i < n; i++){
        cin>>gr[i];
    }

    for(int i = 0; i < n - 2; i++){
        for(int j = 0; j < m; j++){
            if(gr[i][j] == 'R' && gr[i + 1][j] == 'G' && gr[i + 2][j] == 'W'){
                name[i][j][0] = ++ad;
            }
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m - 2; j++){
            if(gr[i][j] == 'R' && gr[i][j + 1] == 'G' && gr[i][j + 2] == 'W'){
                name[i][j][1] = ++ad;
                if(name[i][j][0]){
                    adj[name[i][j][0]].push_back(name[i][j][1]);
                    adj[name[i][j][1]].push_back(name[i][j][0]);
                }
                if(i && name[i - 1][j + 1][0]){
                    adj[name[i - 1][j + 1][0]].push_back(name[i][j][1]);
                    adj[name[i][j][1]].push_back(name[i - 1][j + 1][0]);
                }

                if(i > 1 && name[i - 2][j + 2][0]){
                    adj[name[i - 2][j + 2][0]].push_back(name[i][j][1]);
                    adj[name[i][j][1]].push_back(name[i - 2][j + 2][0]);
                }
            }
        }
    }

    int cnt = 0;    
    
    for(int j = 1; j <= ad; j++){
        if(col[j] == 0){
            c[0] = 1;
            c[1] = 0;
            col[j] = 1;
            dfs(j);
            cnt += max(c[0], c[1]);
        }
    }    

    cout<<cnt<<endl;





    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Runtime error 4 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Runtime error 4 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Runtime error 4 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Halted 0 ms 0 KB -