제출 #1062763

#제출 시각아이디문제언어결과실행 시간메모리
1062763pravcoder전선 연결 (IOI17_wiring)C++17
0 / 100
1 ms348 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...