이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
ll n,m;
struct date
{
ll poz,val;
};
vector<date> myy[100005];
ll dp[3][2][100005];
bool comp(date a, date b)
{
return a.poz<b.poz;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
n=N;
m=M;
for(int i=0;i<m;i++)
{
ll x=X[i];
ll y=Y[i];
ll w=W[i];
myy[x+1].push_back({y+1,w});
}
for(int i=1;i<=n;i++)
{
myy[i].push_back({0,0});
myy[i].push_back({n+1,0});
sort(myy[i].begin(),myy[i].end(),comp);
}
ll ans=0;
ll cur=1;
ll prv=0;
for(int i=2;i<=n;i++)
{
// neutru
ll suma=0;
vector<ll> suf;
int lg=myy[i-1].size();
ll maxim=0;
for(int j=lg-1;j>=0;j--)
{
int p1=myy[i-1][j].poz-1;
maxim=max(maxim,max(dp[1][prv][p1],dp[2][prv][p1]));
suf.push_back(maxim);
}
reverse(suf.begin(),suf.end());
for(ll j=0;j<myy[i].size();j++)
{
suma+=myy[i][j].val;
ll p=myy[i][j].poz;
dp[0][cur][p]=0;
ll st=0;
ll dr=myy[i-1].size();
dr--;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(myy[i-1][mij].poz-1>=p)
{
dp[0][cur][p]=max(dp[0][cur][p],suma+suf[mij]);
dr=mij-1;
}
else
st=mij+1;
}
ans=max(ans,dp[0][cur][p]);
}
vector<ll> prefsum;
suma=0;
for(int j=0;j<myy[i-1].size();j++)
{
suma+=myy[i-1][j].val;
prefsum.push_back(suma);
}
maxim=0;
ll s2=0;
for(ll k=0;k<myy[i-1].size();k++)
{
ll poz=myy[i-1][k].poz-1;
if(poz>=0)
{
ll val=dp[1][prv][poz]-s2;
maxim=max(maxim,val);
}
s2+=myy[i-1][k].val;
poz++;
ll val=dp[0][prv][poz]-s2;
maxim=max(maxim,val);
}
// cresc
for(int j=0;j<myy[i].size();j++)
{
ll p=myy[i][j].poz-1;
if(p<0)
continue;
dp[1][cur][p]=0;
ll s1=0;
ll st=0;
ll dr=myy[i-1].size();
dr--;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(myy[i-1][mij].poz<=p)
{
s1=prefsum[mij];
st=mij+1;
}
else
dr=mij-1;
}
dp[1][cur][p]=s1+maxim;
ans=max(ans,dp[1][cur][p]);
}
// desc
prefsum.clear();
suma=0;
for(int j=0;j<myy[i].size();j++)
{
suma+=myy[i][j].val;
prefsum.push_back(suma);
}
maxim=0;
for(int k=0;k<myy[i-1].size();k++)
{
ll p1=myy[i-1][k].poz-1;
if(p1<0)
continue;
ll s1=0;
ll st=0;
ll dr=myy[i].size();
dr--;
while(st<=dr)
{
ll mij=(st+dr)/2;
if(myy[i][mij].poz<=p1)
{
s1=prefsum[mij];
st=mij+1;
}
else
dr=mij-1;
}
ll val=max(dp[1][prv][p1],dp[2][prv][p1])+s1;
maxim=max(maxim,val);
}
s2=0;
for(int j=0;j<myy[i].size();j++)
{
ll p=myy[i][j].poz-1;
if(p<0)
continue;
ll poz=0;
dp[2][cur][p]=maxim-s2;
ans=max(ans,dp[2][cur][p]);
s2+=myy[i][j].val;
}
swap(cur,prv);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:50:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(ll j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int j=0;j<myy[i-1].size();j++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:80:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(ll k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:122:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | for(int j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:128:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | for(int k=0;k<myy[i-1].size();k++)
| ~^~~~~~~~~~~~~~~~
fish.cpp:152:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<date>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
152 | for(int j=0;j<myy[i].size();j++)
| ~^~~~~~~~~~~~~~
fish.cpp:157:16: warning: unused variable 'poz' [-Wunused-variable]
157 | ll poz=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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |