이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
#define ll long long
#define sc second
#define fr first
#define pb push_back
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w){
bool sb1=1,sb2=1,sb3=1;
for(int i=0;i<m;i++){
sb1&=(x[i]%2==0);
sb2&=(x[i]<=1);
sb3&=(y[i]==0);
}
if(sb1){
ll sum=0;
for(int i=0;i<m;i++) sum+=w[i];
return sum;
}
if(sb2){
vector<ll> a(n),b(n);
ll A=0,B=0;
for(int i=0;i<m;i++){
if(x[i]==0){
A+=w[i];
a[y[i]]=w[i];
}
else{
B+=w[i];
b[y[i]]=w[i];
}
}
if(n==2) return max(A,B);
ll x=0,y=B;
for(int i=0;i<n;i++){
x+=a[i];
y-=b[i];
B=max(B,x+y);
}
return B;
}
if(sb3){
vector<int> id(m);
iota(id.begin(),id.end(),0);
sort(id.begin(),id.end(),[&](int i, int j){
return x[i]<x[j];
});
vector<int> dp(m),mx(m);
dp[0]=w[id[0]];
mx[0]=dp[0];
for(int i=1;i<m;i++){
if(x[id[i]]-1==x[id[i-1]]){
if(i==1) dp[i]=w[id[i]];
else dp[i]=mx[i-2]+w[id[i]];
}
else{
dp[i]=mx[i-1]+w[id[i]];
}
mx[i]=max(dp[i],mx[i-1]);
}
return mx[m-1];
}
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
65 | }
| ^
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |