답안 #936669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
936669 2024-03-02T13:20:39 Z maomao90 화성 (APIO22_mars) C++17
0 / 100
1 ms 352 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
#include "mars.h"
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;
const int dirr[] = {1, 0, -1, 0}, dirc[] = {0, 1, 0, -1};
const ii corners[] = {{0, 0}, {0, 2}, {2, 2}, {2, 0}};

string process(vector<vector<string>> a, int i, int j, int k, int n) {
    int tn = 3 + 2 * k, m = 2 * (n - k - 1);
    int HALFN = (n + 1) / 2 * 2 + 1;
    int BORDER = 2 * n - HALFN + 1;
    int SIDES[] = {BORDER, BORDER, HALFN, HALFN};
    // 3 + 2 * k == HALFN
    // k = (HALFN - 3) / 2
    if (tn <= HALFN) {
        vector<string> grid(tn, string(tn, '0'));
        REP (x, 0, 3) {
            REP (y, 0, 3) {
                REP (p, 0, (k + 1) * (k + 1)) {
                    int r = x + 2 * (p / (k + 1)),
                        c = y + 2 * (p % (k + 1));
                    grid[r][c] = a[x][y][p];
                }
            }
        }
        //cerr << i << ' ' << j << ' ' << k << '\n';
        //REP (r, 0, tn) {
            //cerr << grid[r] << '\n';
        //}
        string res;
        if (tn == HALFN) {
            if (m - 1 <= i && m - 2 <= j) {
                // m - 1 <= r <= 2 * n
                // 2 * n - HALFN + 1 <= r <= 2 * n
                // m - 2 <= c <= 2 * n
                //for (int r = 2 * n - (m - i); r >= i; r -= 2) {
                    //for (int c = 2 * n - (m - j); c >= j; c -= 3) {
                for (int r = 2 * n - (m - i); r >= BORDER; r -= 2) {
                    for (int c = 2 * n - (m - j); c >= BORDER; c -= 3) {
                        res += grid[r - i][c - j];
                    }
                }
            } else if (i < 2 && j < 3) {
                //for (int r = i; r < i + tn; r += 2) {
                    //for (int c = j; c < j + tn; c += 3) {
                for (int r = i; r < BORDER; r += 2) {
                    for (int c = j; c < BORDER; c += 3) {
                        res += grid[r - i][c - j];
                    }
                }
            } else if (i < 3 && m - 1 <= j) {
                //for (int r = i; r < i + tn; r += 3) {
                for (int r = i; r < BORDER; r += 3) {
                    //for (int c = 2 * n - (m - j); c >= j; c -= 2) {
                    for (int c = 2 * n - (m - j); c >= BORDER; c -= 2) {
                        res += grid[r - i][c - j];
                    }
                }
            } else if (m - 2 <= i && j < 2) {
                //for (int r = 2 * n - (m - i); r >= i; r -= 3) {
                for (int r = 2 * n - (m - i); r >= BORDER; r -= 3) {
                    //for (int c = j; c < j + tn; c += 2) {
                    for (int c = j; c < BORDER; c += 2) {
                        res += grid[r - i][c - j];
                    }
                }
            }
        }
        for (int r = 0; r < tn; r += 2) {
            for (int c = 0; c < tn; c += 2) {
                res += grid[r][c];
            }
        }
        res.resize(100, '0');
        return res;
    } else if (k < n - 2) {
        if (m - 1 <= i && m - 2 <= j) {
            return a[2][2];
        } else if (i < 2 && j < 3) {
            return a[0][0];
        } else if (i < 3 && m - 1 <= j) {
            return a[0][2];
        } else if (m - 2 <= i && j < 2) {
            return a[2][0];
        } else {
            return string(100, '0');
        }
    } else if (k == n - 2) {
        vector<string> grid;
        if (i == 2 && j == 2) {
            grid = vector<string>(HALFN, string(HALFN, '0'));
            REP (di, 1, 3) {
                REP (dj, 0, 3) {
                    int ptr = 0;
                    for (int r = 2 * n - (2 - di); r >= BORDER; r -= 2) {
                        for (int c = 2 * n - (2 - dj); c >= BORDER; c -= 3) {
                            grid[r - BORDER][c - BORDER] = a[di][dj][ptr++];
                        }
                    }
                }
            }
        } else if (i == 0 && j == 0) {
            grid = vector<string>(BORDER, string(BORDER, '0'));
            REP (di, 0, 2) {
                REP (dj, 0, 3) {
                    int ptr = 0;
                    for (int r = di; r < BORDER; r += 2) {
                        for (int c = dj; c < BORDER; c += 3) {
                            grid[r][c] = a[di][dj][ptr++];
                        }
                    }
                }
            }
        } else if (i == 0 && j == 2) {
            grid = vector<string>(BORDER, string(HALFN, '0'));
            REP (di, 0, 3) {
                REP (dj, 1, 3) {
                    int ptr = 0;
                    for (int r = di; r < BORDER; r += 3) {
                        for (int c = 2 * n - (2 - dj); c >= BORDER; c -= 2) {
                            grid[r][c - BORDER] = a[di][dj][ptr++];
                        }
                    }
                }
            }
        } else if (i == 2 && j == 0) {
            grid = vector<string>(HALFN, string(BORDER, '0'));
            REP (di, 0, 3) {
                REP (dj, 0, 2) {
                    int ptr = 0;
                    for (int r = 2 * n - (2 - di); r >= BORDER; r -= 3) {
                        for (int c = dj; c < BORDER; c += 2) {
                            grid[r - BORDER][c] = a[di][dj][ptr++];
                        }
                    }
                }
            }
        } else {
            return string(100, '0');
        }
        cerr << i << ' ' << j << '\n';
        REP (i, 0, SZ(grid)) {
            cerr << grid[i] << '\n';
        }
        vector<vi> vis(SZ(grid), vi(SZ(grid[0]), 0));
        int comp = 0, ptr = 1;
        REP (r, 0, SZ(grid)) {
            REP (c, 0, SZ(grid[0])) {
                if (vis[r][c] || grid[r][c] == '0') {
                    continue;
                }
                comp++;
                queue<ii> bfs;
                bfs.push({r, c});
                vis[r][c] = ptr++;
                while (!bfs.empty()) {
                    auto [ur, uc] = bfs.front(); bfs.pop();
                    REP (k, 0, 4) {
                        int vr = ur + dirr[k], vc = uc + dirc[k];
                        if (vr < 0 || vr >= SZ(grid) || vc < 0 || vc >= SZ(grid[0])) {
                            continue;
                        }
                        if (grid[vr][vc] == '0' || vis[vr][vc]) {
                            continue;
                        }
                        bfs.push({vr, vc});
                        vis[vr][vc] = vis[ur][uc];
                    }
                }
            }
        }
        vi border;
        // clockwise
        if (i == 2 && j == 2) {
            // left then down
            RREP (c, SZ(grid[0]) - 1, 0) {
                border.pb(vis[0][c]);
            }
            REP (r, 1, SZ(grid)) {
                border.pb(vis[r][0]);
            }
        } else if (i == 0 && j == 0) {
            // right then up
            REP (c, 0, SZ(grid[0])) {
                border.pb(vis[SZ(grid) - 1][c]);
            }
            RREP (r, SZ(grid) - 2, 0) {
                border.pb(vis[r][SZ(grid[0]) - 1]);
            }
        } else if (i == 0 && j == 2) {
            // down then right
            REP (r, 0, SZ(grid)) {
                border.pb(vis[r][0]);
            }
            REP (c, 1, SZ(grid[1])) {
                border.pb(vis[SZ(grid) - 1][c]);
            }
        } else if (i == 2 && j == 0) {
            // up then left
            RREP (r, SZ(grid) - 1, 0) {
                border.pb(vis[r][SZ(grid[0]) - 1]);
            }
            RREP (c, SZ(grid[0]) - 2, 0) {
                border.pb(vis[0][c]);
            }
        }
        for (int i : border) {
            cerr << i << ' ';
        }
        cerr << '\n';
        vi lst(ptr, -1);
        REP (i, 0, SZ(border)) {
            lst[border[i]] = i;
        }
        REP (i, 1, ptr) {
            comp -= lst[i] != -1;
        }
        string res;
        REP (k, 0, 9) {
            if (comp >> k & 1) {
                res += "1";
            } else {
                res += "0";
            }
        }
        vi stk;
        stk.pb(0);
        int lvl = 0;
        REP (i, 0, SZ(border)) {
            int delta;
            if (border[i] == 0) {
                if (lvl & 1) {
                    if (lst[border[i - 1]] == i - 1) {
                        stk.pop_back();
                        delta = -1;
                    } else {
                        delta = 1;
                    }
                } else {
                    delta = 0;
                }
            } else {
                if (lvl & 1) {
                    delta = 0;
                } else {
                    if (stk.back() != border[i]) {
                        stk.pb(border[i]);
                        delta = 1;
                    } else {
                        delta = -1;
                    }
                }
            }
            if (delta == 0) {
                cerr << '_';
                res += "10";
            } else if (delta == -1) {
                cerr << ')';
                res += "00";
            } else {
                cerr << '(';
                res += "01";
            }
            lvl += delta;
        }
        cerr << '\n';
        res.resize(100, '0');
        cerr << comp << '\n';
        cerr << res << '\n';
        return res;
    } else {
        assert(k == n - 1);
        int ans = 0;
        int ptr = 1;
        vi border[4];
        REP (l, 0, 4) {
            auto [ai, aj] = corners[l];
            REP (b, 0, 9) {
                if (a[ai][aj][b] == '1') {
                    ans += 1 << b;
                }
            }
            vi stk;
            stk.pb(0);
            int lvl = 0;
            REP (i, 0, SIDES[l] + SIDES[(l + 1) % 4] - 1) {
                int delta;
                if (a[ai][aj][9 + i * 2] == '1') {
                    delta = 0;
                } else if (a[ai][aj][9 + i * 2 + 1] == '0') {
                    delta = -1;
                } else {
                    delta = 1;
                }
                lvl += delta;
                if (delta == 1 && (lvl & 1)) {
                    stk.pb(ptr++);
                } else if (delta == -1 && (lvl & 1 ^ 1)) {
                    stk.pop_back();
                }
                if (lvl & 1) {
                    border[l].pb(stk.back());
                } else {
                    border[l].pb(0);
                }
            }
            for (int i : border[l]) {
                cerr << i << ' ';
            }
            cerr << '\n';
        }
        vector<vi> adj(ptr);
        REP (l, 0, 4) {
            int pl = l == 0 ? 3 : l - 1;
            REP (i, 0, SIDES[l]) {
                int u = border[l][i],
                    v = border[pl][SZ(border[pl]) - 1 - i];
                if (u == 0 || v == 0) {
                    continue;
                }
                adj[u].pb(v);
                adj[v].pb(u);
            }
        }
        vector<bool> vis(ptr);
        REP (i, 1, ptr) {
            if (vis[i]) {
                continue;
            }
            ans++;
            vis[i] = 1;
            queue<int> qu;
            qu.push(i);
            while (!qu.empty()) {
                int u = qu.front(); qu.pop();
                for (int v : adj[u]) {
                    if (vis[v]) {
                        continue;
                    }
                    vis[v] = 1;
                    qu.push(v);
                }
            }
        }
        string sans(100, '0');
        REP (l, 0, 30) {
            if (ans >> l & 1) {
                sans[l] = '1';
            }
        }
        return sans;
    }
}

Compilation message

mars.cpp: In function 'std::string process(std::vector<std::vector<std::__cxx11::basic_string<char> > >, int, int, int, int)':
mars.cpp:333:48: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
  333 |                 } else if (delta == -1 && (lvl & 1 ^ 1)) {
      |                                            ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 352 KB Incorrect
2 Halted 0 ms 0 KB -