답안 #795996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795996 2023-07-28T03:54:32 Z NeroZein The Potion of Great Power (CEOI20_potion) C++17
0 / 100
39 ms 49340 KB
#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9; 

int getDis (vector<int> h1, vector<int> h2) {
  if (h1.empty() || h2.empty()) {
    return INF; 
  }
  int ret = INF; 
  int i = 0, j = 0;
  int n = h1.size(), m = h2.size();
  while (i < n || j < m) {
    if (i < n && (j == m || h1[i] < h2[j])) {
      if (j < m) {
        ret = min(ret, h2[j] - h1[i]);        
      }
      i++;
    } else {
      if (i < n) {
        ret = min(ret, h1[i] - h2[j]);         
      }
      j++; 
    }
  }
  return ret;
}

const int MX_N = 1e3 + 5;
const int MX_DAYS = 1e3 + 5;

int h[MX_N];
vector<int> friends[MX_DAYS][MX_N];

void invert (int day, int u, int v) {
  auto ite = find(friends[day][u].begin(), friends[day][u].end(), v); 
  if (ite != friends[day][u].end()) {//erase
    friends[day][u].erase(ite);
    ite = find(friends[day][v].begin(), friends[day][v].end(), u);
    friends[day][v].erase(ite);
  } else {
    int n = friends[day][u].size();
    int m = friends[day][v].size();
    bool inserted_v = false;
    for (int i = 0; i < n; ++i) {
      if (h[friends[day][u][i]] > h[v]) {
        inserted_v = true;
        friends[day][u].insert(friends[day][u].begin() + i, v);
      }
    }
    if (!inserted_v) {
      //cout << "V: " << v << ' ' << friends[day][u].size() << endl; 
      friends[day][u].push_back(v);
    }
    bool inserted_u = false;
    for (int i = 0; i < m; ++i) {
      if (h[friends[day][v][i]] > h[u]) {
        inserted_u = true;
        friends[day][v].insert(friends[day][v].begin() + i, u);        
      }
    }
    if (!inserted_u) {
      //cout << "U: " << u << ' ' << friends[day][v].size() << endl;
      friends[day][v].push_back(u); 
    }
    //cout << '\n';
  }
}

int ppl;

void init(int N, int D, int H[]) {
  ppl = N;
  for (int i = 0; i < N; ++i) {
    h[i] = H[i];
  }
}

void curseChanges(int U, int A[], int B[]) {
  for (int day = 1; day <= U; ++day) {
    for (int person = 0; person < ppl; ++person) {
      friends[day][person] = friends[day - 1][person];      
    }
    invert(day, A[day - 1], B[day - 1]); 
  }
}

int question(int x, int y, int v) {//p1, p2, day
  if (x == y) {
    return 0;
  }
  vector<int> h1, h2;
  for (int i : friends[v][x]) {
    h1.push_back(h[i]);
  }
  for (int i : friends[v][y]) {
    h2.push_back(h[i]);
  }
  return getDis(h1, h2); 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 24016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 41960 KB Output is correct
2 Correct 37 ms 42116 KB Output is correct
3 Correct 37 ms 41732 KB Output is correct
4 Runtime error 39 ms 49232 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 49340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 49340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 48588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 24016 KB Output is correct
2 Correct 35 ms 41960 KB Output is correct
3 Correct 37 ms 42116 KB Output is correct
4 Correct 37 ms 41732 KB Output is correct
5 Runtime error 39 ms 49232 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -