이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
using namespace std;
char c, d;
int a, b, n, i, j, k;
long long ans, res, ans2=1e18;
struct st
{
int a, b;
};
vector<st>v;
bool cmp(st a, st b)
{
return a.a+a.b<b.a+b.b;
}
main()
{
ios_base::sync_with_stdio(!cin.tie(NULL));
for(cin>>k>>n;i++<n;)
{
cin>>c>>a>>d>>b;
if(c==d)ans+=abs(b-a);
else ans++,v.push_back({a, b});
}
sort(v.begin(), v.end(), cmp);
for(i=0;i<=v.size();i++)
{
vector<int>V;res=0;
for(j=0;j<i;j++)
{
V.push_back(v[j].a);V.push_back(v[j].b);
}
sort(V.begin(), V.end());
for(k=0;k<V.size()/2;k++)res-=V[k];
for(k=V.size()/2;k<V.size();k++)res+=V[k];
V.clear();
for(j=i;j<v.size();j++)
{
V.push_back(v[j].a);V.push_back(v[j].b);
}
sort(V.begin(), V.end());
for(k=0;k<V.size()/2;k++)res-=V[k];
for(k=V.size()/2;k<V.size();k++)res+=V[k];
ans2=min(ans2, res);
}
cout<<ans+ans2;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp:16:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main()
| ^
bridge.cpp: In function 'int main()':
bridge.cpp:26:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(i=0;i<=v.size();i++)
| ~^~~~~~~~~~
bridge.cpp:34:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(k=0;k<V.size()/2;k++)res-=V[k];
| ~^~~~~~~~~~~
bridge.cpp:35:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(k=V.size()/2;k<V.size();k++)res+=V[k];
| ~^~~~~~~~~
bridge.cpp:37:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<st>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(j=i;j<v.size();j++)
| ~^~~~~~~~~
bridge.cpp:42:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(k=0;k<V.size()/2;k++)res-=V[k];
| ~^~~~~~~~~~~
bridge.cpp:43:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(k=V.size()/2;k<V.size();k++)res+=V[k];
| ~^~~~~~~~~
# | 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... |