Submission #254689

# Submission time Handle Problem Language Result Execution time Memory
254689 2020-07-30T12:53:15 Z egekabas Dango Maker (JOI18_dango_maker) C++14
0 / 100
1 ms 384 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, m;
int a[3009][3009];
int l1[3009][3009];
int u1[3009][3009];
pii b1[3009][3009];
pii b2[3009][3009];
int vis[3009][3009];
int st;
int dfs(pii x){
    if(x.ff == 1e9){
        st = 1;
        return 0;
    }
    if(x.ff == -1) return 0;
    if(vis[x.ff][x.ss]) return 0;
    vis[x.ff][x.ss] = 1;
    
    int ret = 1;
    ret += dfs(b1[x.ff][x.ss])+dfs(b2[x.ff][x.ss]);
    return ret;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> m;
    string s;
    for(int i = 0; i < n; ++i){
        cin >> s;
        for(int j = 0; j < m; ++j){
            switch(s[j]){
                case 'R':
                    a[i][j] = 1;
                    break;
                case 'G':
                    a[i][j] = 2;
                    break;
                case 'W':
                    a[i][j] = 3;
                    break;  
            }
        }
    }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j){
            if(a[i][j] == 1){
                l1[i][j+1] = 1;
                u1[i+1][j] = 1;
            }
            b1[i][j] = {-1, -1};
            b2[i][j] = {-1, -1};
        }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j){
            if(a[i][j] != 2) continue;
            if(l1[i][j] && u1[i][j] && a[i+1][j] == 3 && a[i][j+1] == 3){
                b1[i+1][j] = {i, j+1};
                b2[i][j+1] = {i+1, j};
            }
            else if(l1[i][j])
                b2[i][j+1] = {1e9, 1e9};    
            else if(u1[i][j])
                b1[i+1][j] = {1e9, 1e9};
        }
    int ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            if(vis[i][j] == 0 && a[i][j] == 3){
                st = 0;
                ans += dfs({i, j})-1+st;
            }
    cout << ans << '\n';
}
# 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 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Incorrect 0 ms 384 KB Output isn't correct
9 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 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Incorrect 0 ms 384 KB Output isn't correct
9 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 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Incorrect 0 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -