이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <chrono>
#define ll long long
#define ull unsigned long long
#define ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf 1e15
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
using namespace std;
using namespace std::chrono;
/*auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop - start);
cout << "Time taken by function: "
<< duration.count() << " microseconds" << endl;*/
const int maxn = 2e5+5;
int a[maxn];
int b[maxn];
int main(){
int n,m;
cin >> n >> m;
for(int i = 0;i<n+m-1;i++){
cin >> a[i];
}
for(int i = 0;i<n+m-1;i++){
cin >> b[i];
}
if(n!=1){
ll ans1 = 0;
ll ans2 = 0;
ll ans = 0;
if(n+m>4){
a[n+m-2]=min(a[n+m-2],b[n+m-4]);
a[0]=min(a[0],b[(n+m-1)/2-(n+m-1)%2]);
b[0]=min(b[0],a[(n+m-1)/2-(n+m-1)%2]);
b[n+m-2]=min(b[n+m-2],a[n+m-4]);
}
/*for(int i = 0;i<n+m-1;i++) cout<<a[i]<<" ";
cout<<"\n";
for(int i = 0;i<n+m-1;i++) cout<<b[i]<<" ";
cout<<"\n";*/
for(int i = 1;i<n+m-1;i+=2){
ans1+=a[i];
}
for(int i = 1;i<n+m-1;i+=2){
ans2+=b[i];
}
ans+=min(ans2,ans1);
//cout<<ans1<< " "<<ans2<<"\n";
ans1 = 0;
ans2 = 0;
for(int i = 0;i<n+m-1;i+=2){
ans1+=a[i];
}
for(int i = 0;i<n+m-1;i+=2){
ans2+=b[i];
}
//cout<<ans1<< " "<<ans2<<"\n";
ans+=min(ans1,ans2);
cout<<ans;
}else if(n==1){
ll ans = 0;
for(int i = 0;i<m+n-1;i++){
ans+=min(a[i],b[m+n-i-2]);
}
cout<<ans;
}else{
cout<<0;
}
}
/*1 5
3 2 3 5 7
1 3 5 2 4*/
컴파일 시 표준 에러 (stderr) 메시지
colouring.cpp:5:9: warning: ISO C++11 requires whitespace after the macro name
5 | #define ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
| ^~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |