# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
626472 | 2022-08-11T13:17:16 Z | Antekb | 메기 농장 (IOI22_fish) | C++17 | 148 ms | 32364 KB |
#include "fish.h" #include <bits/stdc++.h> #define pb push_back #define st first #define nd second using namespace std; using ll = long long; const int INF=1e9+5; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll max_weights(int n, int m, std::vector<int> X, std::vector<int> Y, std::vector<int> W) { /*n=1e5; m=1e5; X.resize(m); Y.resize(m); W.resize(m); for(int i=0; i<m; i++){ X[i]=(rng()%(n/2))*2+2; Y[i]=rng()%n; W[i]=rng(); }*/ for(auto &i:X)i++; ll ans=0; for(int i:W)ans+=i; //return ans; vector<pair<int, int> > V[n+2]; vector<ll> dp[n+2][2]; ll dp2[n+2][2]; for(int i=0; i<=n+1; i++)dp2[i][0]=dp2[i][1]=0; for(int i=0; i<m; i++){ V[X[i]].pb({Y[i], W[i]}); } for(int i=0; i<=n+1; i++){ V[i].pb({n, INF}); sort(V[i].begin(), V[i].end()); dp[i][0].resize(V[i].size()); dp[i][1].resize(V[i].size()); } dp[0][1][0]=dp[0][0][0]=-1e18; for(int i=1; i<=n+1; i++){ ll s=0; int wsk=0; for(int j=0; j<V[i-1].size(); j++){ dp[i-1][0][j]-=s; s+=V[i-1][j].nd; } ll m=dp2[i-1][0]; dp2[i][0]=max(dp2[i-1][0], dp2[i-1][1]); s=0; for(int j=0; j<V[i].size(); j++){ while(wsk<V[i-1].size() && V[i][j].st>V[i-1][wsk].st){ m=max(m, dp[i-1][0][wsk]); s+=V[i-1][wsk].nd; wsk++; } dp[i][0][j]=s+m; } wsk=V[i-1].size()-1; m=dp[i-1][1][wsk]; for(int j=V[i].size()-2; j>=0; j--){ while(wsk!=0 && V[i-1][wsk-1].st>=V[i][j].st){ m=max(m, dp[i-1][1][wsk-1]); wsk--; } dp[i][1][j]=m; m+=V[i][j].nd; } for(int j=0; j<V[i-1].size(); j++)dp2[i][0]=max(dp2[i][0], dp[i-1][1][j]); dp2[i][1]=max(m, dp2[i][0]); for(int j=0; j<V[i].size(); j++){ dp[i][0][j]=max(dp[i][0][j], dp2[i-1][1]); } for(int j=0; j<V[i].size(); j++){ dp[i][1][j]=max(dp[i][0][j], dp[i][1][j]); } //cout<<i<<"\n"; //cout<<dp2[i][0]<<" "<<dp2[i][1]<<" a\n"; for(int j=0; j<V[i].size(); j++){ //cout<<dp[i][0][j]<<" "<<dp[i][1][j]<<" b\n"; } } //assert(dp2[n+1][0]==ans); return dp2[n+1][0]; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 20288 KB | Output is correct |
2 | Correct | 61 ms | 22932 KB | Output is correct |
3 | Correct | 25 ms | 18240 KB | Output is correct |
4 | Correct | 25 ms | 18176 KB | Output is correct |
5 | Correct | 142 ms | 32364 KB | Output is correct |
6 | Correct | 148 ms | 31900 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 81 ms | 24112 KB | Output is correct |
3 | Correct | 98 ms | 27712 KB | Output is correct |
4 | Correct | 56 ms | 20176 KB | Output is correct |
5 | Correct | 60 ms | 22952 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 25 ms | 18296 KB | Output is correct |
11 | Correct | 24 ms | 18240 KB | Output is correct |
12 | Correct | 53 ms | 20288 KB | Output is correct |
13 | Correct | 61 ms | 22908 KB | Output is correct |
14 | Correct | 58 ms | 20220 KB | Output is correct |
15 | Correct | 59 ms | 22592 KB | Output is correct |
16 | Correct | 51 ms | 20324 KB | Output is correct |
17 | Correct | 56 ms | 22472 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 18268 KB | Output is correct |
2 | Correct | 24 ms | 18292 KB | Output is correct |
3 | Incorrect | 44 ms | 17740 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361' |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Incorrect | 1 ms | 212 KB | 1st lines differ - on the 1st token, expected: '2', found: '1' |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Incorrect | 1 ms | 212 KB | 1st lines differ - on the 1st token, expected: '2', found: '1' |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Incorrect | 1 ms | 212 KB | 1st lines differ - on the 1st token, expected: '2', found: '1' |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 18268 KB | Output is correct |
2 | Correct | 24 ms | 18292 KB | Output is correct |
3 | Incorrect | 44 ms | 17740 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361' |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 20288 KB | Output is correct |
2 | Correct | 61 ms | 22932 KB | Output is correct |
3 | Correct | 25 ms | 18240 KB | Output is correct |
4 | Correct | 25 ms | 18176 KB | Output is correct |
5 | Correct | 142 ms | 32364 KB | Output is correct |
6 | Correct | 148 ms | 31900 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 81 ms | 24112 KB | Output is correct |
9 | Correct | 98 ms | 27712 KB | Output is correct |
10 | Correct | 56 ms | 20176 KB | Output is correct |
11 | Correct | 60 ms | 22952 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 25 ms | 18296 KB | Output is correct |
17 | Correct | 24 ms | 18240 KB | Output is correct |
18 | Correct | 53 ms | 20288 KB | Output is correct |
19 | Correct | 61 ms | 22908 KB | Output is correct |
20 | Correct | 58 ms | 20220 KB | Output is correct |
21 | Correct | 59 ms | 22592 KB | Output is correct |
22 | Correct | 51 ms | 20324 KB | Output is correct |
23 | Correct | 56 ms | 22472 KB | Output is correct |
24 | Correct | 24 ms | 18268 KB | Output is correct |
25 | Correct | 24 ms | 18292 KB | Output is correct |
26 | Incorrect | 44 ms | 17740 KB | 1st lines differ - on the 1st token, expected: '21261825233649', found: '21208021504361' |
27 | Halted | 0 ms | 0 KB | - |