이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int lld;
typedef pair<pair<lld,lld>,lld> piii;
int cmp(pair<pair<lld,lld>,pair<int,int> > x, pair<pair<lld,lld>,pair<int,int> > y){
if(x.first.first*y.first.second>x.first.second*y.first.first){
return true;
}return false;
}
int main(){
int n;
scanf("%d",&n);
piii arr[n];
for(int i=0;i<n;i++){
scanf("%lld %lld %lld",&arr[i].first.first,&arr[i].first.second,&arr[i].second);
}sort(arr,arr+n);
lld ans=0;
if(n==1){
if(arr[0].second>0){
cout<<arr[0].second<<endl;
return 0;
}cout<<0<<endl;
return 0;
}
vector<pair<pair<lld,lld>,pair<int,int> > > array;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
pair<lld,lld> p1=pair<lld,lld>(arr[j].first.second-arr[i].first.second,arr[j].first.first-arr[i].first.first);
array.push_back(pair<pair<lld,lld>,pair<int,int> >(p1,pair<int,int>(i,j)));
}
}sort(array.begin(),array.end(),cmp);
/*for(int i=0;i<array.size();i++){
cout<<array[i].first.first<<" "<<array[i].first.second<<" "<<array[i].second.first<<" "<<array[i].second.second<<endl;
}*/
pair<int,int> changes[array.size()];
for(int i=0;i<array.size();i++){
changes[i].first=array[i].second.first;
changes[i].second=array[i].second.second;
}
int per[n];
for(int i=0;i<n;i++)per[i]=i;
for(int i=0;i<array.size();i++){
int x,y;
for(int j=0;j<n;j++){
if(per[j]==array[i].second.first)x=j;
if(per[j]==array[i].second.second)y=j;
}
swap(per[x],per[y]);
lld DP[n];
lld zero=0;
DP[0]=max(zero,arr[per[0]].second);
ans=max(ans,DP[0]);
for(int j=1;j<n;j++){
DP[j]=max(zero,DP[j-1]+arr[per[j]].second);
ans=max(ans,DP[j]);
}
}cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<array.size();i++){
~^~~~~~~~~~~~~
bulldozer.cpp:47:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<array.size();i++){
~^~~~~~~~~~~~~
bulldozer.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
bulldozer.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&arr[i].first.first,&arr[i].first.second,&arr[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bulldozer.cpp:48:7: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
int x,y;
^
bulldozer.cpp:48:9: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
int x,y;
^
# | 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... |