이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+8;
struct f{
int y;
long long w;
long long pod;
long long lewo;
long long prawo;
};
bool operator< (f a, f b){
if(a.y < b.y) return 1;
return 0;
}
vector<f> fish[N];
long long arzad[N];
long long brzad[N];
long long crzad[N];
f pusta;
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> z){
f nowy;
for(int i=0; i<m; i++){
nowy.y = y[i];
nowy.w = z[i];
nowy.lewo = 0;
nowy.pod = 0;
nowy.prawo=0;
fish[x[i]].push_back(nowy);
}
pusta.w = 0;
pusta.y = N+2;
pusta.lewo=0;
pusta.prawo=0;
pusta.pod=0;
for(int i=0; i<n; i++) fish[i].push_back(pusta);
for(int i=0; i<n; i++){
sort(fish[i].begin(), fish[i].end());
arzad[i]=0;
brzad[i]=0;
crzad[i]=0;
long long suma=0;
for(int j=0; j<fish[i].size(); j++){
fish[i][j].pod = suma;
suma+= fish[i][j].w;
}
}
for(int i=0; i<n-1; i++){
long long lesum=0, prsum=0;
for(int le=0, pr=0; le<fish[i].size()||pr<fish[i+1].size(); ){
if(fish[i][le].y < fish[i+1][pr].y){
fish[i][le].prawo = prsum;
lesum = fish[i][le].pod + fish[i][le].w;
le++;
continue;
}
if(fish[i][le].y > fish[i+1][pr].y){
fish[i+1][pr].lewo = lesum;
prsum = fish[i+1][pr].pod + fish[i+1][pr].w;
pr++;
continue;
}
lesum = fish[i][le].pod;
prsum = fish[i+1][pr].pod;
fish[i][le].prawo = prsum;
fish[i+1][pr].lewo = lesum;
lesum += fish[i][le].w;
prsum += fish[i+1][pr].w;
le++;
pr++;
}
}
arzad[0] = fish[0][fish[0].size()-1].prawo;
brzad[0] = 0;
crzad[0]=0;
for(int i=0; i<fish[1].size(); i++){
long long bi = fish[1][i].lewo - fish[1][i].pod;
long long ci = max(arzad[0] - fish[1][i].pod, bi + fish[1][i].pod);
long long ai = ci + fish[1][i].prawo;
arzad[1] = max(arzad[1], ai);
brzad[1] = max(brzad[1], bi);
crzad[1] = max(crzad[1], ci);
}
//cout <<"\n";
//cout << arzad[0]<<" "<<brzad[0]<<" "<<crzad[0]<<"\n";
//cout << arzad[1]<<" "<<brzad[1]<<" "<<crzad[1]<<"\n";
for(int j=2; j<n; j++){
for(int i=0; i<fish[j].size(); i++){
long long bi = fish[j][i].lewo + brzad[j-1];
bi = max(bi, arzad[j-2]);
bi = max(bi, crzad[j-2] + fish[j][i].lewo);
bi -= fish[j][i].pod;
long long ci = max(arzad[j-1] - fish[j][i].pod, bi + fish[j][i].pod);
long long ai = ci + fish[j][i].prawo;
arzad[j] = max(arzad[j], ai);
brzad[j] = max(brzad[j], bi);
crzad[j] = max(crzad[j], ci);
}
//cout << arzad[j]<<" "<<brzad[j]<<" "<<crzad[j]<<"\n";
}
long long wynik = 0;
wynik = max(wynik, arzad[n-1]);
wynik = max(wynik, brzad[n-1]);
wynik = max(wynik, crzad[n-1]);
return wynik;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<f>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int j=0; j<fish[i].size(); j++){
| ~^~~~~~~~~~~~~~~
fish.cpp:52:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<f>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int le=0, pr=0; le<fish[i].size()||pr<fish[i+1].size(); ){
| ~~^~~~~~~~~~~~~~~
fish.cpp:52:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<f>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int le=0, pr=0; le<fish[i].size()||pr<fish[i+1].size(); ){
| ~~^~~~~~~~~~~~~~~~~
fish.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<f>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i=0; i<fish[1].size(); i++){
| ~^~~~~~~~~~~~~~~
fish.cpp:90:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<f>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int i=0; i<fish[j].size(); i++){
| ~^~~~~~~~~~~~~~~
# | 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... |