답안 #869449

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869449 2023-11-04T11:25:57 Z lolismek Stranded Far From Home (BOI22_island) C++14
0 / 100
476 ms 52256 KB
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>

#define pii pair <int, int>


using namespace std;

//ifstream fin("input.in");
//ofstream fout("output.out");

#define fin cin
#define fout cout

const int NMAX = 2e5;

int v[NMAX + 1];
vector <int> adj[NMAX + 1];

int par[NMAX + 1];
int sum[NMAX + 1];

int Find(int x){
    if(x == par[x]){
        return x;
    }
    return par[x] = Find(par[x]);
}

void Join(int x, int y){
    x = par[x];
    y = par[y];

    par[x] = y;
    sum[y] += sum[x];
}

bool ins[NMAX + 1];

void Insert(int x){
    ins[x] = true;
    for(int vec : adj[x]){
        if(ins[vec]){
            Join(vec, x);
        }
    }
}

bool ans[NMAX + 1];

vector <int> inds[NMAX + 1];

int wher[NMAX + 1];
vector <int> quer[NMAX + 1];

int main(){

    int n, m;
    fin >> n >> m;

    priority_queue <pii, vector <pii>, greater <pii>> pq;

    vector <int> vals;
    for(int i = 1; i <= n; i++){
        fin >> v[i];
        par[i] = i;
        sum[i] = v[i];
        vals.push_back(v[i]);
        ans[i] = 1;
    }

    for(int i = 1; i <= m; i++){
        int a, b;
        fin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());

    map <int, int> norm;
    for(int i = 0; i < (int)vals.size(); i++){
        norm[vals[i]] = i;
    }

    for(int i = 1; i <= n; i++){
        inds[norm[v[i]]].push_back(i);
        quer[norm[v[i]]].push_back(i);
        wher[i] = norm[v[i]];
    }

    for(int val = 0; val < (int)vals.size(); val++){
        for(int ind : inds[val]){
            Insert(ind);
        }

        for(int x : quer[val]){
            int s = sum[Find(x)];
            int st = 0, dr = (int)vals.size() - 1, a = 0;
            while(st <= dr){
                int mid = (st + dr) / 2;
                if(vals[mid] <= s){
                    a = mid;
                    st = mid + 1;
                }else{
                    dr = mid - 1;
                }
            }

            if(a > val){
                wher[x] = a;
                quer[a].push_back(x);
            }
        }
    }

    for(int i = 1; i <= n; i++){
        if(wher[i] == (int)vals.size() - 1){
            fout << 1;
        }else{
            fout << 0;
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17240 KB Output is correct
2 Correct 3 ms 17240 KB Output is correct
3 Correct 3 ms 17076 KB Output is correct
4 Incorrect 5 ms 17500 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17244 KB Output is correct
2 Correct 3 ms 17244 KB Output is correct
3 Incorrect 315 ms 52116 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17244 KB Output is correct
2 Incorrect 476 ms 52256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 17240 KB Output is correct
2 Incorrect 204 ms 32164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17240 KB Output is correct
2 Correct 3 ms 17240 KB Output is correct
3 Correct 3 ms 17076 KB Output is correct
4 Incorrect 5 ms 17500 KB Output isn't correct
5 Halted 0 ms 0 KB -