답안 #240892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
240892 2020-06-21T12:03:14 Z aggu_01000101 Dango Maker (JOI18_dango_maker) C++14
33 / 100
607 ms 262148 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;
vector<vector<int>> adj;
int currnode = 0;
int solve(int i){
    vector<int> lvls;
    queue<pair<int, int>> q;
    q.push({i, 0});
    vis[i] = true;
    while(!q.empty()){
        pair<int, int> curr = q.front();
        q.pop();
        if(lvls.size()<=curr.second) lvls.push_back(1);
        else lvls[curr.second]++;
        for(int j: adj[curr.first]){
            if(vis[j]) continue;
            vis[j] = true;
            q.push({j, 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;
    node mat[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);
                    adj.push_back({});
                    //cout<<cnode<<" is ("<<i<<", "<<j<<") vertical"<<endl;
                    mat[i][j].second = cnode;
                    /*if(nodenum[i][j].first != -1){
                        adj[nodenum[i][j].first].insert(cnode);
                        adj[cnode].insert(nodenum[i][j].first);
                    }
                    if(j>0 && nodenum[i+1][j-1].first!=-1){
                        adj[nodenum[i+1][j-1].first].insert(cnode);
                        adj[cnode].insert(nodenum[i+1][j-1].first);
                    }
                    if(j>1 && nodenum[i+2][j-2].first!=-1){
                        adj[nodenum[i+2][j-2].first].insert(cnode);
                        adj[cnode].insert(nodenum[i+2][j-2].first);
                    }*/
                }
            }
            if(j+2<m){
                if(mat[i][j+1].c=='G' && mat[i][j+2].c=='W'){
                    int cnode = currnode++;
                    vis.push_back(false);
                    adj.push_back({});
                    //cout<<cnode<<" is ("<<i<<", "<<j<<") horizontal"<<endl;
                    mat[i][j].first = cnode;
                    if(mat[i][j].second != -1){
                        adj[mat[i][j].second].push_back(cnode);
                        adj[cnode].push_back(mat[i][j].second);
                    }
                    if(i>0 && mat[i-1][j+1].second!=-1){
                        adj[mat[i-1][j+1].second].push_back(cnode);
                        adj[cnode].push_back(mat[i-1][j+1].second);
                    }
                    if(i>1 && mat[i-2][j+2].second!=-1){
                        adj[mat[i-2][j+2].second].push_back(cnode);
                        adj[cnode].push_back(mat[i-2][j+2].second);
                    }
                }
            }
        }
    }
    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:31:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(lvls.size()<=curr.second) lvls.push_back(1);
            ~~~~~~~~~~~^~~~~~~~~~~~~
dango_maker.cpp:43:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 2;i<lvls.size();i++){
                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 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 5 ms 384 KB Output is correct
16 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 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 5 ms 384 KB Output is correct
16 Correct 4 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 4 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 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 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 5 ms 384 KB Output is correct
37 Correct 4 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 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 4 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 4 ms 384 KB Output is correct
53 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 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 5 ms 384 KB Output is correct
16 Correct 4 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 4 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 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 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 5 ms 384 KB Output is correct
37 Correct 4 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 5 ms 384 KB Output is correct
42 Correct 4 ms 384 KB Output is correct
43 Correct 4 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 4 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 4 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 4 ms 384 KB Output is correct
53 Correct 4 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 6 ms 640 KB Output is correct
57 Correct 6 ms 640 KB Output is correct
58 Correct 50 ms 15900 KB Output is correct
59 Correct 410 ms 135808 KB Output is correct
60 Correct 392 ms 135788 KB Output is correct
61 Correct 396 ms 135792 KB Output is correct
62 Correct 5 ms 384 KB Output is correct
63 Correct 383 ms 132208 KB Output is correct
64 Runtime error 607 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
65 Halted 0 ms 0 KB -