답안 #114486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114486 2019-06-01T13:05:13 Z Dung Two Dishes (JOI19_dishes) C++11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

unsigned int N,M;

vector<unsigned long> A;
vector<unsigned long> B;
vector<unsigned long long> S;
vector<unsigned long long> T;
vector<long> P;
vector<long> Q;
vector<unsigned long> suma, sumb;
unsigned long sum = 0;
long ans = 0;
unsigned long long curtime = 0;






long dp(const unsigned int & posa,const unsigned int & posb,const short int & state){
  if(state == 1){
  	if(posa < N){
  	  if(posb >= 0){
  	    curtime = suma[posa] + sumb[posb];
  	  }
  	  else{
  	    curtime = suma[posa];
  	  }
  	  if(curtime < S[posa]){
  	    ans += P[posa]; 
  	  }
      return max(dp(++posa, posb,1),dp(posa,++posb,-1));
  	  
  	}
  	else{
  	  long long ans1= ans;
      ans -= P[posa - 1];
  	  return ans1;
  	}
  }
  else if(state == -1){
    if(posb < M){
  	  if(posa >= 0){
  	    curtime = suma[posa] + sumb[posb];
  	  }
  	  else{
  	    curtime = sumb[posb];
  	  }
  	  if(curtime < S[posb]){
  	    ans += Q[posb]; 
  	  }
  	  return max(dp(++posa, posb,1),dp(posa,++posb,-1));
  	}
  	else{
      long long ans1= ans;
      ans -= Q[posb - 1];
  	  return ans1;
  	}
  }
}

int main(){
  cin >> N >> M;
  A.resize(N);
  S.resize(N);
  P.resize(N);
  suma.resize(N);
  B.resize(M); T.resize(M); Q.resize(M); sumb.resize(M);
  for(int i = 0;i< N;i++){
    cin >> A[i] >> S[i] >> P[i];
    sum += A[i];
    suma[i] = sum;
  }
  sum = 0;
  for(int i = 0;i< M;i++){
    cin >> B[i] >> T[i] >> Q[i];
    sum += B[i];
    sumb[i] = sum;
  }
  cout << max(dp(0,-1,1),dp(-1,0,-1));
  
}

Compilation message

dishes.cpp: In function 'long int dp(const unsigned int&, const unsigned int&, const short int&)':
dishes.cpp:35:23: error: increment of read-only reference 'posa'
       return max(dp(++posa, posb,1),dp(posa,++posb,-1));
                       ^~~~
dishes.cpp:35:47: error: increment of read-only reference 'posb'
       return max(dp(++posa, posb,1),dp(posa,++posb,-1));
                                               ^~~~
dishes.cpp:55:22: error: increment of read-only reference 'posa'
      return max(dp(++posa, posb,1),dp(posa,++posb,-1));
                      ^~~~
dishes.cpp:55:46: error: increment of read-only reference 'posb'
      return max(dp(++posa, posb,1),dp(posa,++posb,-1));
                                              ^~~~
dishes.cpp: In function 'int main()':
dishes.cpp:72:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i< N;i++){
                 ~^~~
dishes.cpp:78:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0;i< M;i++){
                 ~^~~
dishes.cpp: In function 'long int dp(const unsigned int&, const unsigned int&, const short int&)':
dishes.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^