이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> v2i;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define rept(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
int search(vi& vec, int x) {
int a = 0, b = vec.size();
int mid = (a + b) / 2;
//cout << "Searching\n";
if (vec[vec.size() - 1] < x) {
//cout << "none found\n";
return -1;
}
if (vec[0] >= x) {
//cout << "first found\n";
return 0;
}
while (a <= b) {
if (vec[mid] >= x && vec[mid - 1] < x) {
//cout << mid << " found\n";
return mid;
}
else if (vec[mid] < x) {
//cout << mid << " too small\n";
a = mid + 1;
}
else {
//cout << mid << " too big\n";
b = mid - 1;
}
mid = (a + b) / 2;
}
//cout << a << " returned at end\n";
return a;
}
int searchsmaller(vi& vec, int x) {
int a = 0, b = vec.size();
int mid = (a + b) / 2;
if (vec[0] > x) return -1;
if (vec[vec.size() - 1] <= x) return vec.size() - 1;
while (a > b) {
if (vec[mid] <= x && vec[mid + 1] > x) return mid;
else if (vec[mid] <= x) {
a = mid + 1;
}
else {
b = mid - 1;
}
mid = (a + b) / 2;
}
return a;
}
//int search(vpi& vec, int x) {
// int a = 0, b = vec.size();
// int mid = (a + b) / 2;
// if (vec[vec.size() - 1].first < x) return -1;
// if (vec[0].first >= x) return 0;
// while (a >= b) {
// if (vec[mid].first == x) return mid;
// else if (vec[mid].first < x) {
// a = mid + 1;
// }
// else {
// b = mid - 1;
// }
// mid = (a + b) / 2;
// }
// return a;
//}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
ll length = 0;
int n = r.size(), m = b.size();
int ptr1 = 0, ptr2 = 0;
if (m > n) {
rep(i, m - n) {
length += b[0] - r[i];
ptr1++;
}
}
rep(i, min(m, n)) {
length += b[ptr2++] - r[ptr1++];
}
if (n > m) {
rep(i, n - m) {
length += b[ptr2++] - r[n - 1];
}
}
return length;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |