Submission #530633

# Submission time Handle Problem Language Result Execution time Memory
530633 2022-02-26T04:30:18 Z kevin Dango Maker (JOI18_dango_maker) C++17
13 / 100
5 ms 7500 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define nl cout<<"\n"
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define ca(v) for(auto i:v) cout<<i<<" ";

const int MOD = 1e9 + 7;

int onv[3001][3001];
int onh[3001][3001];
list<int> adj[300001];
bool vis[3000001];
int dp[3000001][2];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
    int n, m; cin>>n>>m;
    char grid[n][m];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>grid[i][j];
        }
    }
    int cnt = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(grid[i][j] == 'R' && j+2 < m && grid[i][j+1] == 'G' && grid[i][j+2] == 'W') onh[i][j] = ++cnt;
        }
    }
    for(int j=0; j<m; j++){
        for(int i=0; i<n; i++){
            if(grid[i][j] == 'R' && i+2 < n && grid[i+1][j] == 'G' && grid[i+2][j] == 'W') onv[i][j] = ++cnt;
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(onh[i][j]){
                for(int k=0; k<3; k++){
                    if(i-k >= 0 && j+k < m && onv[i-k][j+k]){
                        adj[onh[i][j]].push_back(onv[i-k][j+k]);
                        adj[onv[i-k][j+k]].push_back(onh[i][j]);
                    }
                }
            }
        }
    }
    int ans = 0;
    // cout<<cnt;
    for(int a=0; a<n; a++){
        for(int b=m-1; b>=0; b--){
            int i = 0;
            if(onh[a][b]) i = onh[a][b];
            else if(onv[a][b] && (i == 0 || adj[onv[a][b]].size() < adj[i].size())) i = onv[a][b];
            if(i && !vis[i]){
                vis[i] = 1;
                queue<int> q;
                q.push(i);
                while(q.size()){
                    int c = q.front();
                    // cout<<c<<" ";
                    q.pop();
                    dp[c][0] = 1;
                    for(int a:adj[c]){
                        if(!vis[a]){
                            q.push(a);
                            vis[a] = 1;
                        }
                        else{
                            dp[c][0] += dp[a][1];
                            dp[c][1] += max(dp[a][1], dp[a][0]);
                        }
                    }
                    if(q.size() == 0){
                        ans += max(dp[c][0], dp[c][1]);
                    }
                }
            }
        }
    }
    cout<<ans;
}

Compilation message

dango_maker.cpp: In function 'int main()':
dango_maker.cpp:22:40: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     if (fopen("input.in", "r")) freopen("input.in", "r", stdin);
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7300 KB Output is correct
10 Correct 5 ms 7324 KB Output is correct
11 Correct 4 ms 7384 KB Output is correct
12 Correct 4 ms 7500 KB Output is correct
13 Correct 4 ms 7372 KB Output is correct
14 Correct 4 ms 7388 KB Output is correct
15 Correct 4 ms 7372 KB Output is correct
16 Correct 4 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7300 KB Output is correct
10 Correct 5 ms 7324 KB Output is correct
11 Correct 4 ms 7384 KB Output is correct
12 Correct 4 ms 7500 KB Output is correct
13 Correct 4 ms 7372 KB Output is correct
14 Correct 4 ms 7388 KB Output is correct
15 Correct 4 ms 7372 KB Output is correct
16 Correct 4 ms 7372 KB Output is correct
17 Correct 4 ms 7372 KB Output is correct
18 Correct 4 ms 7372 KB Output is correct
19 Correct 4 ms 7372 KB Output is correct
20 Incorrect 4 ms 7364 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7372 KB Output is correct
2 Correct 4 ms 7372 KB Output is correct
3 Correct 4 ms 7372 KB Output is correct
4 Correct 4 ms 7372 KB Output is correct
5 Correct 4 ms 7372 KB Output is correct
6 Correct 4 ms 7372 KB Output is correct
7 Correct 4 ms 7372 KB Output is correct
8 Correct 4 ms 7372 KB Output is correct
9 Correct 4 ms 7300 KB Output is correct
10 Correct 5 ms 7324 KB Output is correct
11 Correct 4 ms 7384 KB Output is correct
12 Correct 4 ms 7500 KB Output is correct
13 Correct 4 ms 7372 KB Output is correct
14 Correct 4 ms 7388 KB Output is correct
15 Correct 4 ms 7372 KB Output is correct
16 Correct 4 ms 7372 KB Output is correct
17 Correct 4 ms 7372 KB Output is correct
18 Correct 4 ms 7372 KB Output is correct
19 Correct 4 ms 7372 KB Output is correct
20 Incorrect 4 ms 7364 KB Output isn't correct
21 Halted 0 ms 0 KB -