제출 #870139

#제출 시각아이디문제언어결과실행 시간메모리
870139nghia0912Sjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms348 KiB
#define COPYRIGHT CODE BY TRINH TUAN NGHIA #include<bits/stdc++.h> #define Boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ll long long #define endl "\n" #define st first #define nd second #define ii pair <ll,ll> #define iii pair <ll,ii> #define iiii pair <ii,ii> #define pb push_back #define NAME "recipe" using namespace std; const int N = 2e5 + 10; const int Nsub1 = 210; const int Nsub2 = 3e3 + 10; int n,q ; long long dp[3010]; ll a[N]; void inp (){ cin >> n >> q; for (int i = 1;i <= n; ++i){ cin >> a[i]; } } void reset(){ for (int i =1 ; i <= n; ++i)dp[i] = 0; } void sub1(){ while (q--){ reset(); int l, r, x; cin >> l >> r >> x; for (int i = l; i <= r; ++i){ a[i] += x; } for (int i = 1; i <= n; ++i){ ll minn = a[i]; ll maxx = a[i]; for (int j = i; j >= 1; --j){ minn = min(minn, a[j]); maxx = max(maxx, a[j]); dp[i] = max({dp[i], dp[j - 1] + a[i] - minn, dp[j - 1] + maxx - a[i]}); // if (i == 2 and j == 1)cout << minn << " " << maxx << "\n"; } // cout << a[i] << " "; } // cout << "\n"; // for (int i =1 ; i <= n; ++i)cout << dp[i] << " "; // cout << "\n"; cout << dp[n] << "\n"; } } void sub2(){ while (q--){ reset(); int l, r, x; cin >> l >> r >> x; for (int i = l; i <= r; ++i){ a[i] += x; } ll minn = 1e18; ll maxx = 0; ll minndp = 1e18; ll maxxdp = 0; for (int i = 1; i <= n; ++i){ dp[i] = max({dp[i -1 ], a[i] - minndp, maxxdp - a[i]}); minndp = min(minndp, a[i] - dp[i - 1]); maxxdp = max(maxxdp, dp[i - 1] + a[i]); // cout << dp[i] << " "; //cout << i << " " << dp[i] << " " << minndp << " " << maxxdp << endl; } // cout << endl; cout << dp[n] << endl; } } void solve(){ // sub1(); sub2(); } signed main (){ if (fopen(NAME".inp", "r")){ freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout); } Boost; inp(); solve(); } /* input */ /* output */

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

Main.cpp: In function 'void sub2()':
Main.cpp:64:12: warning: unused variable 'minn' [-Wunused-variable]
   64 |         ll minn = 1e18;
      |            ^~~~
Main.cpp:65:12: warning: unused variable 'maxx' [-Wunused-variable]
   65 |         ll maxx = 0;
      |            ^~~~
Main.cpp: In function 'int main()':
Main.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...