제출 #778621

#제출 시각아이디문제언어결과실행 시간메모리
778621TekorCatfish Farm (IOI22_fish)C++17
100 / 100
403 ms90708 KiB
#include "fish.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define en '\n' #define pii pair <int,int> #define mp make_pair #define f first #define s second #define all(v) v.begin(),v.end() const int N = 1e5 + 10; const ll LLINF = (ll)1e18; vector <pair <int,ll>> g[N]; vector <ll> dp[N],dp1[N]; map <int,bool> was[N]; ll max_weights(int n, int m, vector <int> X, vector <int> Y, vector <int> W) { for(int i = 0;i < m;i++) { g[X[i]].pb(mp(Y[i] + 1,W[i])); was[X[i]][Y[i] + 1] = 1; } for(int i = 0;i < n;i++) { int k = g[i].size(); for(int j = 0;j < k;j++) { if(g[i][j].f > 1 && !was[i][g[i][j].f - 1]) { was[i][g[i][j].f - 1] = 1; g[i].pb(mp(g[i][j].f - 1,0)); } } g[i].pb(mp(0,0)); sort(all(g[i])); if(g[i].back().f != n)g[i].pb(mp(n,0)); for(int j = 1;j <= (int)g[i].size();j++) { dp[i].pb(0); dp1[i].pb(0); } } ll ans = 0; for(int i = 1;i < n;i++) { ll typ1mx = -LLINF,typ2mx = -LLINF; int R = 0; ll cur = 0,cur1 = 0; for(int j = 0;j < g[i - 1].size();j++) { auto to = g[i - 1][j]; cur1 += to.s; while(R < g[i].size() && to.f >= g[i][R].f) { cur += g[i][R].s; R++; } typ1mx = max(typ1mx,dp[i - 1][j] + cur); typ2mx = max(typ2mx,dp1[i - 1][j] - cur1); } cur = 0,cur1 = 0; R = 0; ll tek = 0,sum = 0; for(int j = 0;j < g[i].size();j++) { auto to = g[i][j]; while(R < g[i - 1].size() && to.f >= g[i - 1][R].f) { if(to.f > g[i - 1][R].f) { tek = max(tek,dp[i - 1][R] + sum); }else { tek = max(tek,dp[i - 1][R] + sum + to.s); } cur += g[i - 1][R].s; R++; } sum += to.s; dp[i][j] = ans; // dp1[i][j] = ans; dp[i][j] = max(dp[i][j],typ1mx - sum); dp[i][j] = max(dp[i][j],typ2mx + cur); dp1[i][j] = max(dp1[i][j],typ2mx + cur); while(R < g[i - 1].size() && (to.f != n ? g[i][j + 1].f : n + 1) > g[i - 1][R].f) { cur += g[i - 1][R].s; tek = max(tek,dp[i - 1][R] + sum); R++; } dp1[i][j] = max(dp1[i][j],tek); } // cout << i << " " << typ1mx << " " << typ2mx << " gooo " << en; for(int j = 0;j < g[i].size();j++) { ans = max(ans,dp[i][j]); ans = max(ans,dp1[i][j]); // cout << dp[i][j] << " " << dp1[i][j] << " " << g[i][j].f << en; } // cout << ans << en; } return ans; }

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

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(int j = 0;j < g[i - 1].size();j++) {
      |                 ~~^~~~~~~~~~~~~~~~~
fish.cpp:47:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    while(R < g[i].size() && to.f >= g[i][R].f) {
      |          ~~^~~~~~~~~~~~~
fish.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int j = 0;j < g[i].size();j++) {
      |                 ~~^~~~~~~~~~~~~
fish.cpp:59:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    while(R < g[i - 1].size() && to.f >= g[i - 1][R].f) {
      |          ~~^~~~~~~~~~~~~~~~~
fish.cpp:74:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    while(R < g[i - 1].size() && (to.f != n ? g[i][j + 1].f : n + 1) > g[i - 1][R].f) {
      |          ~~^~~~~~~~~~~~~~~~~
fish.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |   for(int j = 0;j < g[i].size();j++) {
      |                 ~~^~~~~~~~~~~~~
#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...