Submission #714612

# Submission time Handle Problem Language Result Execution time Memory
714612 2023-03-25T06:37:53 Z aykhn Stranded Far From Home (BOI22_island) C++14
0 / 100
275 ms 13204 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
                    cout << v[i] << " "; \
                    cout<<endl;

/*
int ternarySearch(int l, int r, int key, int ar[])
{
    if (r >= l)
    {
        int mid1 = l + (r - l) / 3;
        int mid2 = r - (r - l) / 3;

        if (ar[mid1] == key) {
            return mid1;
        }
        if (ar[mid2] == key) {
            return mid2;
        }
        if (key < ar[mid1]) {
            return ternarySearch(l, mid1 - 1, key, ar);
        }
        else if (key > ar[mid2]) {
            return ternarySearch(mid2 + 1, r, key, ar);
        }
        else {
            return ternarySearch(mid1 + 1, mid2 - 1, key, ar);
        }
    }
    return -1;
}
*/

struct DSU {
	vector<int> e;

	void init(int n)
	{
	    e.assign(n, -1);
	}

	int get(int x)
	{
	    if (e[x] < 0)
            return x;
        return e[x] = get(e[x]);
	}

	bool together(int a, int b)
	{
	    return get(a) == get(b);
    }

	int s(int x)
	{
	    return -e[get(x)];
    }

	bool unite(int x, int y)
	{
		x = get(x);
        y = get(y);

		if (x == y) return false;

		if (e[x] > e[y]) swap(x, y);

		e[x] += e[y];
		e[y] = x;

		return true;
	}
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pii> v(n);
    vector<vector<int>> adj(n + 1);
    int x;
    cin >> x;

    for (int i = 1; i < n; i++)
    {
        cin >> v[i].fi;
        if (i == 1) x = v[i].fi;
        v[i].se = i;
    }

    sort(v.begin() + 1, v.end());

    while (m--)
    {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    int l = 1;
    int r = n - 1;

    int sum = 0;
    while (l < r)
    {
        int mid = ((l + r) >> 1);

        if (v[mid].fi < x)
        {
            l = mid + 1;
            continue;
        }
        sum = v[mid].fi + x;

        bool flag = false;

        for (int i = 1; i < n; i++)
        {
            if (i == mid) continue;

            if (sum < v[i].fi)
            {
                flag = true;
                break;
            }
        }
        if (!flag) l = mid + 1;
        else r = mid;
    }
    sum = x;
    bool flag = false;
    for (int i = 1; i < n; i++)
    {
        if (sum < v[i].fi)
        {
            flag = true;
            break;
        }
    }
    string s;
    if (flag)
    {
        s.pb('0');
    }
    else
    {
        s.pb('1');
    }

    for (int i = 1; i < n; i++) s.pb('0');

    for (int i = l; i < n; i++)
    {
        s[v[i].se] = '1';
    }

    cout << s << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 250 ms 13172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 275 ms 13204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -