이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
#define MAX 300001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef double db;
typedef long double ldb;
ll n,q,t=1,m,n2,m2,k,cnt=0,a[MAX],b[MAX],d[MAX],d2[MAX],x,y,z,x2,y2,z2,res1=0,cnt1,cnt2,cnt3;
long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
bool ok=false;
bool ok2=false;
bool ok3=false;
ll dp[N][10];
ll arr[N][10];
for(int i=0;i<N;i++){
for(int j=0;j<10;j++){
dp[i][j]=0;
arr[i][j]=0;
}
}
for(int i=0;i<M;i++){
if(X[i]%2){
ok=true;
}
if(Y[i]!=0){
ok2=true;
}
if(X[i]>1){
ok3=true;
}
a[X[i]]=W[i];
if(X[i]==0){
b[Y[i]]=W[i];
}
else{
d[Y[i]]=W[i];
}
arr[X[i]][Y[i]+1]+=W[i];
}
if(!ok){
ll res=0;
for(int i=0;i<M;i++){
res+=W[i];
}
return res;
}
if(!ok2){
ll res=0;
ll dp[N][2];
dp[0][0]=dp[0][1]=0;
dp[1][0]=a[1];
dp[1][1]=a[0];
for(int i=2;i<N;i++){
dp[i][0]=dp[i-1][0];
dp[i][1]=dp[i-1][1];
dp[i][0]=max(dp[i][0],dp[i-1][1]+a[i]);
dp[i][1]=max(dp[i][1],max(dp[i-2][0],dp[i-2][1])+a[i-1]);
}
return max(dp[N-1][0],dp[N-1][1]);
}
if(!ok3){
for(int i=1;i<N;i++){
b[i]+=b[i-1];
d[i]+=d[i-1];
}
ll res=max(b[N-1],d[N-1]);
if(N>2){
for(int i=0;i<N;i++){
res=max(res,b[i]+d[N-1]-d[i]);
}
}
return res;
}
for(int i=0;i<N;i++){
for(int j=1;j<10;j++){
arr[i][j]+=arr[i][j-1];
}
}
for(int j=0;j<10;j++){
for(int z=0;z<10;z++){
ll res2=0;
if(j>z){
res2=arr[0][j]-arr[0][z];
}
else{
res2=arr[1][z]-arr[1][j];
}
dp[1][j]=max(dp[1][j],res2);
}
}
for(int i=2;i<N;i++){
for(int j=0;j<10;j++){
for(int z=j;z<10;z++){
dp[i][j]=max(dp[i][j],dp[i-1][z]+arr[i][z]-arr[i][j]);
}
for(int z=0;z<j;z++){
for(int k=z;k<10;k++){
dp[i][j]=max(dp[i][j],dp[i-2][k]+arr[i-1][max(j,k)]-arr[i-1][z]);
}
}
}
}
ll res=0;
for(int i=0;i<10;i++){
res=max(res,dp[N-1][i]);
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:89:12: warning: unused variable 'res' [-Wunused-variable]
89 | ll res=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... |