Submission #1054293

# Submission time Handle Problem Language Result Execution time Memory
1054293 2024-08-12T08:27:54 Z 정민찬(#11058) Land of the Rainbow Gold (APIO17_rainbow) C++14
35 / 100
3000 ms 31324 KB
#include "rainbow.h"
#include <bits/stdc++.h>

using namespace std;

int r, c;
vector<int> vis[200010];
vector<pair<int,int>> ran[200010];

void init(int R, int C, int sr, int sc, int M, char *S) {
    r = R;
    c = C;
    int x = sr, y = sc;
    vis[x].push_back(y);
    for (int i=0; i<M; i++) {
        if (S[i] == 'N') x --;
        if (S[i] == 'S') x ++;
        if (S[i] == 'W') y --;
        if (S[i] == 'E') y ++;
        vis[x].push_back(y);
    }
    for (int i=1; i<=R; i++) {
        sort(vis[i].begin(), vis[i].end());
        vis[i].erase(unique(vis[i].begin(), vis[i].end()), vis[i].end());
        int p = 0;
        for (auto &y : vis[i]) {
            if (y != p + 1) {
                ran[i].push_back({p+1, y-1});
            }
            p = y;
        }
        if (p != C) ran[i].push_back({p+1, C});
    }
}

struct DisjointSet{
    vector<int> par;
    void init(int n) {
        par.resize(n);
        iota(par.begin(), par.end(), 0);
    }
    int Find(int x) {
        if (par[x] == x) return x;
        return par[x] = Find(par[x]);
    }
    void Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        par[y] = x;
    }
};

DisjointSet dsu;

vector<array<int,3>> ran2[200010];

int colour(int ar, int ac, int br, int bc) {
    int num = 0;
    for (int x=ar; x<=br; x++) {
        ran2[x].clear();
        for (auto &[ly, ry] : ran[x]) {
            if (ry < ac) continue;
            if (ly > bc) break;
            int nly = max(ly, ac);
            int nry = min(ry, bc);
            ran2[x].push_back({nly, nry, num++});
        }
    }
    dsu.init(num);
    for (int x=ar+1; x<=br; x++) {
        if (ran2[x].empty() || ran2[x-1].empty()) continue;
        int j = 0;
        for (auto &[ly, ry, id] : ran2[x]) {
            while (j < ran2[x-1].size() && ran2[x-1][j][1] <= ry) {
                if (ran2[x-1][j][1] >= ly) dsu.Union(ran2[x-1][j][2], id);
                j ++;
            }
            if (j < ran2[x-1].size() && ry >= ran2[x-1][j][0]) {
                dsu.Union(ran2[x-1][j][2], id);
            }
        }
    }
    int ans = 0;
    for (int x=ar; x<=br; x++) {
        for (auto &[ly, ry, id] : ran2[x]) {
            if (dsu.Find(id) == id)
                ans ++;
        }
    }
    return ans;
}
/*
static int R, C, M, Q;
static int sr, sc;
static char S[100000 + 5];

int main() {
    scanf("%d %d %d %d", &R, &C, &M, &Q);
    scanf("%d %d", &sr, &sc);
    if (M > 0) {
        scanf(" %s ", S);
    }

    init(R, C, sr, sc, M, S);

    int query;
    for (query = 0; query < Q; query++) {
        int ar, ac, br, bc;
        scanf("%d %d %d %d", &ar, &ac, &br, &bc);
        printf("%d\n", colour(ar, ac, br, bc));
    }

    return 0;
}*/



Compilation message

rainbow.cpp: In function 'int colour(int, int, int, int)':
rainbow.cpp:61:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |         for (auto &[ly, ry] : ran[x]) {
      |                    ^
rainbow.cpp:73:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   73 |         for (auto &[ly, ry, id] : ran2[x]) {
      |                    ^
rainbow.cpp:74:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             while (j < ran2[x-1].size() && ran2[x-1][j][1] <= ry) {
      |                    ~~^~~~~~~~~~~~~~~~~~
rainbow.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             if (j < ran2[x-1].size() && ry >= ran2[x-1][j][0]) {
      |                 ~~^~~~~~~~~~~~~~~~~~
rainbow.cpp:85:20: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   85 |         for (auto &[ly, ry, id] : ran2[x]) {
      |                    ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Correct 3 ms 14428 KB Output is correct
3 Correct 3 ms 14428 KB Output is correct
4 Correct 4 ms 14540 KB Output is correct
5 Correct 4 ms 14428 KB Output is correct
6 Correct 2 ms 14428 KB Output is correct
7 Correct 2 ms 14428 KB Output is correct
8 Correct 3 ms 14428 KB Output is correct
9 Correct 2 ms 14428 KB Output is correct
10 Correct 2 ms 14428 KB Output is correct
11 Correct 3 ms 14428 KB Output is correct
12 Correct 4 ms 14428 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 4 ms 14428 KB Output is correct
15 Correct 2 ms 14472 KB Output is correct
16 Correct 3 ms 14428 KB Output is correct
17 Correct 2 ms 14428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Correct 2 ms 14428 KB Output is correct
3 Correct 38 ms 15764 KB Output is correct
4 Correct 645 ms 15604 KB Output is correct
5 Correct 2174 ms 16012 KB Output is correct
6 Correct 1717 ms 16076 KB Output is correct
7 Execution timed out 3035 ms 16320 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14472 KB Output is correct
2 Correct 15 ms 24788 KB Output is correct
3 Correct 16 ms 25948 KB Output is correct
4 Correct 15 ms 24368 KB Output is correct
5 Correct 15 ms 24280 KB Output is correct
6 Correct 19 ms 26460 KB Output is correct
7 Correct 19 ms 26972 KB Output is correct
8 Correct 4 ms 15064 KB Output is correct
9 Correct 5 ms 15196 KB Output is correct
10 Correct 7 ms 18012 KB Output is correct
11 Correct 9 ms 18392 KB Output is correct
12 Correct 10 ms 21740 KB Output is correct
13 Correct 14 ms 24496 KB Output is correct
14 Correct 12 ms 22876 KB Output is correct
15 Correct 13 ms 23000 KB Output is correct
16 Correct 18 ms 25692 KB Output is correct
17 Correct 17 ms 24412 KB Output is correct
18 Correct 16 ms 25544 KB Output is correct
19 Correct 16 ms 26748 KB Output is correct
20 Correct 16 ms 25304 KB Output is correct
21 Correct 4 ms 15320 KB Output is correct
22 Correct 5 ms 15452 KB Output is correct
23 Correct 13 ms 21596 KB Output is correct
24 Correct 14 ms 22484 KB Output is correct
25 Correct 18 ms 28260 KB Output is correct
26 Correct 24 ms 31324 KB Output is correct
27 Correct 21 ms 29532 KB Output is correct
28 Correct 21 ms 29740 KB Output is correct
29 Correct 22 ms 28504 KB Output is correct
30 Correct 29 ms 28508 KB Output is correct
31 Correct 22 ms 30044 KB Output is correct
32 Correct 19 ms 29504 KB Output is correct
33 Correct 19 ms 29656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Correct 3 ms 14428 KB Output is correct
3 Correct 3 ms 14428 KB Output is correct
4 Correct 4 ms 14540 KB Output is correct
5 Correct 4 ms 14428 KB Output is correct
6 Correct 2 ms 14428 KB Output is correct
7 Correct 2 ms 14428 KB Output is correct
8 Correct 3 ms 14428 KB Output is correct
9 Correct 2 ms 14428 KB Output is correct
10 Correct 2 ms 14428 KB Output is correct
11 Correct 3 ms 14428 KB Output is correct
12 Correct 4 ms 14428 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 4 ms 14428 KB Output is correct
15 Correct 2 ms 14472 KB Output is correct
16 Correct 3 ms 14428 KB Output is correct
17 Correct 2 ms 14428 KB Output is correct
18 Execution timed out 3060 ms 18212 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Correct 3 ms 14428 KB Output is correct
3 Correct 3 ms 14428 KB Output is correct
4 Correct 4 ms 14540 KB Output is correct
5 Correct 4 ms 14428 KB Output is correct
6 Correct 2 ms 14428 KB Output is correct
7 Correct 2 ms 14428 KB Output is correct
8 Correct 3 ms 14428 KB Output is correct
9 Correct 2 ms 14428 KB Output is correct
10 Correct 2 ms 14428 KB Output is correct
11 Correct 3 ms 14428 KB Output is correct
12 Correct 4 ms 14428 KB Output is correct
13 Correct 5 ms 14428 KB Output is correct
14 Correct 4 ms 14428 KB Output is correct
15 Correct 2 ms 14472 KB Output is correct
16 Correct 3 ms 14428 KB Output is correct
17 Correct 2 ms 14428 KB Output is correct
18 Execution timed out 3060 ms 18212 KB Time limit exceeded
19 Halted 0 ms 0 KB -