답안 #221191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
221191 2020-04-09T16:39:27 Z Haunted_Cpp Džumbus (COCI19_dzumbus) C++17
0 / 110
52 ms 2420 KB
#include <bits/stdc++.h> 
 
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
using namespace std::chrono;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};

const int N = 1e3 + 5;

struct E {
  int st, et;
  i64 custo;
  int profit;
  bool operator < (E Other) const {
    return custo * (profit == 1 ? 2 : 1) < Other.custo * (profit == 1 ? 2 : 1);
  }
};

i64 cost [N];
bool paid [N];

vvi g (N);

/*
int parent [N], tamanho [N];

int root (int x) { while (x != parent[x]) x = parent[x]; return x; }
bool is_connected (int a, int b) { return (root (a) == root (b)); }
void join (int a, int b) {
  a = root (a);
  b = root (b);
  if (a == b) return;
  if (tamanho[a] < tamanho[b]) swap (a, b);
  tamanho[a] += tamanho[b];
  parent[b] = a;
}
*/

 

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  F0R (i, n) cin >> cost[i];
  vector<E> edge (m);
  F0R (i, m) {
    int st, et;
    cin >> st >> et;
    --st; --et;
    g[st].eb(et);
    g[et].eb(st);
    E add = {st, et, cost[st] + cost[et], 2};
    edge[i] = add;
  }
  sort (all(edge));
  vector<pair<i64, int> > ans;
  i64 cur = 0;
  int score = 0;
  while (!edge.empty()) {
    cur += edge.front().custo;
    score += edge.front().profit;
    ans.eb(cur, score);
    paid[edge.front().st] = paid[edge.front().et] = true;
    vector<E> Get;
    F0R (i, n) {
      int st = i;
      GO (et, g[i]) {
        if (paid[st] && paid[et]) continue;
        int profit = !paid[st] + !paid[et];
        E add = {st, et, cost[st] * !paid[st] + cost[et] * !paid[et], profit};
        Get.eb(add);
      }
    }
    sort (all(Get));
    edge = Get;
  }
  
  int q;
  cin >> q;
  while (q--) {
    int budget;
    cin >> budget;
    if (ans.empty() || budget < ans.front().f) {
      cout << 0 << '\n';
      continue;
    }
    int lo = 0, hi = sz(ans);
    while (lo < hi) {
      int mid = lo + (hi - lo) / 2;
      if (ans[mid].f > budget) hi = mid;
      else lo = mid + 1;
    }
    cout << ans[hi - 1].s << '\n';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 2420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -