답안 #644096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
644096 2022-09-23T19:29:58 Z NintsiChkhaidze 메기 농장 (IOI22_fish) C++17
0 / 100
789 ms 154508 KB
#include "fish.h"
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
 
const int N = 3005;
ll p[N][N],dp[N][5],suff[N],pref[N];
vector <int> v[N],prc[N];
 
ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W) {
 
  for (int i = 0;i < m; i++){
    X[i]++,Y[i]++;
    p[X[i]][Y[i]] += W[i];
    v[X[i] + 1].pb(Y[i]);
    v[X[i] - 1].pb(Y[i]);
    
  }
 /*
  for (int j = 1; j <= n; j++){
  	v[j].pb(0),v[j].pb(n);
  	sort(v[j].begin(),v[j].end());
  }*/
  
  for (int j = 1; j <= n; j++)
    for (int i = 1; i <= n; i++)
      p[j][i] += p[j][i - 1];
 
  for (int j = 1; j <= n; j++){
    
    for (int i=0;i<v[j].size();i++){
      int a = v[j][i];
      dp[a][0] = suff[a] - p[j][a];
      dp[a][1] = pref[a] + p[j - 1][a];
      //v[j - 2][ind] <= a

      int l = 0,r = v[j - 2].size() - 1,ind= 0;
      while(l<=r){
        int mid=(l+r)>>1;
        if (v[j - 2][mid] <= a){
          ind = mid;
          l = mid + 1;
        }else{
          r=  mid - 1;
        }
      }
      
      if (j >= 3) dp[a][1] = max(dp[a][1], prc[j - 2][ind] + p[j - 1][a]);
    }
    
    for (int a = n; a >= 0; a--)
      suff[a] = max(suff[a+1],max(dp[a][0],dp[a][1]) + p[j + 1][a]);
 
    pref[0] = dp[0][1] - p[j][0];
    for (int a =1; a <= n; a++)
      pref[a] = max(pref[a - 1],dp[a][1] - p[j][a]);

   	ll ls = 0;
    prc[j].resize(v[j].size());
   	for (int i = 0; i < v[j].size(); i++){
   		int a = v[j][i];
   		prc[j][i] = max(ls, max(dp[a][0],dp[a][1])); 
   		ls = prc[j][i];
  	}
  
  }
 
  ll ans = 0;
  for (int a = 0; a <= n; a++)
      ans=max({ans,dp[a][0],dp[a][1]});
  return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i=0;i<v[j].size();i++){
      |                  ~^~~~~~~~~~~~
fish.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i = 0; i < v[j].size(); i++){
      |                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 715 ms 149548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Runtime error 776 ms 154508 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 789 ms 143960 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '8866', found: '7755'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 789 ms 143960 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 715 ms 149548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -