제출 #1231861

#제출 시각아이디문제언어결과실행 시간메모리
1231861loloka메기 농장 (IOI22_fish)C++20
18 / 100
1061 ms2162688 KiB
#include "fish.h" #include<bits/stdc++.h> using namespace std; long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { bool f1 = 1, f2 = 1, f3 = 1; for(int i = 0; i < M; i++) { f1 &= (X[i] % 2 == 0); f2 &= (X[i] <= 1); f3 &= (Y[i] == 0); } if(f1) { long long ans = 0; for(int i = 0; i < M; i++) ans += W[i]; return ans; } if(f2) { long long pr[2][N + 1]; for(int i = 0; i < N + 1; i++) pr[0][i] = pr[1][i] = 0; for(int i = 0; i < M; i++) pr[X[i] % 2][Y[i] + 1] = W[i]; for(int i = 1; i <= N; i++) pr[0][i] += pr[0][i - 1], pr[1][i] += pr[1][i - 1]; long long ans = 0; for(int i = 1; i <= N; i++) ans = max(ans, pr[0][i - 1] + pr[1][N] - pr[1][i - 1]); if(N == 2) return max(pr[0][N], pr[1][N]); return ans; } if(f3) { long long dp[2][2][N + 1], mp[N + 1]; for(int i = 0; i < N + 1; i++) dp[0][0][i] = dp[0][1][i] = dp[1][0][i] = dp[1][1][i] = mp[i] = 0; for(int i = 0; i < M; i++) mp[X[i] + 1] = W[i]; dp[0][1][2] = mp[1]; dp[1][0][2] = mp[2]; for(int i = 3; i <= N; i++) { for(int j1 = 0; j1 < 2; j1++) { for(int j2 = 0; j2 < 2; j2++) { for(int j3 = 0; j3 < 2; j3++) { long long x = dp[j1][j2][i - 1]; if(j1 == 0 && j2 == 0 && j3 == 1) x += mp[i - 1]; if(j2 == 1 && j3 == 0) x += mp[i]; dp[j2][j3][i] = max(dp[j2][j3][i], x); } } } } return max({dp[0][0][N], dp[0][1][N], dp[1][0][N], dp[1][1][N]}); } long long pr[N][N], dp[N][9][9]; for(int i = 0; i < N; i++) { for(int j = 0; j < 9; j++) { for(int z = 0; z < 9; z++) dp[i][j][z] = 0; pr[i][j] = 0; } } for(int i = 0; i < M; i++) pr[X[i]][Y[i]] = W[i]; for(int i = 0; i < N; i++) { for(int j = 1; j < 9; j++) pr[i][j] += pr[i][j - 1]; } for(int x1 = 0; x1 < 9; x1++) { for(int x2 = 0; x2 < 9; x2++) { dp[1][x1][x2] = max(0ll, pr[0][x2] - pr[0][x1]) + max(0ll, pr[1][x1] - pr[1][x2]); } } for(int i = 2; i < N; i++) { for(int x1 = 0; x1 < 9; x1++) { for(int x2 = 0; x2 < 9; x2++) { for(int x3 = 0; x3 < 9; x3++) { dp[i][x2][x3] = max(dp[i][x2][x3], dp[i - 1][x1][x2] + max(0ll, pr[i - 1][x3] - pr[i - 1][max(x1, x2)]) + max(0ll, pr[i][x2] - pr[i][x3])); } } } } long long ans = 0; for(int x1 = 0; x1 < 9; x1++) { for(int x2 = 0; x2 < 9; x2++) ans = max(ans, dp[N - 1][x1][x2]); } return ans; }
#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...