답안 #714614

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714614 2023-03-25T06:38:36 Z aykhn Stranded Far From Home (BOI22_island) C++14
0 / 100
276 ms 15768 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;
        if (i == 1) x = 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;

    ll sum = 0;
    while (l < r)
    {
        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;
            }
        }
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 253 ms 14720 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 276 ms 15768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -