답안 #1090401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090401 2024-09-18T10:39:20 Z mychecksedad Akcija (COCI21_akcija) C++17
90 / 110
5000 ms 230428 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 1e9 + 7;
const ll MAXN = 2100;
#define all(x) x.begin(), x.end()
#define int long long
vector<pair<int,int>> v;
int sg[4*MAXN], lazy[4*MAXN];
void init(int k, int a, int b) {
    if (a == b) {
        sg[k] = a;
        lazy[k] = 0;
        return ;
    }
    init(2*k, a, (a+b)/2);
    init(2*k+1, (a+b)/2+1, b);
    sg[k] = min(sg[2*k], sg[2*k+1]);
    lazy[k] = 0;
}
 
void push(int k, int a, int b) {
    if (lazy[k]) {
        sg[k] += lazy[k];
        if (a != b) {
            lazy[2*k] += lazy[k];
            lazy[2*k+1] += lazy[k];
        }
        lazy[k] = 0;
    }
}
 
void update(int k, int a, int b, int q_l, int q_r, int val) {
    push(k, a, b);
    if (b < q_l || a > q_r)
        return ;
    if (q_l <= a && b <= q_r) {
        lazy[k] += val;
        push(k, a, b);
        return ;
    }
    update(2*k, a, (a+b)/2, q_l, q_r, val);
    update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
    sg[k] = min(sg[2*k], sg[2*k+1]);
}
 
int query(int k, int a, int b, int q_l, int q_r) {
    if (b < q_l || a > q_r)
        return 1e9;
    push(k, a, b);
    if (q_l <= a && b <= q_r)
        return sg[k];
    return min(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}
 
struct Partition {
    int n = 2100, lastban = -1;
    vector<int> ban, here;
    int cnt = 0, cost = 0;
    Partition(vector<int> _ban) : ban(_ban) {
        n = ban.size();
        cnt = cost = 0;
        init(1, 1, n);
        for (int i = 0; i < n; i++) {
            if (ban[i] != -1 && (ban[i] == 1 || query(1, 1, n, v[i].s, n) == 0)){
              if(ban[i] == 1){
                lastban=max(lastban, i);
              }
              continue;
          }
            cnt++;
            cost += v[i].f;
            if (ban[i] != -1)
                here.push_back(i);
            update(1, 1, n, v[i].s, n, -1);
        }
    }
};
 
bool operator <(Partition A, Partition B) {
    return make_pair(A.cnt, -A.cost) < make_pair(B.cnt, -B.cost);
}
 
signed main() {
    fast;
    int n, k;
    cin >> n >> k;
 
    v = vector<pair<int,int>>(n);
    for (int i = 0; i < n; i++)
        cin >> v[i].f >> v[i].s;
    sort(v.begin(), v.end());
 
    set<Partition> pq;
    vector<int> Q(n, 0);
    pq.insert(Partition(Q));
    while (!pq.empty()) {
        Partition Q = *prev(pq.end());
        pq.erase(prev(pq.end()));
 
        cout << Q.cnt << " " << Q.cost << "\n";
        k--;
        if (k == 0)
            exit(0);
 
        vector<int> ban_here = Q.ban;
        int pos = lower_bound(all(Q.here), Q.lastban) - Q.here.begin();
        for (int i = pos; i < Q.here.size(); ++i) {
            int u = Q.here[i];
            ban_here[u] = 1;
            Partition K = Partition(ban_here);
 //           if (pq.size() > k && K < *(pq.begin()))
   //             break;
            pq.insert(K);
            ban_here[u] = -1;
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:114:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |         for (int i = pos; i < Q.here.size(); ++i) {
      |                           ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 792 ms 43432 KB Output is correct
2 Correct 871 ms 46716 KB Output is correct
3 Correct 744 ms 38676 KB Output is correct
4 Correct 790 ms 38880 KB Output is correct
5 Correct 924 ms 46080 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 8 ms 1112 KB Output is correct
10 Correct 162 ms 17492 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1628 KB Output is correct
2 Correct 19 ms 1368 KB Output is correct
3 Correct 12 ms 1964 KB Output is correct
4 Correct 7 ms 1216 KB Output is correct
5 Correct 15 ms 2140 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 4 ms 604 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 4 ms 604 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 8 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 856 KB Output is correct
2 Correct 11 ms 1372 KB Output is correct
3 Correct 4 ms 712 KB Output is correct
4 Correct 12 ms 1116 KB Output is correct
5 Correct 9 ms 1372 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 360 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 7 ms 1112 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 5 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 600 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 792 ms 43432 KB Output is correct
28 Correct 871 ms 46716 KB Output is correct
29 Correct 744 ms 38676 KB Output is correct
30 Correct 790 ms 38880 KB Output is correct
31 Correct 924 ms 46080 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 8 ms 1112 KB Output is correct
36 Correct 162 ms 17492 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 12 ms 1628 KB Output is correct
41 Correct 19 ms 1368 KB Output is correct
42 Correct 12 ms 1964 KB Output is correct
43 Correct 7 ms 1216 KB Output is correct
44 Correct 15 ms 2140 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 4 ms 604 KB Output is correct
47 Correct 3 ms 604 KB Output is correct
48 Correct 4 ms 604 KB Output is correct
49 Correct 0 ms 464 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 8 ms 1100 KB Output is correct
53 Correct 8 ms 856 KB Output is correct
54 Correct 11 ms 1372 KB Output is correct
55 Correct 4 ms 712 KB Output is correct
56 Correct 12 ms 1116 KB Output is correct
57 Correct 9 ms 1372 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 360 KB Output is correct
61 Correct 1 ms 464 KB Output is correct
62 Correct 7 ms 1112 KB Output is correct
63 Correct 1 ms 344 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 5 ms 856 KB Output is correct
66 Execution timed out 5068 ms 230428 KB Time limit exceeded
67 Halted 0 ms 0 KB -