Submission #1086013

# Submission time Handle Problem Language Result Execution time Memory
1086013 2024-09-09T09:38:40 Z underwaterkillerwhale Land of the Rainbow Gold (APIO17_rainbow) C++17
11 / 100
24 ms 1372 KB
#include <bits/stdc++.h>
#define ll              long long
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)
#define iter(id, v)     for(auto id : v)
#define fs              first
#define se              second
#define MP              make_pair
#define pb              push_back
#define bit(msk, i)     ((msk >> i) & 1)
#define SZ(v)           (ll)v.size()
#define ALL(v)          v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 2e5 + 7;
const ll INF = 1e18;
const ll BASE = 137;
const int szBL = 350;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int n, m, Sr, Sc, nmove, Q;
string moves;

bool sub1c, sub2c, sub3c;

namespace sub1 {
    const int N1 = 50 + 7;
    int dd[N1][N1];

    void init () {
        int u = Sr, v = Sc;
        dd[u][v] = -1;
        iter (&c, moves) {
            if (c == 'N') dd[--u][v] = -1;
            else if (c == 'S') dd[++u][v] = -1;
            else if (c == 'W') dd[u][--v] = -1;
            else dd[u][++v] =-1;
        }
    }

    bool inside (int u, int v, int x, int y, int u1, int v1) {
        return u >= x && u <= u1 && v >= y && v <= v1;
    }

    int solution (int x, int y, int u, int v) {
        rep (i, 1, n)
        rep (j, 1, m) if (dd[i][j] != -1) dd[i][j] = 0;
//        rep (i, 1, n) rep (j, 1, m) cout << dd[i][j] <<" \n"[j == m];
        auto flooding = [&] (int u1, int v1, int color) {
            static queue<pii> Q;
            Q.push({u1, v1});
            dd[u1][v1] = color;
            while (!Q.empty()) {
                pii cur = Q.front();
                Q.pop();
                rep (k, 0, 3)  {
                    int ni = cur.fs + dx[k], nj = cur.se + dy[k];
                    if (inside(ni, nj, x, y, u, v) && dd[ni][nj] != -1 && dd[ni][nj] == 0) {
                        dd[ni][nj] = color;
                        Q.push({ni, nj});
                    }
                }
            }
        };

        int num_cpn = 0;
        rep (i, 1, n)
        rep (j, 1, m) {
            if (dd[i][j] == 0 && inside(i, j, x, y, u, v)) {
                ++num_cpn;
                flooding(i, j, num_cpn);
            }
        }
        return num_cpn;
    }

}

int colour (int x, int y, int u, int v) {
//    if (sub1c)
        return sub1 :: solution(x, y, u, v);
}

void init (int _n, int _m, int _Sr, int _Sc, int _nmove, char _moves[]) {
    n = _n;
    m = _m;
    Sr = _Sr;
    Sc = _Sc;
    nmove = _nmove;
    rep (i, 0, nmove - 1) moves += _moves[i];
    if (n <= 50 && m <= 50) {
        sub1 :: init();
        sub1c = 1;
    }
}

void solution() {
    cin >> n >> m >> nmove >> Q;
    cin >> Sr >> Sc;
    cin >> moves;
    if (n <= 50 && m <= 50) {
        sub1 :: init();
        sub1c = 1;
    }
    rep (i, 1, Q) {
        int x, y, u, v;
        cin >> x >> y >> u >> v;
        cout << colour (x, y, u, v) <<"\n";
    }
}

#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
//int main () {
////    file("c");
//    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
//    int num_Test = 1;
////    cin >> num_Test;
//    while (num_Test--)
//        solution();
//}
/*
no bug +6
6 4 9 1
3 3
NWESSWEWS
2 3 2 3

*/

# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 8 ms 488 KB Output is correct
3 Correct 13 ms 488 KB Output is correct
4 Correct 24 ms 480 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 0 ms 448 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 0 ms 444 KB Output is correct
11 Correct 15 ms 476 KB Output is correct
12 Correct 11 ms 496 KB Output is correct
13 Correct 10 ms 500 KB Output is correct
14 Correct 8 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 1116 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 2 ms 1232 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 8 ms 488 KB Output is correct
3 Correct 13 ms 488 KB Output is correct
4 Correct 24 ms 480 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 0 ms 448 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 0 ms 444 KB Output is correct
11 Correct 15 ms 476 KB Output is correct
12 Correct 11 ms 496 KB Output is correct
13 Correct 10 ms 500 KB Output is correct
14 Correct 8 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Runtime error 2 ms 1372 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 8 ms 488 KB Output is correct
3 Correct 13 ms 488 KB Output is correct
4 Correct 24 ms 480 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 0 ms 448 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Correct 0 ms 444 KB Output is correct
11 Correct 15 ms 476 KB Output is correct
12 Correct 11 ms 496 KB Output is correct
13 Correct 10 ms 500 KB Output is correct
14 Correct 8 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Runtime error 2 ms 1372 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -