Submission #714703

# Submission time Handle Problem Language Result Execution time Memory
714703 2023-03-25T08:10:38 Z aykhn Stranded Far From Home (BOI22_island) C++14
0 / 100
269 ms 15812 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()
{
    ll n, m;
    cin >> n >> m;
    vector<pll> v(n);
    vector<vector<ll>> adj(n + 1);
    ll x;
    cin >> x;

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

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

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

    ll l = 1;
    ll r = n - 1;

    while (l < r)
    {
        ll sum = 0;
        ll 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;
            }
            sum += v[i].fi;
        }
        if (flag) l = mid + 1;
        else r = mid;
    }
    ll sum = x;
    bool flag = false;
    for (int i = 1; i < n; i++)
    {
        if (sum < v[i].fi)
        {
            flag = true;
            break;
        }
        sum += v[i].fi;
    }
    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 1 ms 212 KB Output is correct
2 Incorrect 248 ms 14740 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 269 ms 15812 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 -