답안 #795673

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
795673 2023-07-27T12:41:19 Z AbdullahMohammedAhmad Minerals (JOI19_minerals) C++14
40 / 100
1000 ms 2348 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
 
mt19937 rng(66);
void Solve(int n) {
    vector<int> p1, p2;
    int ans = 0, prevans = -1;
    vector<int> bulanea(2 * n);
    iota(bulanea.begin(), bulanea.end(), 1);
    shuffle(bulanea.begin(), bulanea.end(), rng);
    for(int i: bulanea) {
        ans = Query(i);
        if(ans == prevans) {
            p2.push_back(i);
        } else {
            p1.push_back(i);
        }
        prevans = ans;
    }
    assert(p1.size() == n && p2.size() == n);
    vector<int> pr(n, 0);
    vector<bool> bagat(n, 1);
    vector<int> bit_order;
    vector<int> best_order; int mn = INT_MAX;
    for(int bit = 0; (1 << bit) < n; ++bit) {
        bit_order.push_back(bit);
    }
    int f = 0;
    while(f++ < 1000) {
        vector<bool> bruh(n, true);
        int cost = 0;
        for(int b: bit_order) {
            for(int i = 0; i < n; ++i) {
                if(i >> b & 1) {
                    if(!bruh[i]) ++cost;
                    bruh[i] = 1;
                } else {
                    if(bruh[i]) ++cost;
                    bruh[i] = 0;
                }
            }
        }
        if(cost < mn) {
            mn = cost;
            best_order = bit_order;
        }
        shuffle(bit_order.begin(), bit_order.end(), rng);
    }
    for(int bit: best_order) {
        int cntt = 0;
        for(int i = 0; i < n; ++i) {
            if(i >> bit & 1) {
                ++cntt;
                if(!bagat[i]) prevans = Query(p1[i]);
                bagat[i] = 1;
            } else {
                if(bagat[i]) prevans = Query(p1[i]);
                bagat[i] = 0;
            }
        }
        for(int i = 0; i < n && cntt; ++i) {
            if(pr[i] + (1 << bit) >= n) continue;
            int ans = Query(p2[i]);
            if(ans == prevans) {
                pr[i] += (1 << bit);
                --cntt;
            }
            prevans = ans;
        }
    }
    for(int i = 0; i < n; ++i) {
        Answer(p2[i], p1[pr[i]]);
    }
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from minerals.cpp:2:
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:21:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |     assert(p1.size() == n && p2.size() == n);
      |            ~~~~~~~~~~^~~~
minerals.cpp:21:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |     assert(p1.size() == n && p2.size() == n);
      |                              ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 356 KB Output is correct
2 Correct 53 ms 384 KB Output is correct
3 Correct 114 ms 472 KB Output is correct
4 Correct 248 ms 644 KB Output is correct
5 Correct 499 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 24 ms 356 KB Output is correct
6 Correct 53 ms 384 KB Output is correct
7 Correct 114 ms 472 KB Output is correct
8 Correct 248 ms 644 KB Output is correct
9 Correct 499 ms 892 KB Output is correct
10 Correct 24 ms 360 KB Output is correct
11 Correct 337 ms 768 KB Output is correct
12 Correct 497 ms 956 KB Output is correct
13 Correct 502 ms 956 KB Output is correct
14 Correct 497 ms 900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 24 ms 356 KB Output is correct
6 Correct 53 ms 384 KB Output is correct
7 Correct 114 ms 472 KB Output is correct
8 Correct 248 ms 644 KB Output is correct
9 Correct 499 ms 892 KB Output is correct
10 Correct 24 ms 360 KB Output is correct
11 Correct 337 ms 768 KB Output is correct
12 Correct 497 ms 956 KB Output is correct
13 Correct 502 ms 956 KB Output is correct
14 Correct 497 ms 900 KB Output is correct
15 Execution timed out 1459 ms 2348 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 24 ms 356 KB Output is correct
6 Correct 53 ms 384 KB Output is correct
7 Correct 114 ms 472 KB Output is correct
8 Correct 248 ms 644 KB Output is correct
9 Correct 499 ms 892 KB Output is correct
10 Correct 24 ms 360 KB Output is correct
11 Correct 337 ms 768 KB Output is correct
12 Correct 497 ms 956 KB Output is correct
13 Correct 502 ms 956 KB Output is correct
14 Correct 497 ms 900 KB Output is correct
15 Execution timed out 1459 ms 2348 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 24 ms 356 KB Output is correct
6 Correct 53 ms 384 KB Output is correct
7 Correct 114 ms 472 KB Output is correct
8 Correct 248 ms 644 KB Output is correct
9 Correct 499 ms 892 KB Output is correct
10 Correct 24 ms 360 KB Output is correct
11 Correct 337 ms 768 KB Output is correct
12 Correct 497 ms 956 KB Output is correct
13 Correct 502 ms 956 KB Output is correct
14 Correct 497 ms 900 KB Output is correct
15 Execution timed out 1459 ms 2348 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 24 ms 356 KB Output is correct
6 Correct 53 ms 384 KB Output is correct
7 Correct 114 ms 472 KB Output is correct
8 Correct 248 ms 644 KB Output is correct
9 Correct 499 ms 892 KB Output is correct
10 Correct 24 ms 360 KB Output is correct
11 Correct 337 ms 768 KB Output is correct
12 Correct 497 ms 956 KB Output is correct
13 Correct 502 ms 956 KB Output is correct
14 Correct 497 ms 900 KB Output is correct
15 Execution timed out 1459 ms 2348 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 24 ms 356 KB Output is correct
6 Correct 53 ms 384 KB Output is correct
7 Correct 114 ms 472 KB Output is correct
8 Correct 248 ms 644 KB Output is correct
9 Correct 499 ms 892 KB Output is correct
10 Correct 24 ms 360 KB Output is correct
11 Correct 337 ms 768 KB Output is correct
12 Correct 497 ms 956 KB Output is correct
13 Correct 502 ms 956 KB Output is correct
14 Correct 497 ms 900 KB Output is correct
15 Execution timed out 1459 ms 2348 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 2 ms 208 KB Output is correct
5 Correct 24 ms 356 KB Output is correct
6 Correct 53 ms 384 KB Output is correct
7 Correct 114 ms 472 KB Output is correct
8 Correct 248 ms 644 KB Output is correct
9 Correct 499 ms 892 KB Output is correct
10 Correct 24 ms 360 KB Output is correct
11 Correct 337 ms 768 KB Output is correct
12 Correct 497 ms 956 KB Output is correct
13 Correct 502 ms 956 KB Output is correct
14 Correct 497 ms 900 KB Output is correct
15 Execution timed out 1459 ms 2348 KB Time limit exceeded
16 Halted 0 ms 0 KB -