이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define ull unsigned long long
#define pb push_back
#define inf 1000000000000000000
#define linf 1000000000
#define mpr make_pair
#define in insert
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
//author :: E.Mustafayev
using namespace std;
const int Max= 100000;
vector<vector<vector<ll>>> dp(Max,vector<vector<ll>>(2,vector<ll>(2)));
vector<int>v(Max);
int N;
ll solve(int col, bool a, bool b) {
if (col==N) {
return 0;
}
ll &res=dp[col][a][b];
if (res!=-1) {
return res;
}
res=solve(col+1,b,false);
ll x=0;
if (col>0&& b){
x-=v[col];
}
if (col>0&&!a&&!b){
x+=v[col-1];
}
if (col+1<N){
x+=v[col+1];
}
res=max(res,x+solve(col+1,b,true));
return res;
}
ll max_weights(int n, int m, vector<int>x, vector<int>y, vector<int>w) {
for(int i=0;i<m;i++){
v[x[i]]=w[i];
}
for(int i=0;i<Max;i++){
for(int j=0;j<2;j++){
for(int k=0;k<2;k++){
dp[i][j][k]=-1;
}
}
}
bool a=true,b=true;
N=n;
ll ans=0;
for(int i=0;i<m;i++){
if(x[i]%2){
a=false;
}
ans+=w[i];
}
if(a){
return ans;
}
ll res=solve(0,false,false);
return res;
}
// void solve(){
//int n,m;
//cin>>n>>m;
//vector<int>x(m),y(m),w(m);
//for(int i=0;i<m;i++){
// cin>>x[i]>>y[i]>>w[i];
//
//}
//cout<<max_weights(n,m,x,y,w);
//
//
//}
//int main(){
// ios_base::sync_with_stdio(false);
//
//solve();
//
//}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:66:13: warning: unused variable 'b' [-Wunused-variable]
66 | bool a=true,b=true;
| ^
# | 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... |