이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
ll max_weights(int n,int m,vector<int>x,vector<int>y,vector<int>w){
int even=0,X=0,Y=0;
for(int i=0;i<m;i++){
X=max(X,x[i]);
Y=max(Y,y[i]);
if(x[i]%2==0) even++;
}
if(even==m){
ll ans=0;
for(int i=0;i<m;i++){
ans+=w[i];
}
return ans;
}
if(X<=1){
ll ans=0,cur=0;
for(int i=0;i<m;i++){
if(x[i]==0){
ans+=w[i];
}
else{
cur+=w[i];
}
}
if(n==2) return max(ans,cur);
ll sum[n][2];
memset(sum,0,sizeof sum);
for(int i=0;i<m;i++){
sum[y[i]][x[i]]+=w[i];
}
for(int i=1;i<n;i++){
sum[i][0]+=sum[i-1][0];
sum[i][1]+=sum[i-1][1];
}
ans=max(ans,cur);
for(int i=0;i<n;i++){
ans=max(ans,sum[i][0]+sum[n-1][1]-sum[i][1]);
}
return ans;
}
if(Y==0){
ll sum[n];
fill(sum,sum+n,0);
for(int i=0;i<m;i++){
sum[x[i]]+=w[i];
}
ll dp[n][2][2];//i, i,i-1
dp[1][0][0]=0;
dp[1][0][1]=sum[0];
dp[1][1][0]=sum[1];
dp[1][1][1]=0;
for(ll i=2;i<n;i++){
dp[i][1][1]=max(dp[i-1][1][0],dp[i-1][1][1]);
dp[i][1][0]=max(dp[i-1][0][1],dp[i-1][0][0]+sum[i-1]);
dp[i][0][1]=max(dp[i-1][1][0],dp[i-1][1][1])+sum[i];
dp[i][0][0]=max(dp[i-1][0][1],dp[i-1][0][0]);
}
return max({dp[n-1][0][0],dp[n-1][0][1],dp[n-1][1][0],dp[n-1][1][1]});
}
return 0ll;
}
# | 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... |