제출 #1113892

#제출 시각아이디문제언어결과실행 시간메모리
1113892ntdaccodeCloud Computing (CEOI18_clo)C++17
36 / 100
3060 ms262144 KiB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i = a;i <= b; i++)
#define int long long

using namespace std;

typedef pair<int,int> ii;
typedef tuple<int,int,int> tp;

const int M = 1e5 + 10;
const int N = 2e3 + 10;
const int mod = 1e9 + 7;

int n , m ;
struct node
{
  int c,f,v;
}buy[N],sell[N];

bool cmp(const node & a, const node & b) {
  return a.f < b.f;
}

vector<int> f[N];
int kq = 0;
int g[M];
int upper[N];

void solve(int l,int r,int u,int v)
{
  if(l >= r) return ;
  int mid = (l + r)/2;
  int lim = upper[mid+1];
  solve(mid + 1,r,lim,v);

  for(int i = 0; i<= f[mid + 1].size() - 1; i++) g[i] =  f[mid + 1][i];

  int sum = f[mid + 1].size() - 1,i = 0 ;
  for(int idx = mid; idx >= l; idx--) {
    if(upper[idx] != lim)
    {
      i = idx;
      break;
    }

  for(int e = 0;e <= f[idx].size() - 1; e++) {
    f[idx][e] = max(f[idx][e],g[e]);
    if(e + sell[idx].c > f[idx].size() - 1) continue;
    f[idx][e] = max(f[idx][e],sell[idx].v + g[e + sell[idx].c]);
    kq = max(f[idx][e],kq);
   }
   for(int e =  f[idx].size() - 2;e >= 0;e--) f[idx][e] = max(f[idx][e],f[idx][e + 1]);
  }
  for(int j = lim - 1;j >= upper[l] ; j--) {
    sum += buy[j].c;

    for(int e = sum;e >= buy[j].c ; e--) {
      g[e] = max(g[e],g[e - buy[j].c] - buy[j].v);
      g[e] = max(g[e],g[e + 1]);
    }
   //     cout << i << " " << l << " " << r << "root\n";
    while(upper[i] == j && i > l - 1) {
        // nhan tien
       for(int e = 0;e <= f[i].size() - 1; e++) {
          f[i][e] = max(f[i][e],g[e]);
        if(e + sell[i].c > sum) continue;
        f[i][e] = max(f[i][e],sell[i].v + g[e + sell[i].c]);
       // cout << e << " " << f[i][e] <<  "\n";
        //if(i == 3 && e == 0) cout << g[1]   << "jja\n";
        kq = max(f[i][e],kq);
       // if(sell[i].v + g[e + sell[e].c] == 4) cout << i << " "  << e << " "  << lim - 1 << " "  << upper[l] <<   "\n";
       }
       for(int e =  f[i].size() - 2;e >= 0;e--) f[i][e] = max(f[i][e],f[i][e + 1]);
      i--;
    }
  }

  for(int i = 0;i <= sum ; i++) g[i] = -1e15;

  solve(l,mid,u,lim - 1);
}
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if(fopen("1.inp","r"))
  {
    freopen("1.inp","r",stdin);
    freopen("1.out","w",stdout);
  }
  #define task ""
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n ;
  for(int i = 1;i <= n ; i++) cin >> buy[i].c >> buy[i].f >> buy[i].v;
  cin >> m;
  for(int i = 1;i <= m ; i++) cin >> sell[i].c >> sell[i].f >> sell[i].v;
  sort(buy + 1, buy + n + 1,cmp);
  sort(sell + 1,sell + m + 1,cmp);


  int j = n,sum = 0 ,idx = 0;
  for(int i = m; i != 0; i--) {
    while(sell[i].f <= buy[j].f && j != 0) sum += buy[j].c,j--;
    f[i].assign(sum + 1,-1e15);
    f[i][0] = 0;
    upper[i] = j + 1;
    if(upper[i] != n + 1 && idx == 0) idx = i;
  }

    for(int i = 1; i <= m ;i++) {
    sum = 0;
      //cout << i <<  " " << sell[i].c <<   "\n";
      for(int j = n;j >= upper[i]; j--) {
          sum += buy[j].c;
        for(int e = sum; e >= buy[j].c; e--) {
          f[i][e] = max(f[i][e],f[i][e - buy[j].c] - buy[j].v);
          kq = max(kq,f[i][e]);

          }
      }
      for(int e = sell[i].c;e <= sum; e++) {
        f[i][e - sell[i].c] = max(f[i][e - sell[i].c],f[i][e] + sell[i].v);
        kq = max(kq,f[i][e - sell[i].c]);
      }
      //for(int e = sum - 1;e >= 0;e--) f[i][e] = max(f[i][e],f[i][e + 1]);
    }
    //cout << f[3][2] << " " << upper[3] << "\n";
  for(int i = 1;i <= 100000; i++) g[i] = -1e15;
  solve(1,idx,upper[1],n);
  cout << kq;
}

컴파일 시 표준 에러 (stderr) 메시지

clo.cpp: In function 'void solve(long long int, long long int, long long int, long long int)':
clo.cpp:36:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for(int i = 0; i<= f[mid + 1].size() - 1; i++) g[i] =  f[mid + 1][i];
      |                  ~^~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:46:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int e = 0;e <= f[idx].size() - 1; e++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~~
clo.cpp:48:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     if(e + sell[idx].c > f[idx].size() - 1) continue;
      |        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
clo.cpp:64:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |        for(int e = 0;e <= f[i].size() - 1; e++) {
      |                      ~~^~~~~~~~~~~~~~~~~~
clo.cpp: In function 'int32_t main()':
clo.cpp:89:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
clo.cpp:90:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
clo.cpp:95:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
clo.cpp:96:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...