Submission #930928

#TimeUsernameProblemLanguageResultExecution timeMemory
930928AlebnArt Collections (BOI22_art)C++17
35 / 100
141 ms440 KiB
#include <bits/stdc++.h>
#include "art.h"

using namespace std;

int n, x, y, p, q, mid;
vector<int> res;
bool compare(int a, int b) {
    vector<int> q(n);
    q[0] = a, q[1] = b;
    for(int i = 2, j = 1; i < n; i++) {
        if(j == a) j++;
        if(j == b) j++;
        if(j == a) j++;
        q[i] = j;
        j++;
    }
    x = publish(q);
    swap(q[0], q[1]);
    y = publish(q);
    if(x < y) return true;
    return false;
}
void merge(int l, int r) {
    if(l == r) return;
    merge(l, (l + r) / 2);
    merge((l + r) / 2 + 1, r);
    mid = (l + r) / 2;
    vector<int> a(mid - l + 1), b(r - mid);
    for(int k = 0; k <= mid - l; k++) a[k] = res[k + l];
    for(int k = 0; k < r - mid; k++) b[k] = res[k + mid + 1];
    p = 0, q = 0;
    while(p < a.size() && q < b.size()) {
        x = compare(a[p], b[q]);
        if(x) {
            res[l + p + q] = a[p];
            p++;
        } else {
            res[l + p + q] = b[q];
            q++;
        }
    }
    while(p < a.size()) {
        res[l + p + q] = a[p];
        p++;
    }
    while(q < b.size()) {
        res[l + p + q] = b[q];
        q++;
    }
}

void solve(int ni) {
    n = ni, res = vector<int>(n);
    for(int i = 0; i < n; i++) res[i] = i + 1;
    merge(0, n-1);
    answer(res);
}

Compilation message (stderr)

art.cpp: In function 'void merge(int, int)':
art.cpp:33:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     while(p < a.size() && q < b.size()) {
      |           ~~^~~~~~~~~~
art.cpp:33:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     while(p < a.size() && q < b.size()) {
      |                           ~~^~~~~~~~~~
art.cpp:43:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     while(p < a.size()) {
      |           ~~^~~~~~~~~~
art.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     while(q < b.size()) {
      |           ~~^~~~~~~~~~
interface.cpp: In function 'int publish(std::vector<int>)':
interface.cpp:20:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
interface.cpp: In function 'void answer(std::vector<int>)':
interface.cpp:36:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |     if(v.size() != N) {
      |        ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...