답안 #614241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
614241 2022-07-30T23:09:38 Z Plurm Stranded Far From Home (BOI22_island) C++11
10 / 100
412 ms 15556 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int s[200005];
vector<int> g[200005];
int n, m;
bool check(int u) {
  priority_queue<pair<int, int>> pq;
  long long allies = s[u];
  gp_hash_table<int, null_type> alliance;
  alliance.insert(u);
  for (int v : g[u])
    pq.push({-s[v], v});
  while (!pq.empty()) {
    int vnxt = pq.top().second;
    pq.pop();
    if (alliance.find(vnxt) != alliance.end())
      continue;
    if (s[vnxt] <= allies) {
      allies += 1ll * s[vnxt];
      alliance.insert(vnxt);
      for (int v : g[vnxt]) {
        if (alliance.find(v) == alliance.end()) {
          pq.push({-s[v], v});
        }
      }
    } else {
      return false;
    }
  }
  return true;
}
int par[200005];
long long qs[200005];
int suff[200005];
bool dp[200005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", s + i);
    qs[i] = qs[i - 1] + s[i];
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (n > 2000) {
    suff[n + 1] = n + 1;
    for (int i = n; i > 0; i--) {
      par[i] = i;
      for (int j : g[i]) {
        if (j < i)
          par[i] = min(par[i], j);
      }
      suff[i] = min(suff[i + 1], par[i]);
      suff[i] = min(suff[i], suff[suff[i]]);
    }
    dp[1] = true;
    for (int i = 2; i <= n; i++) {
      dp[i] = (qs[n] - qs[i - 1]) >= s[i - 1] ? dp[i - 1] : false;
    }
    for (int i = 1; i <= n; i++) {
      if (dp[suff[i]])
        printf("1");
      else
        printf("0");
    }
    printf("\n");
  } else {
    for (int i = 1; i <= n; i++) {
      if (check(i))
        printf("1");
      else
        printf("0");
    }
    printf("\n");
  }
  return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
island.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d", s + i);
      |     ~~~~~^~~~~~~~~~~~~
island.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%d%d", &u, &v);
      |     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 251 ms 5076 KB Output is correct
5 Correct 209 ms 5156 KB Output is correct
6 Correct 412 ms 5140 KB Output is correct
7 Correct 272 ms 5156 KB Output is correct
8 Correct 197 ms 5152 KB Output is correct
9 Correct 282 ms 5128 KB Output is correct
10 Correct 98 ms 5152 KB Output is correct
11 Correct 90 ms 5076 KB Output is correct
12 Correct 153 ms 5152 KB Output is correct
13 Correct 165 ms 5152 KB Output is correct
14 Correct 145 ms 5156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 125 ms 15556 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 117 ms 15504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 147 ms 15532 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 251 ms 5076 KB Output is correct
5 Correct 209 ms 5156 KB Output is correct
6 Correct 412 ms 5140 KB Output is correct
7 Correct 272 ms 5156 KB Output is correct
8 Correct 197 ms 5152 KB Output is correct
9 Correct 282 ms 5128 KB Output is correct
10 Correct 98 ms 5152 KB Output is correct
11 Correct 90 ms 5076 KB Output is correct
12 Correct 153 ms 5152 KB Output is correct
13 Correct 165 ms 5152 KB Output is correct
14 Correct 145 ms 5156 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Incorrect 125 ms 15556 KB Output isn't correct
18 Halted 0 ms 0 KB -