Submission #948791

# Submission time Handle Problem Language Result Execution time Memory
948791 2024-03-18T14:25:09 Z Nhoksocqt1 Mars (APIO22_mars) C++17
14 / 100
11 ms 4288 KB
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 22;
const int lx[] = {-1, 0, 0, 1}, ly[] = {0, -1, 1, 0};

bool dx[2 * MAXN][2 * MAXN];

void bfs_mark(int x, int y, int n) {
    queue<ii> qu;
    qu.push(ii(x, y));
    dx[x][y] = 1;

    while(sz(qu)) {
        int x(qu.front().fi), y(qu.front().se);
        qu.pop();

        for (int id = 0; id < 4; ++id) {
            int u(x + lx[id]), v(y + ly[id]);
            if(min(u, v) < 0 || max(u, v) > 2 * n || dx[u][v])
                continue;

            dx[u][v] = 1;
            qu.push(ii(u, v));
        }
    }
}

string process(vector<vector<string>> str, int i, int j, int k, int n) {
    string res;
    int is_max_i = (i + 2 * (k + 1) >= 2 * n);
    int is_max_j = (j + 2 * (k + 1) >= 2 * n);
    if(k > 0 && is_max_i && is_max_j) {
        string st[3];
        for (int x = 0; x < 1 + 2 * is_max_i; ++x) {
            for (int y = 0; y < 1 + 2 * is_max_j; ++y) {
                string s(str[x][y]);
                if(k > 0) {
                    while(s.back() != '1')
                        s.pop_back();

                    s.pop_back();
                } else {
                    string z;
                    z.push_back(s[0]);
                    s = z;
                }

                if(x == 2) {
                    st[y] = s;
                } else {
                    res += s;
                }
            }
        }

        //cout << st[0] << ' ' << st[1] << ' ' << st[2] << '\n';
        int cnt(0);
        for (int i = 0; i <= 2 * k; ++i) {
            res.push_back(st[0][i]);
            res.push_back(st[1][i]);
            for (int j = 0; j <= 2 * k; ++j)
                res.push_back(st[2][cnt++]);
        }
    } else {
        for (int x = 0; x < 1 + 2 * is_max_i; ++x) {
            for (int y = 0; y < 1 + 2 * is_max_j; ++y) {
                string s(str[x][y]);
                if(k > 0) {
                    while(s.back() != '1')
                        s.pop_back();

                    s.pop_back();
                } else {
                    string z;
                    z.push_back(s[0]);
                    s = z;
                }

                res += s;
            }
        }
    }

    if(k + 1 == n) {
        int cnt(0);
        for (int i = 0; i <= 2 * n; ++i) {
            for (int j = 0; j <= 2 * n; ++j) {
                dx[i][j] = (res[cnt++] == '0');
                //cout << res[cnt - 1] << " \n"[j == 2 * n];
            }
        }

        int cnt_islands(0);
        for (int i = 0; i <= 2 * n; ++i) {
            for (int j = 0; j <= 2 * n; ++j) {
                if(!dx[i][j]) {
                    bfs_mark(i, j, n);
                    ++cnt_islands;
                }
            }
        }

        string ans;
        while(cnt_islands > 0) {
            ans.push_back(cnt_islands % 2 + '0');
            cnt_islands /= 2;
        }

        if(sz(ans) < 100)
            ans.insert(sz(ans), 100 - sz(ans), '0');

        return ans;
    }

    res.push_back('1');
    if(sz(res) < 100)
        res.insert(sz(res), 100 - sz(res), '0');

    return res;
}

#ifdef Nhoksocqt1

int main(void) {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    #define TASK "mars"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    vector<vector<int>> A;
    int n;
    cin >> n;

    for (int i = 0; i < 2 * n + 1; ++i) {
        vector<int> p;
        for (int j = 0; j < 2 * n + 1; ++j) {
            int z;
            cin >> z;
            p.push_back(z);
        }

        A.push_back(p);
    }

    string new_h[2 * MAXN][2 * MAXN], h[2 * MAXN][2 * MAXN];
    for (int i = 0; i < 2 * n + 1; ++i) {
        for (int j = 0; j < 2 * n + 1; ++j) {
            h[i][j] = A[i][j] + '0';
            h[i][j].insert(1, 99, '0');
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int x = 0; x + 2 * (i + 1) <= 2 * n; ++x) {
            for (int y = 0; y + 2 * (i + 1) <= 2 * n; ++y) {
                vector<vector<string>> p;
                for (int lx = 0; lx < 3; ++lx) {
                    vector<string> pt;
                    for (int ly = 0; ly < 3; ++ly)
                        pt.push_back(h[x + lx][y + ly]);

                    p.push_back(pt);
                }

                new_h[x][y] = process(p, x, y, i, n);
                cout << x << ' ' << y << ": " << new_h[x][y] << '\n';
            }
        }

        for (int x = 0; x <= 2 * n; ++x) {
            for (int y = 0; y <= 2 * n; ++y)
                h[x][y] = new_h[x][y];
        }
    }

    cout << "ANSWER: " << h[0][0] << '\n';

    int res(0);
    for (int it = 0; it < 30; ++it)
        res += (1LL << it) * (h[0][0][it] == '1');

    cout << "NUM ISLAND: " << res << '\n';

    return 0;
}

#endif // Nhoksocqt1
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
14 Incorrect 2 ms 608 KB invalid len
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
14 Incorrect 2 ms 608 KB invalid len
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
14 Incorrect 2 ms 608 KB invalid len
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
14 Incorrect 2 ms 608 KB invalid len
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
14 Incorrect 2 ms 608 KB invalid len
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
14 Incorrect 2 ms 608 KB invalid len
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
14 Incorrect 2 ms 608 KB invalid len
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3868 KB Output is correct
2 Correct 4 ms 4084 KB Output is correct
3 Correct 5 ms 4044 KB Output is correct
4 Correct 7 ms 3664 KB Output is correct
5 Correct 6 ms 4064 KB Output is correct
6 Correct 6 ms 3916 KB Output is correct
7 Correct 8 ms 4288 KB Output is correct
8 Correct 8 ms 4004 KB Output is correct
9 Correct 9 ms 4032 KB Output is correct
10 Correct 8 ms 4032 KB Output is correct
11 Correct 8 ms 3800 KB Output is correct
12 Correct 11 ms 3652 KB Output is correct
13 Correct 8 ms 3392 KB Output is correct
14 Incorrect 2 ms 608 KB invalid len
15 Halted 0 ms 0 KB -