Submission #819175

# Submission time Handle Problem Language Result Execution time Memory
819175 2023-08-10T08:18:49 Z cig32 Akcija (COCI21_akcija) C++17
90 / 110
5000 ms 57812 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long 
#define double long double
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
bool cmp(pair<int, int> x, pair<int, int> y) {
  return x.second < y.second;
}
void solve(int tc) {
  int n, k;
  cin >> n >> k;
  pair<int, int> p[n+1];
  for(int i=1; i<=n; i++) cin >> p[i].first >> p[i].second;
  sort(p+1, p+1+n, cmp);
  int dp[2][n+1][k+1];
  for(int i=1; i<=n; i++) {
    for(int j=1; j<=k; j++) {
      dp[0][i][j] = 1e18;
    }
  }
  dp[0][0][1] = 0;
  for(int i=2; i<=k; i++) dp[0][0][i] = 1e18;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> sol;
  sol.push({0, 0});
  for(int i=1; i<=n; i++) {
    for(int j=0; j<i; j++) {
      for(int l=1; l<=k; l++) {
        dp[i&1][j][l] = 1e18;
      }
    }
    int opt[k+1];
    for(int j=1; j<=k; j++) opt[j] = 1e18;
    for(int j=0; j<i; j++) {
      int res[k+1];
      int p1 = 1, p2 = 1;
      for(int l=1; l<=k; l++) {
        if(dp[(i-1)&1][j][p1] < opt[p2]) {
          res[l] = dp[(i-1)&1][j][p1++];
        }
        else {
          res[l] = opt[p2++];
        }
      }
      for(int l=1; l<=k; l++) {
        opt[l] = res[l];
      }
    }
    for(int j=i; j<=n; j++) {
      if(p[j].second >= i) {
        for(int l=1; l<=k; l++) dp[i&1][j][l] = opt[l] + p[j].first;
      }
      else {
        for(int l=1; l<=k; l++) dp[i&1][j][l] = 1e18;
      }
      int res[k+1];
      int p1 = 1, p2 = 1;
      for(int l=1; l<=k; l++) {
        if(dp[(i-1)&1][j][p1] < opt[p2]) {
          res[l] = dp[(i-1)&1][j][p1++];
        }
        else {
          res[l] = opt[p2++];
        }
      }
      for(int l=1; l<=k; l++) {
        opt[l] = res[l];
      }
    }
    for(int j=i; j<=n; j++) {
      for(int l=1; l<=k; l++) {
        if(dp[i&1][j][l] <= 1e13) sol.push({i, -dp[i&1][j][l]});
        if(sol.size() > k) sol.pop();
      }
    }
  }
  while(sol.size() > k) sol.pop();
  stack<pair<int, int> > stk;
  for(int i=0; i<k; i++) {
    stk.push({sol.top().first, -sol.top().second});
    sol.pop();
  }
  for(int i=0; i<k; i++) {
    cout << stk.top().first << ' ' << stk.top().second << '\n';
    stk.pop();
  }
  
}
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷

Compilation message

Main.cpp: In function 'void solve(long long int)':
Main.cpp:90:23: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   90 |         if(sol.size() > k) sol.pop();
      |            ~~~~~~~~~~~^~~
Main.cpp:94:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int>, std::vector<std::pair<long long int, long long int> >, std::greater<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   94 |   while(sol.size() > k) sol.pop();
      |         ~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 340 KB Output is correct
2 Correct 58 ms 396 KB Output is correct
3 Correct 42 ms 340 KB Output is correct
4 Correct 42 ms 340 KB Output is correct
5 Correct 52 ms 392 KB Output is correct
6 Correct 22 ms 404 KB Output is correct
7 Correct 27 ms 396 KB Output is correct
8 Correct 26 ms 388 KB Output is correct
9 Correct 23 ms 340 KB Output is correct
10 Correct 29 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 340 KB Output is correct
2 Correct 58 ms 396 KB Output is correct
3 Correct 42 ms 340 KB Output is correct
4 Correct 42 ms 340 KB Output is correct
5 Correct 52 ms 392 KB Output is correct
6 Correct 22 ms 404 KB Output is correct
7 Correct 27 ms 396 KB Output is correct
8 Correct 26 ms 388 KB Output is correct
9 Correct 23 ms 340 KB Output is correct
10 Correct 29 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 61 ms 392 KB Output is correct
15 Correct 74 ms 396 KB Output is correct
16 Correct 53 ms 340 KB Output is correct
17 Correct 61 ms 380 KB Output is correct
18 Correct 62 ms 340 KB Output is correct
19 Correct 25 ms 404 KB Output is correct
20 Correct 27 ms 340 KB Output is correct
21 Correct 30 ms 340 KB Output is correct
22 Correct 34 ms 340 KB Output is correct
23 Correct 32 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 340 KB Output is correct
2 Correct 122 ms 428 KB Output is correct
3 Correct 87 ms 412 KB Output is correct
4 Correct 105 ms 408 KB Output is correct
5 Correct 134 ms 424 KB Output is correct
6 Correct 44 ms 340 KB Output is correct
7 Correct 48 ms 424 KB Output is correct
8 Correct 49 ms 416 KB Output is correct
9 Correct 31 ms 424 KB Output is correct
10 Correct 57 ms 424 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 980 KB Output is correct
2 Correct 13 ms 980 KB Output is correct
3 Correct 9 ms 972 KB Output is correct
4 Correct 7 ms 976 KB Output is correct
5 Correct 11 ms 1072 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 4 ms 1064 KB Output is correct
8 Correct 2 ms 980 KB Output is correct
9 Correct 3 ms 980 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 340 KB Output is correct
2 Correct 18 ms 472 KB Output is correct
3 Correct 15 ms 464 KB Output is correct
4 Correct 16 ms 340 KB Output is correct
5 Correct 19 ms 480 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 5 ms 340 KB Output is correct
10 Correct 6 ms 460 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 340 KB Output is correct
2 Correct 58 ms 396 KB Output is correct
3 Correct 42 ms 340 KB Output is correct
4 Correct 42 ms 340 KB Output is correct
5 Correct 52 ms 392 KB Output is correct
6 Correct 22 ms 404 KB Output is correct
7 Correct 27 ms 396 KB Output is correct
8 Correct 26 ms 388 KB Output is correct
9 Correct 23 ms 340 KB Output is correct
10 Correct 29 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 61 ms 392 KB Output is correct
15 Correct 74 ms 396 KB Output is correct
16 Correct 53 ms 340 KB Output is correct
17 Correct 61 ms 380 KB Output is correct
18 Correct 62 ms 340 KB Output is correct
19 Correct 25 ms 404 KB Output is correct
20 Correct 27 ms 340 KB Output is correct
21 Correct 30 ms 340 KB Output is correct
22 Correct 34 ms 340 KB Output is correct
23 Correct 32 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 120 ms 340 KB Output is correct
28 Correct 122 ms 428 KB Output is correct
29 Correct 87 ms 412 KB Output is correct
30 Correct 105 ms 408 KB Output is correct
31 Correct 134 ms 424 KB Output is correct
32 Correct 44 ms 340 KB Output is correct
33 Correct 48 ms 424 KB Output is correct
34 Correct 49 ms 416 KB Output is correct
35 Correct 31 ms 424 KB Output is correct
36 Correct 57 ms 424 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 10 ms 980 KB Output is correct
41 Correct 13 ms 980 KB Output is correct
42 Correct 9 ms 972 KB Output is correct
43 Correct 7 ms 976 KB Output is correct
44 Correct 11 ms 1072 KB Output is correct
45 Correct 0 ms 256 KB Output is correct
46 Correct 4 ms 1064 KB Output is correct
47 Correct 2 ms 980 KB Output is correct
48 Correct 3 ms 980 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 7 ms 980 KB Output is correct
53 Correct 21 ms 340 KB Output is correct
54 Correct 18 ms 472 KB Output is correct
55 Correct 15 ms 464 KB Output is correct
56 Correct 16 ms 340 KB Output is correct
57 Correct 19 ms 480 KB Output is correct
58 Correct 2 ms 340 KB Output is correct
59 Correct 3 ms 468 KB Output is correct
60 Correct 4 ms 340 KB Output is correct
61 Correct 5 ms 340 KB Output is correct
62 Correct 6 ms 460 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 4 ms 340 KB Output is correct
66 Execution timed out 5049 ms 57812 KB Time limit exceeded
67 Halted 0 ms 0 KB -