이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define int long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "vrtic"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int mod2=1e9+7;
const int mod1=998244353;
struct ib
{
int a;
int b;
};
struct icd
{
int a,b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
int n,m,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l;
int i,s10,s12;
int el=29;
main()
{
//#ifndef ONLINE_JUDGE
// fin(task),fou(task);
//#endif
NHP
//modwwe
// cin>>res;
phongbeo(),down
checktime
}
int dp[100001];
ib a[100001];
struct cmp{
bool operator()(int a,int b)
{
return a>b;
}
};
struct cmp2{
bool operator()(int a,int b)
{
return a<b;
}
};
priority_queue<int,vector<int>,cmp2>p;
priority_queue<int,vector<int>,cmp>p2;
void get()
{
if(p.top()>p2.top())
{ s5=p.top();
s6=p2.top();
s2=s2+s5*2;
s2=s2-s6*2;
s3+=s5;
s3-=s6;
s4+=s6;
s4-=s5;
p2.push(s5);
p.push(s6);
p2.pop();
p.pop();
}
}
bool cmp3(ib a,ib b)
{
return a.a+a.b<b.a+b.b;
}
void phongbeo()
{
cin>>k>>n;
for(int i=1;i<=n;i++)
{
string ss,sx;
cin>>ss>>l>>sx>>r;
if(ss==sx)
{
s8+=abs(r-l);
continue;
}
a[++dem]={l,r};
}
sort(a+1,a+1+dem,cmp3);
for(int i=1;i<=dem;i++)
{
s2+=abs(a[i].a-a[i].b);
p.push(min(a[i].b,a[i].a));
s3+=max(a[i].a,a[i].b);
s4+=min(a[i].a,a[i].b);
p2.push(max(a[i].b,a[i].a));
get();
dp[i]=s2;
}
if(k==1){
cout<<s2+dem+s8;
exit(0);}
else
{
while(!p.empty())
{
p.pop();
}
while(!p2.empty())
{
p2.pop();
}
s2=0;
s7=dp[dem];
for(int i=dem;i>=1;--i)
{ s2+=abs(a[i].a-a[i].b);
p.push(min(a[i].b,a[i].a));
p2.push(max(a[i].b,a[i].a));
get();
s7=min(s7,s2+dp[i-1]);
}
cout<<s7+dem+s8;
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
39 | main()
| ^~~~
# | 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... |