Submission #1031949

# Submission time Handle Problem Language Result Execution time Memory
1031949 2024-07-23T08:58:53 Z gs25 None (KOI17_cook) C++17
100 / 100
455 ms 163124 KB
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
using namespace std; 

const int MAXN = 3010; 
typedef long long ll; 

ll dp[MAXN][MAXN], dp1[MAXN][MAXN], dp2[MAXN][MAXN]; 
ll T; 
ll psum[MAXN][MAXN]; 
int f[MAXN]; 
const ll inf = 1e18; 

int main(void){
  ios::sync_with_stdio(false); cin.tie(nullptr); 
  int n,m; cin >> n >> m; 
  int s,e; cin >> s >> e; 
  cin >> T; 
  for(int i=1; i<=n; i++){
    for(int j=1; j<=m; j++){
      int x; cin >> x; psum[i][j] = psum[i][j-1] + x; 
    }
  }
  for(int i=1; i<=n; i++) cin >> f[i]; 
  for(int i=1; i<=n; i++) dp1[i][0] = -T; 
  deque<pair<ll,int>> dq[MAXN]; 
  deque<pair<ll,int>> dq1[MAXN]; 
  for(int i=1; i<=n; i++){
    dq[i].push_back({-T,0});
    if(s==1) dq1[i].push_back({-T,0}); 
    dp2[i][0] = -T; 
  }
  for(int t=1; t<=m; t++){
    vector<pair<ll,int>> v; 
    for(int i=1; i<=n; i++){
      while(!dq[i].empty() && dq[i].front().second < max(t-e,0)) dq[i].pop_front(); 
      while(!dq1[i].empty() && dq1[i].front().second < max(t-e,0)) dq1[i].pop_front(); 
      dp[i][t] = T + psum[i][t] + dq[i].front().first;  
      if(!dq1[i].empty()) dp1[i][t] = T + psum[i][t] + dq1[i].front().first, v.push_back({dp1[i][t],i}); 
      else dp1[i][t] = inf; 
    }
    sort(all(v),[](auto & x, auto & y){
      return x.first < y.first; 
    }); 
    for(int i=1; i<=n; i++){
      if(v.empty()){
        dp2[i][t] = inf; 
      }
      else{
        for(int k=0; k<3; k++){
          if(v[k].second != i && v[k].second != f[i]){
            //if(i==1 && t==2) cerr << v[k].first << "fuckkkkkkkkkkkkkkkkk" << endl; 
            dp2[i][t] = v[k].first - psum[i][t]; break; 
          }
        }
      }
      while(!dq[i].empty() && dq[i].back().first >= dp2[i][t]) dq[i].pop_back(); 
      dq[i].push_back({dp2[i][t],t}); 
      if(t>=s-1) {
        while(!dq1[i].empty() && dq1[i].back().first >= dp2[i][t-s+1]) dq1[i].pop_back(); 
        //cerr << "wtf?? " << i << " " << t << " " << dp2[i][t-s+1] << endl;
        dq1[i].push_back({dp2[i][t-s+1],t-s+1}); 
      }
      //cerr << i << " " << dp[i][t] << " " << dp1[i][t] << endl;
    }
  } 
  ll ans = inf; 
  for(int i=1; i<=n; i++) ans = min(dp[i][m],ans); 
  cout << ans; 
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 13 ms 12712 KB Output is correct
12 Correct 10 ms 11392 KB Output is correct
13 Correct 18 ms 12892 KB Output is correct
14 Correct 11 ms 11356 KB Output is correct
15 Correct 12 ms 12636 KB Output is correct
16 Correct 14 ms 12636 KB Output is correct
17 Correct 16 ms 12624 KB Output is correct
18 Correct 9 ms 9816 KB Output is correct
19 Correct 14 ms 12636 KB Output is correct
20 Correct 8 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 13 ms 12712 KB Output is correct
11 Correct 10 ms 11392 KB Output is correct
12 Correct 18 ms 12892 KB Output is correct
13 Correct 11 ms 11356 KB Output is correct
14 Correct 12 ms 12636 KB Output is correct
15 Correct 14 ms 12636 KB Output is correct
16 Correct 16 ms 12624 KB Output is correct
17 Correct 9 ms 9816 KB Output is correct
18 Correct 14 ms 12636 KB Output is correct
19 Correct 8 ms 9820 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 130 ms 86100 KB Output is correct
22 Correct 159 ms 86100 KB Output is correct
23 Correct 157 ms 86072 KB Output is correct
24 Correct 120 ms 86100 KB Output is correct
25 Correct 102 ms 86096 KB Output is correct
26 Correct 163 ms 86120 KB Output is correct
27 Correct 176 ms 86096 KB Output is correct
28 Correct 118 ms 86096 KB Output is correct
29 Correct 147 ms 86096 KB Output is correct
30 Correct 96 ms 86116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 13 ms 12712 KB Output is correct
11 Correct 10 ms 11392 KB Output is correct
12 Correct 18 ms 12892 KB Output is correct
13 Correct 11 ms 11356 KB Output is correct
14 Correct 12 ms 12636 KB Output is correct
15 Correct 14 ms 12636 KB Output is correct
16 Correct 16 ms 12624 KB Output is correct
17 Correct 9 ms 9816 KB Output is correct
18 Correct 14 ms 12636 KB Output is correct
19 Correct 8 ms 9820 KB Output is correct
20 Correct 3 ms 4952 KB Output is correct
21 Correct 119 ms 37664 KB Output is correct
22 Correct 111 ms 37788 KB Output is correct
23 Correct 121 ms 37460 KB Output is correct
24 Correct 84 ms 37544 KB Output is correct
25 Correct 109 ms 37612 KB Output is correct
26 Correct 94 ms 37716 KB Output is correct
27 Correct 120 ms 37456 KB Output is correct
28 Correct 112 ms 37476 KB Output is correct
29 Correct 123 ms 37744 KB Output is correct
30 Correct 102 ms 37712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5208 KB Output is correct
2 Correct 2 ms 5212 KB Output is correct
3 Correct 2 ms 5212 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5212 KB Output is correct
6 Correct 3 ms 5212 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 3 ms 5212 KB Output is correct
10 Correct 13 ms 12712 KB Output is correct
11 Correct 10 ms 11392 KB Output is correct
12 Correct 18 ms 12892 KB Output is correct
13 Correct 11 ms 11356 KB Output is correct
14 Correct 12 ms 12636 KB Output is correct
15 Correct 14 ms 12636 KB Output is correct
16 Correct 16 ms 12624 KB Output is correct
17 Correct 9 ms 9816 KB Output is correct
18 Correct 14 ms 12636 KB Output is correct
19 Correct 8 ms 9820 KB Output is correct
20 Correct 130 ms 86100 KB Output is correct
21 Correct 159 ms 86100 KB Output is correct
22 Correct 157 ms 86072 KB Output is correct
23 Correct 120 ms 86100 KB Output is correct
24 Correct 102 ms 86096 KB Output is correct
25 Correct 163 ms 86120 KB Output is correct
26 Correct 176 ms 86096 KB Output is correct
27 Correct 118 ms 86096 KB Output is correct
28 Correct 147 ms 86096 KB Output is correct
29 Correct 96 ms 86116 KB Output is correct
30 Correct 119 ms 37664 KB Output is correct
31 Correct 111 ms 37788 KB Output is correct
32 Correct 121 ms 37460 KB Output is correct
33 Correct 84 ms 37544 KB Output is correct
34 Correct 109 ms 37612 KB Output is correct
35 Correct 94 ms 37716 KB Output is correct
36 Correct 120 ms 37456 KB Output is correct
37 Correct 112 ms 37476 KB Output is correct
38 Correct 123 ms 37744 KB Output is correct
39 Correct 102 ms 37712 KB Output is correct
40 Correct 3 ms 4952 KB Output is correct
41 Correct 159 ms 48740 KB Output is correct
42 Correct 429 ms 115028 KB Output is correct
43 Correct 405 ms 114988 KB Output is correct
44 Correct 455 ms 163124 KB Output is correct
45 Correct 193 ms 59988 KB Output is correct
46 Correct 227 ms 71072 KB Output is correct
47 Correct 226 ms 82256 KB Output is correct
48 Correct 225 ms 104016 KB Output is correct
49 Correct 448 ms 115104 KB Output is correct
50 Correct 415 ms 115060 KB Output is correct