답안 #889444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889444 2023-12-19T17:33:48 Z winter0101 메기 농장 (IOI22_fish) C++17
100 / 100
301 ms 87680 KB
#include<bits/stdc++.h>
#include "fish.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int maxn=1e5+9;
const long long inf=-1e15;
vector<int>cord[maxn];
vector<long long>a[maxn];
vector<vector<long long>>f[maxn];
vector<long long>g[maxn];
/*
f[i][j][0] col i bridge j and col i-1 bridge <=j (can update for all) to last subtask just need to count some j that j+1 have a fish
f[i][j][1] col i bridge j and col i-1 bridge >j (just can update for <=j)same as f[i][j][0]
g[i][j] col i bridge <=j and col i-1 bridge=j (just can update for >j)cal some j have fish
base f[0][0][0]=0,g[0][0]=0
*/
long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W) {
int n=N,m=M;
for1(i,0,m-1){
//a[X[i]+1][Y[i]+1]=W[i];
cord[X[i]+1].pb(Y[i]);
cord[X[i]+1].pb(Y[i]+1);
}
for1(i,0,n){
cord[i].pb(0),cord[i].pb(n);
}
for1(i,0,n){
sort(all(cord[i]));
cord[i].resize(distance(cord[i].begin(),unique(all(cord[i]))));
a[i].resize(sz(cord[i]));
f[i].resize(sz(cord[i]));
for1(j,0,sz(cord[i])-1)f[i][j].resize(2);
g[i].resize(sz(cord[i]));
for1(j,0,sz(cord[i])-1){
f[i][j][0]=f[i][j][1]=g[i][j]=inf;
}
}
f[0][0][0]=g[0][0]=0;
for1(i,0,m-1){
int pos=lower_bound(all(cord[X[i]+1]),Y[i]+1)-cord[X[i]+1].begin();
a[X[i]+1][pos]+=W[i];
}
for1(j,1,n){
for1(i,1,sz(cord[j])-1){
a[j][i]+=a[j][i-1];
}
}
for1(j,1,n){
long long bestf1=inf,bestf0=inf,bestg=inf;
int l=sz(cord[j-1]);
for2(i,sz(cord[j])-1,0){
for2(k,l-1,0){
if (cord[j-1][k]>=cord[j][i]){
int pos=upper_bound(all(cord[j]),cord[j-1][k])-cord[j].begin()-1;
bestf1=max(bestf1,f[j-1][k][1]+a[j][pos]);
bestf0=max(bestf0,f[j-1][k][0]+a[j][pos]);
bestg=max(bestg,max(f[j-1][k][0],f[j-1][k][1]));
l=k;
}
else break;
}
f[j][i][1]=max(f[j][i][1],-a[j][i]+max(bestf1,bestf0));
g[j][i]=max(g[j][i],bestg+a[j][i]);
}
l=-1;
bestf1=inf,bestf0=inf,bestg=inf;
for1(i,0,sz(cord[j])-1){
//end at cord[j][i]
int pos=upper_bound(all(cord[j-1]),cord[j][i])-cord[j-1].begin()-1;
for1(k,l+1,sz(cord[j-1])-1){
if (cord[j-1][k]<=cord[j][i]){
l=k;
bestf1=max(bestf1,f[j-1][k][1]);
bestf0=max(bestf0,f[j-1][k][0]-a[j-1][k]);
bestg=max(bestg,g[j-1][k]-a[j-1][k]);
}
else break;
}
f[j][i][0]=max(f[j][i][0],bestf1);
f[j][i][0]=max(f[j][i][0],max(bestg,bestf0)+a[j-1][pos]);
}
}
long long ans=inf;
for1(i,0,sz(cord[n])-1)ans=max({ans,f[n][i][0],f[n][i][1],g[n][i]});
return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 39620 KB Output is correct
2 Correct 92 ms 42792 KB Output is correct
3 Correct 39 ms 32164 KB Output is correct
4 Correct 45 ms 31568 KB Output is correct
5 Correct 222 ms 67508 KB Output is correct
6 Correct 301 ms 87680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9820 KB Output is correct
2 Correct 132 ms 50020 KB Output is correct
3 Correct 156 ms 53948 KB Output is correct
4 Correct 87 ms 39316 KB Output is correct
5 Correct 91 ms 42924 KB Output is correct
6 Correct 2 ms 9816 KB Output is correct
7 Correct 2 ms 9820 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 2 ms 9820 KB Output is correct
10 Correct 37 ms 31572 KB Output is correct
11 Correct 42 ms 31728 KB Output is correct
12 Correct 85 ms 39656 KB Output is correct
13 Correct 92 ms 42696 KB Output is correct
14 Correct 78 ms 39296 KB Output is correct
15 Correct 95 ms 42604 KB Output is correct
16 Correct 78 ms 39364 KB Output is correct
17 Correct 86 ms 42408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 31580 KB Output is correct
2 Correct 47 ms 31600 KB Output is correct
3 Correct 71 ms 34060 KB Output is correct
4 Correct 54 ms 34684 KB Output is correct
5 Correct 88 ms 39680 KB Output is correct
6 Correct 85 ms 39504 KB Output is correct
7 Correct 82 ms 39764 KB Output is correct
8 Correct 91 ms 39564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9816 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 9832 KB Output is correct
7 Correct 2 ms 9980 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 3 ms 10020 KB Output is correct
10 Correct 3 ms 10076 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 2 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9816 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 9832 KB Output is correct
7 Correct 2 ms 9980 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 3 ms 10020 KB Output is correct
10 Correct 3 ms 10076 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 2 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 5 ms 10076 KB Output is correct
17 Correct 26 ms 15996 KB Output is correct
18 Correct 24 ms 15704 KB Output is correct
19 Correct 25 ms 15460 KB Output is correct
20 Correct 23 ms 15452 KB Output is correct
21 Correct 23 ms 15348 KB Output is correct
22 Correct 45 ms 20820 KB Output is correct
23 Correct 8 ms 11356 KB Output is correct
24 Correct 21 ms 14680 KB Output is correct
25 Correct 3 ms 10076 KB Output is correct
26 Correct 9 ms 11356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9816 KB Output is correct
2 Correct 2 ms 10072 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 3 ms 9820 KB Output is correct
5 Correct 2 ms 9820 KB Output is correct
6 Correct 2 ms 9832 KB Output is correct
7 Correct 2 ms 9980 KB Output is correct
8 Correct 2 ms 9820 KB Output is correct
9 Correct 3 ms 10020 KB Output is correct
10 Correct 3 ms 10076 KB Output is correct
11 Correct 3 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 2 ms 9820 KB Output is correct
14 Correct 3 ms 9820 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 5 ms 10076 KB Output is correct
17 Correct 26 ms 15996 KB Output is correct
18 Correct 24 ms 15704 KB Output is correct
19 Correct 25 ms 15460 KB Output is correct
20 Correct 23 ms 15452 KB Output is correct
21 Correct 23 ms 15348 KB Output is correct
22 Correct 45 ms 20820 KB Output is correct
23 Correct 8 ms 11356 KB Output is correct
24 Correct 21 ms 14680 KB Output is correct
25 Correct 3 ms 10076 KB Output is correct
26 Correct 9 ms 11356 KB Output is correct
27 Correct 6 ms 10844 KB Output is correct
28 Correct 131 ms 37984 KB Output is correct
29 Correct 186 ms 49492 KB Output is correct
30 Correct 200 ms 64336 KB Output is correct
31 Correct 202 ms 64396 KB Output is correct
32 Correct 153 ms 45092 KB Output is correct
33 Correct 201 ms 64912 KB Output is correct
34 Correct 198 ms 65104 KB Output is correct
35 Correct 75 ms 29520 KB Output is correct
36 Correct 216 ms 62232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 31580 KB Output is correct
2 Correct 47 ms 31600 KB Output is correct
3 Correct 71 ms 34060 KB Output is correct
4 Correct 54 ms 34684 KB Output is correct
5 Correct 88 ms 39680 KB Output is correct
6 Correct 85 ms 39504 KB Output is correct
7 Correct 82 ms 39764 KB Output is correct
8 Correct 91 ms 39564 KB Output is correct
9 Correct 99 ms 49184 KB Output is correct
10 Correct 69 ms 32136 KB Output is correct
11 Correct 135 ms 54576 KB Output is correct
12 Correct 2 ms 9816 KB Output is correct
13 Correct 2 ms 9816 KB Output is correct
14 Correct 2 ms 9820 KB Output is correct
15 Correct 2 ms 9816 KB Output is correct
16 Correct 2 ms 9816 KB Output is correct
17 Correct 2 ms 9644 KB Output is correct
18 Correct 36 ms 31756 KB Output is correct
19 Correct 37 ms 31748 KB Output is correct
20 Correct 38 ms 31736 KB Output is correct
21 Correct 37 ms 31676 KB Output is correct
22 Correct 106 ms 49868 KB Output is correct
23 Correct 142 ms 58964 KB Output is correct
24 Correct 141 ms 59448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 39620 KB Output is correct
2 Correct 92 ms 42792 KB Output is correct
3 Correct 39 ms 32164 KB Output is correct
4 Correct 45 ms 31568 KB Output is correct
5 Correct 222 ms 67508 KB Output is correct
6 Correct 301 ms 87680 KB Output is correct
7 Correct 2 ms 9820 KB Output is correct
8 Correct 132 ms 50020 KB Output is correct
9 Correct 156 ms 53948 KB Output is correct
10 Correct 87 ms 39316 KB Output is correct
11 Correct 91 ms 42924 KB Output is correct
12 Correct 2 ms 9816 KB Output is correct
13 Correct 2 ms 9820 KB Output is correct
14 Correct 2 ms 9820 KB Output is correct
15 Correct 2 ms 9820 KB Output is correct
16 Correct 37 ms 31572 KB Output is correct
17 Correct 42 ms 31728 KB Output is correct
18 Correct 85 ms 39656 KB Output is correct
19 Correct 92 ms 42696 KB Output is correct
20 Correct 78 ms 39296 KB Output is correct
21 Correct 95 ms 42604 KB Output is correct
22 Correct 78 ms 39364 KB Output is correct
23 Correct 86 ms 42408 KB Output is correct
24 Correct 36 ms 31580 KB Output is correct
25 Correct 47 ms 31600 KB Output is correct
26 Correct 71 ms 34060 KB Output is correct
27 Correct 54 ms 34684 KB Output is correct
28 Correct 88 ms 39680 KB Output is correct
29 Correct 85 ms 39504 KB Output is correct
30 Correct 82 ms 39764 KB Output is correct
31 Correct 91 ms 39564 KB Output is correct
32 Correct 2 ms 9816 KB Output is correct
33 Correct 2 ms 10072 KB Output is correct
34 Correct 3 ms 9820 KB Output is correct
35 Correct 3 ms 9820 KB Output is correct
36 Correct 2 ms 9820 KB Output is correct
37 Correct 2 ms 9832 KB Output is correct
38 Correct 2 ms 9980 KB Output is correct
39 Correct 2 ms 9820 KB Output is correct
40 Correct 3 ms 10020 KB Output is correct
41 Correct 3 ms 10076 KB Output is correct
42 Correct 3 ms 9816 KB Output is correct
43 Correct 4 ms 9816 KB Output is correct
44 Correct 2 ms 9820 KB Output is correct
45 Correct 3 ms 9820 KB Output is correct
46 Correct 3 ms 9820 KB Output is correct
47 Correct 5 ms 10076 KB Output is correct
48 Correct 26 ms 15996 KB Output is correct
49 Correct 24 ms 15704 KB Output is correct
50 Correct 25 ms 15460 KB Output is correct
51 Correct 23 ms 15452 KB Output is correct
52 Correct 23 ms 15348 KB Output is correct
53 Correct 45 ms 20820 KB Output is correct
54 Correct 8 ms 11356 KB Output is correct
55 Correct 21 ms 14680 KB Output is correct
56 Correct 3 ms 10076 KB Output is correct
57 Correct 9 ms 11356 KB Output is correct
58 Correct 6 ms 10844 KB Output is correct
59 Correct 131 ms 37984 KB Output is correct
60 Correct 186 ms 49492 KB Output is correct
61 Correct 200 ms 64336 KB Output is correct
62 Correct 202 ms 64396 KB Output is correct
63 Correct 153 ms 45092 KB Output is correct
64 Correct 201 ms 64912 KB Output is correct
65 Correct 198 ms 65104 KB Output is correct
66 Correct 75 ms 29520 KB Output is correct
67 Correct 216 ms 62232 KB Output is correct
68 Correct 99 ms 49184 KB Output is correct
69 Correct 69 ms 32136 KB Output is correct
70 Correct 135 ms 54576 KB Output is correct
71 Correct 2 ms 9816 KB Output is correct
72 Correct 2 ms 9816 KB Output is correct
73 Correct 2 ms 9820 KB Output is correct
74 Correct 2 ms 9816 KB Output is correct
75 Correct 2 ms 9816 KB Output is correct
76 Correct 2 ms 9644 KB Output is correct
77 Correct 36 ms 31756 KB Output is correct
78 Correct 37 ms 31748 KB Output is correct
79 Correct 38 ms 31736 KB Output is correct
80 Correct 37 ms 31676 KB Output is correct
81 Correct 106 ms 49868 KB Output is correct
82 Correct 142 ms 58964 KB Output is correct
83 Correct 141 ms 59448 KB Output is correct
84 Correct 269 ms 80696 KB Output is correct
85 Correct 287 ms 82548 KB Output is correct
86 Correct 247 ms 84284 KB Output is correct
87 Correct 247 ms 86988 KB Output is correct
88 Correct 2 ms 9820 KB Output is correct
89 Correct 250 ms 86776 KB Output is correct
90 Correct 258 ms 79040 KB Output is correct
91 Correct 213 ms 69488 KB Output is correct