이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Normie's Template v2.0
*/
// Standard library in one include.
#include <bits/stdc++.h>
using namespace std;
// ordered_set library.
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set(el) tree<el,null_type,less<el>,rb_tree_tag,tree_order_statistics_node_update>
// AtCoder library. (Comment out these two lines if you're not submitting in AtCoder.) (Or if you want to use it in other judges, run expander.py first.)
//#include <atcoder/all>
//using namespace atcoder;
//Pragmas (Comment out these three lines if you're submitting in szkopul.)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//File I/O.
#define FILE_IN "cseq.inp"
#define FILE_OUT "cseq.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
//Fast I/O.
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define endl "\n"
//Order checking.
#define ord(a,b,c) ((a>=b)and(b>=c))
//min/max redefines, so i dont have to resolve annoying compile errors.
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
//Constants.
#define MOD (ll(998244353))
#define MAX 300001
#define mag 320
//Pairs and 3-pairs.
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pii(element_type) pair<element_type,element_type>
#define piii(element_type) pair<element_type,pii(element_type)>
//Quick power of 2.
#define pow2(x) (ll(1)<<x)
//Short for-loops.
#define ff(i,__,___) for(int i=__;i<=___;i++)
#define rr(i,__,___) for(int i=__;i>=___;i--)
//Typedefs.
#define bi BigInt
typedef long long ll;
typedef long double ld;
typedef short sh;
//---------END-------//
vector<ll> loc;
vector<ll> add;
vector<ll> slop;
ll n,m,i,j,k,t,t1,u,v,a,b;
ll shft,fin=1e18;
vector<pii(ll)> lis;
char c1,c2;
void reset()
{
for (ll i=0;i<add.size();i++) add[i]=0;
for (ll i=0;i<add.size();i++) slop[i]=0;
}
void addbf(ll i, ll d)
{
ll x=loc[i];
add[0]+=min(d,x-loc[0]);
ll u=lower_bound(loc.begin(),loc.end(),x-d)-loc.begin();
slop[u]-=1;
slop[i]+=1;
if (u) add[u]-=loc[u]-(x-d);
}
void addaf(ll i, ll d)
{
ll x=loc[i];
slop[i]+=1;
ll u=upper_bound(loc.begin(),loc.end(),x+d)-loc.begin()-1;
slop[u]-=1;
if (u<loc.size()-1) add[u+1]+=(x+d)-loc[u];
}
ll get()
{
ll cur=0,cur_slop=0,minn=1e18;
for (ll i=0;i<loc.size();i++)
{
if (i)
{
cur+=cur_slop*(loc[i]-loc[i-1]);
}
cur+=add[i];
minn=min(minn,cur);
cur_slop+=slop[i];
}
return minn;
}
int main()
{
fio;
cin>>t>>n;
for (i=1;i<=n;i++)
{
cin>>c1>>a>>c2>>b;
if (c1==c2)
{
shft+=abs(a-b);
}
else
{
shft+=abs(a-b);
shft++;
if (a>b) swap(a,b);
lis.push_back({a,b});
loc.push_back(a);
loc.push_back(b);
}
}
sort(loc.begin(),loc.end());
auto last=unique(loc.begin(),loc.end());
loc.erase(last, loc.end());
for (ll g : loc) {add.push_back(0); slop.push_back(0);}
if (t==1)
{
for (auto g : lis)
{
u=lower_bound(loc.begin(),loc.end(),g.fi)-loc.begin();
addbf(u,1e9);
u=lower_bound(loc.begin(),loc.end(),g.se)-loc.begin();
addaf(u,1e9);
}
fin=get();
if (fin==1e18) fin=0;
cout<<shft+fin*2;
}
else
{
for (i=0;i<loc.size();i++)
{
reset();
for (auto g : lis)
{
if (loc[i]>g.se) a=loc[i]-g.se;
else if (loc[i]<g.fi) a=-loc[i]+g.fi;
else a=0;
u=lower_bound(loc.begin(),loc.end(),g.fi)-loc.begin();
addbf(u,a);
u=lower_bound(loc.begin(),loc.end(),g.se)-loc.begin();
addaf(u,a);
}
b=get();
fin=min(fin,b);
}
if (fin==1e18) fin=0;
cout<<shft+fin*2;
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp:20: warning: ignoring #pragma comment [-Wunknown-pragmas]
20 | #pragma comment(linker, "/stack:200000000")
|
bridge.cpp: In function 'void reset()':
bridge.cpp:77:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (ll i=0;i<add.size();i++) add[i]=0;
| ~^~~~~~~~~~~
bridge.cpp:78:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (ll i=0;i<add.size();i++) slop[i]=0;
| ~^~~~~~~~~~~
bridge.cpp: In function 'void addaf(ll, ll)':
bridge.cpp:95:7: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | if (u<loc.size()-1) add[u+1]+=(x+d)-loc[u];
| ~^~~~~~~~~~~~~
bridge.cpp: In function 'll get()':
bridge.cpp:100:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (ll i=0;i<loc.size();i++)
| ~^~~~~~~~~~~
bridge.cpp: In function 'int main()':
bridge.cpp:136:11: warning: unused variable 'g' [-Wunused-variable]
136 | for (ll g : loc) {add.push_back(0); slop.push_back(0);}
| ^
bridge.cpp:152:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
152 | for (i=0;i<loc.size();i++)
| ~^~~~~~~~~~~
# | 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... |