답안 #1050968

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050968 2024-08-09T17:26:46 Z sofijavelkovska Stranded Far From Home (BOI22_island) C++17
40 / 100
1000 ms 21712 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN=2e5, INF=2e9;

int n, m;
int a[MAXN];
vector<int> adj[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    for (int i=0; i<n; i++)
        cin >> a[i];
    for (int i=0; i<m; i++)
    {
        int x, y;
        cin >> x >> y;
        adj[x-1].push_back(y-1);
        adj[y-1].push_back(x-1);
    }
    set<int> values;
    for (int i=0; i<n; i++)
        values.insert(-a[i]);
    bool possible[n]={false};
    queue<int> q;
    for (auto kt : values)
    {
        int k=-kt;
        bool visited[n]={false};
        for (int i=0; i<n; i++)
        {
            if (a[i]!=k || visited[i])
                continue;
            visited[i]=true;
            long long sum=a[i];
            q.push(i);
            vector<int> nodes;
            nodes.push_back(i);
            int minsum=INF;
            while (!q.empty())
            {
                int x=q.front();
                q.pop();
                for (auto y : adj[x])
                {
                    if (a[y]<=k && !visited[y])
                    {
                        visited[y]=true;
                        sum=sum+a[y];
                        q.push(y);
                        if (a[y]==k)
                            nodes.push_back(y);
                    }
                    if (a[y]>k && possible[y])
                        minsum=min(minsum, a[y]);
                }
            }
            if (minsum>sum && k!=-(*values.begin()))
                continue;
            for (auto x : nodes)
                possible[x]=true;
        }
    }
    for (int i=0; i<n; i++)
        cout << possible[i];

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 15 ms 5300 KB Output is correct
5 Correct 5 ms 5212 KB Output is correct
6 Correct 1 ms 5212 KB Output is correct
7 Correct 12 ms 5212 KB Output is correct
8 Correct 12 ms 5212 KB Output is correct
9 Correct 1 ms 5212 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5212 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 1 ms 5212 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Execution timed out 1091 ms 21712 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Execution timed out 1098 ms 21672 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 84 ms 12748 KB Output is correct
3 Correct 93 ms 12780 KB Output is correct
4 Correct 95 ms 12840 KB Output is correct
5 Correct 58 ms 13768 KB Output is correct
6 Correct 54 ms 13332 KB Output is correct
7 Correct 47 ms 15488 KB Output is correct
8 Correct 45 ms 13376 KB Output is correct
9 Correct 55 ms 10184 KB Output is correct
10 Correct 60 ms 13712 KB Output is correct
11 Correct 73 ms 12880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 15 ms 5300 KB Output is correct
5 Correct 5 ms 5212 KB Output is correct
6 Correct 1 ms 5212 KB Output is correct
7 Correct 12 ms 5212 KB Output is correct
8 Correct 12 ms 5212 KB Output is correct
9 Correct 1 ms 5212 KB Output is correct
10 Correct 4 ms 5212 KB Output is correct
11 Correct 4 ms 5212 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 1 ms 5212 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Execution timed out 1091 ms 21712 KB Time limit exceeded
18 Halted 0 ms 0 KB -