Submission #240897

# Submission time Handle Problem Language Result Execution time Memory
240897 2020-06-21T12:22:04 Z aggu_01000101 Dango Maker (JOI18_dango_maker) C++14
100 / 100
1037 ms 182072 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define INF 100000000000000000
//#define int long long
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
#define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
struct node{
    char c;
    int first, second;
};
int n, m;
const int N = 3000;//first->horizontal, second -> vertical
vector<bool> vis;
int currnode = 0;
node mat[N][N];
vector<pair<int, int>> nv;
int solve(int i){
    int type = 1;
    if(mat[nv[i].first][nv[i].second].first != i){
        type = 0;
    }
    //cout<<i<<" "<<type<<endl;
    vector<int> lvls;
    queue<pair<pair<int, int>, int>> q;
    q.push({{i, type}, 0});
    vis[i] = true;
    while(!q.empty()){
        pair<pair<int, int>, int> curr = q.front();
        q.pop();
        if(lvls.size()<=curr.second) lvls.push_back(1);
        else lvls[curr.second]++;
        if(curr.first.second == 0){
            int i = nv[curr.first.first].first;
            int j = nv[curr.first.first].second;
            if(mat[i][j].first != -1){
                if(!vis[mat[i][j].first]){
                    vis[mat[i][j].first] = true;
                    q.push({{mat[i][j].first, 1}, curr.second+1});
                }
            }
            if(j>0 && mat[i+1][j-1].first!=-1){
                if(!vis[mat[i+1][j-1].first]){
                    vis[mat[i+1][j-1].first] = true;
                    q.push({{mat[i+1][j-1].first, 1}, curr.second+1});
                }
            }
            if(j>1 && mat[i+2][j-2].first!=-1){
                if(!vis[mat[i+2][j-2].first]){
                    vis[mat[i+2][j-2].first] = true;
                    q.push({{mat[i+2][j-2].first, 1}, curr.second+1});
                }
            }
        }
        else{
            int i = nv[curr.first.first].first;
            int j = nv[curr.first.first].second;
            if(mat[i][j].second != -1){
                if(!vis[mat[i][j].second]){
                    vis[mat[i][j].second] = true;
                    q.push({{mat[i][j].second, 0}, curr.second+1});
                }
            }
            if(i>0 && mat[i-1][j+1].second!=-1){
                if(!vis[mat[i-1][j+1].second]){
                    vis[mat[i-1][j+1].second] = true;
                    q.push({{mat[i-1][j+1].second, 0}, curr.second+1});
                }
            }
            if(i>1 && mat[i-2][j+2].second!=-1){
                if(!vis[mat[i-2][j+2].second]){
                    vis[mat[i-2][j+2].second] = true;
                    q.push({{mat[i-2][j+2].second, 0}, curr.second+1});
                }
            }
        }
    }
    if(lvls.size()==1) return lvls[0];
    if(lvls.size()==2) return max(lvls[0], lvls[1]);
    pair<int, int> dp = {lvls[0], lvls[1]};
    int tr = max(dp.first, dp.second);
    for(int i = 2;i<lvls.size();i++){
        int temp = max(dp.first + lvls[i], dp.second);
        dp.first = dp.second;
        dp.second = temp;
        tr = max(tr, temp);
    }
    return tr;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    for(int i = 0;i<n;i++){
        string s;
        for(int j = 0;j<m;j++) cin>>mat[i][j].c;
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++) mat[i][j].first = mat[i][j].second =  -1;
    }
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            if(mat[i][j].c!='R') continue;
            if(i+2<n){
                if(mat[i+1][j].c=='G' && mat[i+2][j].c=='W'){
                    int cnode = currnode++;
                    vis.push_back(false);
                    nv.push_back({i, j});
                    mat[i][j].second = cnode;
                }
            }
            if(j+2<m){
                if(mat[i][j+1].c=='G' && mat[i][j+2].c=='W'){
                    int cnode = currnode++;
                    vis.push_back(false);
                    nv.push_back({i, j});
                    mat[i][j].first = cnode;
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0;i<currnode;i++){
        /*cout<<i<<" is connected to: ";
        for(int j: adj[i]){
            cout<<j<<" ";
        }
        cout<<endl;
        */
        if(!vis[i]){
            ans+=solve(i);
        }
    }
    cout<<ans<<endl;
    //create a node out of each skewer that you can make
    //connect nodes that intersect with each other
    //For each connected component,
}
/*
4 4
RGWR
GRRG
WGGW
WWWR

5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW
 */

Compilation message

dango_maker.cpp: In function 'int solve(int)':
dango_maker.cpp:37:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(lvls.size()<=curr.second) lvls.push_back(1);
            ~~~~~~~~~~~^~~~~~~~~~~~~
dango_maker.cpp:88:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 2;i<lvls.size();i++){
                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 4 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 6 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 4 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 4 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 11 ms 12544 KB Output is correct
56 Correct 5 ms 512 KB Output is correct
57 Correct 10 ms 8704 KB Output is correct
58 Correct 52 ms 17284 KB Output is correct
59 Correct 386 ms 114536 KB Output is correct
60 Correct 399 ms 114540 KB Output is correct
61 Correct 389 ms 114512 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 396 ms 114448 KB Output is correct
64 Correct 730 ms 182028 KB Output is correct
65 Correct 778 ms 182036 KB Output is correct
66 Correct 1037 ms 182072 KB Output is correct
67 Correct 691 ms 148424 KB Output is correct
68 Correct 678 ms 148424 KB Output is correct
69 Correct 638 ms 148436 KB Output is correct
70 Correct 78 ms 25456 KB Output is correct
71 Correct 79 ms 25456 KB Output is correct
72 Correct 80 ms 25464 KB Output is correct
73 Correct 82 ms 25456 KB Output is correct
74 Correct 85 ms 25592 KB Output is correct
75 Correct 81 ms 25464 KB Output is correct
76 Correct 83 ms 25456 KB Output is correct
77 Correct 85 ms 25456 KB Output is correct
78 Correct 84 ms 25456 KB Output is correct
79 Correct 85 ms 25592 KB Output is correct
80 Correct 85 ms 25584 KB Output is correct
81 Correct 85 ms 25456 KB Output is correct
82 Correct 86 ms 25456 KB Output is correct
83 Correct 90 ms 25456 KB Output is correct
84 Correct 108 ms 25456 KB Output is correct
85 Correct 97 ms 25464 KB Output is correct
86 Correct 104 ms 25456 KB Output is correct
87 Correct 107 ms 25456 KB Output is correct
88 Correct 94 ms 25456 KB Output is correct
89 Correct 91 ms 25584 KB Output is correct
90 Correct 98 ms 25624 KB Output is correct