# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
391215 | Andyvanh1 | Unscrambling a Messy Bug (IOI16_messy) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
using namespace std;
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define vt vector
#define pb push_back
typedef long long ll;
typedef vt<int> vi;
vt<pair<int,int>> edges;
vt<ll> weights;
const int mxN=5e5+1, M=1e9+7;
int n, m, p[mxN];
int find(int x) {
return x^p[x]?p[x]=find(p[x]):x;
}
bool join(int x, int y) {
if((x=find(x))==(y=find(y)))
return 0;
p[find(x)]=find(y);
return 1;
}
ll prim(){
for(int i = 0; i < 200001; i++){
p[i] = i;
}
priority_queue<pair<ll,pair<int,int>>,vt<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq;
for(int i = 0; i < edges.size(); i++){
pq.push({weights[i],{edges[i].first,edges[i].second}});
}
ll ans = 0;
while(!pq.empty()){
auto e = pq.top();
pq.pop();
if(find(e.second.first)!=find(e.second.second)){
join(e.second.first,e.second.second);
ans+=e.first;
}
}
return ans;
}
ll min_total_length(vi r, vi b){
int n = r.size();
int m = b.size();
ll ans = 0;
if(b[0]>r[n-1]) {
ans += (ll) max(n, m) * (b[0] - r[n - 1]);
for (int i = 0; i < n; i++) {
ans += r[n - 1] - r[i];
}
for (int i = 0; i < m; i++) {
ans += b[i] - b[0];
}
return ans;
}else{
ll dp[n][m];
dp[0][0] = abs(r[0]-b[0]);
for(int i = 0; i < n; i++){
for(int j = (i?0:1); j < m; j++){
if(i==0){
dp[i][j] = dp[i][j-1]+abs(b[j]-r[i]);
}else if(j==0){
dp[i][j] = dp[i-1][j]+abs(b[j]-r[i]);
}else{
dp[i][j] = min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1]))+abs(b[j]-r[i]);
}
}
}
return dp[n-1][m-1];
}
}
vi restore_permutation(int n , int w, int r){
string s = "";
string s1 = "";
for(int i = 0; i < n; i++){
s+="0";
s1+="1";
}
for(int i = 0; i < n; i++){
add_element(s1.substr(0,i+1)+s.substr(i+1));
}
compile_set();
vi p;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
bool nh = false;
for(auto& e: p){
if(e==j){nh = true;
break;
}
}
if(nh)continue;
bool bol = check_element(s.substr(0,j)+"1"+s.substr(j+1));
if(bol){
p.pb(j);
s = s.substr(0,j)+"1"+s.substr(j+1);
break;
}
}
}
return p;
}