제출 #1189863

#제출 시각아이디문제언어결과실행 시간메모리
1189863Amr메기 농장 (IOI22_fish)C++20
0 / 100
12 ms2368 KiB
#include "fish.h"
#include <vector>

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define sz size()
const int N2 = 1e5+2;
 ll a[N2]={0}, b[N2], prea[N2], preb[N2];
 ll dp[N2][2];
 ll inf = 1e18;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {

    for(int i = 0; i < N; i++)
    {
        a[X[i]+1] = W[i];
    }
    dp[0][1] = -inf;
    dp[1][0] = 0;
    dp[1][1] = 0;
    for(int i = 2; i <= N2; i++)
    {
        dp[i][1] = max( max(dp[i-2][0],dp[i-2][1])+a[i-1],dp[i-1][1]);
        dp[i][0] = max(dp[i-1][1]+a[i],dp[i-1][0]);
    }
    cout << max(dp[N2][0], dp[N2][1]) << endl;

  return 0;
}

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

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:24:18: warning: iteration 100000 invokes undefined behavior [-Waggressive-loop-optimizations]
   24 |         dp[i][0] = max(dp[i-1][1]+a[i],dp[i-1][0]);
      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:21:22: note: within this loop
   21 |     for(int i = 2; i <= N2; i++)
      |                    ~~^~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...