Submission #794310

# Submission time Handle Problem Language Result Execution time Memory
794310 2023-07-26T12:26:22 Z TahirAliyev Stranded Far From Home (BOI22_island) C++17
0 / 100
241 ms 14456 KB
#include <bits/stdc++.h>
 
#pragma GCC optimize("O3")
 
using namespace std;
 
#define ll long long int
#define oo 4e18
#define pii pair<int, int>

const int MAX = 2e5 + 5;

ll Presum[MAX];
int arr[MAX];
int ans[MAX];

int main(){
    int n, m; cin >> n >> m;
    vector<pii> v;
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
        Presum[i] = Presum[i - 1] + arr[i];
        v.push_back({arr[i], i});
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for (int i = 0; i < m; i++)
    {
        int a, b; cin >> a >> b;
    }
    set<int> s;
    s.insert(0);
    s.insert(n + 1);
    s.insert(v[0].second);
    
    ans[v[0].second] = 1;
    for(pii &a: v){
        auto itr = s.upper_bound(a.second);
        int l = (*(prev(itr)));
        int r = (*itr);
        s.insert(a.second);
        if(arr[l] == a.first){
            ans[a.second] = ans[l];
            continue;
        }
        if(arr[r] == a.first){
            ans[a.second] = ans[r];
            continue;
        }
        ll sum = Presum[r - 1] - Presum[l];
        if((sum >= arr[l] && sum >= arr[r]) || (sum >= arr[l] && ans[l]) || (sum >= arr[r] && ans[r])){
            ans[a.second] = 1;
            continue;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i];
    }
    
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 207 ms 14456 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 241 ms 14400 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 224 ms 14448 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 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 3 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -