답안 #678563

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678563 2023-01-06T07:36:17 Z uylulu Dango Maker (JOI18_dango_maker) C++17
0 / 100
102 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

#define ld long double
// #define int __int16_t
#define endl "\n"

const int N = 3e3;

set<int> adj[N*N + 1];
char grid[N + 1][N + 1];    

map<pair<pair<int,int>,pair<int,int>>,int> mp;
vector<vector<int>> dp;

int f(int s,int pa,bool type) {
    if(dp[s][type] != -1) return dp[s][type];

    int res = type;
    for(auto u : adj[s]) {
        if(u == pa) continue;
        
        res = (res + f(u,s,!type));
    }
    return dp[s][type] = res;
}

signed main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);

    int n,m;
    cin>>n>>m;

    for(int i = 1;i <= n;i++) {
        for(int j = 1;j <= m;j++) {
            cin>>grid[i][j];
        }
    }

    int curr = 1;

    for(int i = 1;i <= n;i++) {
        for(int j = 1;j <= m;j++) {
            int cnt = 0;

            if(j <= m - 2 && grid[i][j] == 'R' && grid[i][j + 1] == 'G' && grid[i][j + 2] == 'W') {
                mp[{{i,j},{i,j + 2}}] = curr;
            
                // intersect G
                pair<pair<int,int>,pair<int,int>> tmp = {{i - 1,j + 1},{i + 1,j + 1}};
                if(mp[tmp]) {
                    adj[curr].insert(mp[tmp]);
                    adj[mp[tmp]].insert(curr);
                }
                // intersect W
                tmp = {{i - 2,j + 2},{i - 2,j}};
                if(mp[tmp]) {
                    adj[curr].insert(mp[tmp]);
                    adj[mp[tmp]].insert(curr);
                }

                curr++;
                cnt++;
            }
            if(i <= m - 2 && grid[i][j] == 'R' && grid[i + 1][j] == 'G' && grid[i + 2][j] == 'W') {
                mp[{{i,j},{i + 2,j}}] = curr;

                // intersect G
                pair<pair<int,int>,pair<int,int>> tmp = {{i + 1,j - 1},{i + 1,j + 1}};
                if(mp[tmp]) {
                    adj[curr].insert(mp[tmp]);
                    adj[mp[tmp]].insert(curr);
                }
                curr++;
                cnt++;
            }
            if(cnt == 2) {
                adj[curr - 2].insert(curr - 1);
                adj[curr - 1].insert(curr - 2);
            }
        }
    }
    mp.clear();


    return 0;
}    
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 102 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -